GithubHelp home page GithubHelp logo

htmltohaml's Introduction

HtmlToHaml

This script converts HTML code to HAML (for django-hamlpy). If you use django-hamlpy (https://github.com/nyaruka/django-hamlpy) as a template renderer for your django project you might find it hard to convert existing HTML code to HAML. Django-hamlpys HAML syntax is a little different from other HAML syntaxes so existing online converters won't work.
This script does work tho :)

Installation

Just clone this repo. No other dependencies required. The Script was developed and tested on Python 3.9.

Converting files

The script takes two important parameters input (required), the path to the input file and --output (optional) the output path. If --output is not set, the input filename with the .haml file extension will be used as the output file name.
Take a look at the script for more parameters

Examples

Example usage 1

HamlConverter.py index.html
Will save the result to index.haml

Example usage 2

HamlConverter.py index.html --output output.asdf
Will save the result to output.asdf

Link handlers

Django has its own template language to render links and static files (https://docs.djangoproject.com/en/3.1/intro/tutorial06/) You can overwrite the following methods to patch links patch_link_links, patch_a_links, patch_script_links and patch_img_links These methods take the link as input (eg. "/js/example.js" or "http://example.com/script.js") and return the patched script link. The default conversion for the first example would convert it to {% static '/js/example.js' %}

You probably want to overwrite these methods to make them work for your use case.

Improvements

The Script was tested on a "large" website and worked quite well. If you encounter a problem, feel free to submit a pull request.

htmltohaml's People

Contributors

derteufelqwe avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.