GithubHelp home page GithubHelp logo

pjullrich / eextoheex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from multiverse-io/eextoheex

0.0 2.0 0.0 2.13 MB

Automatic conversion of html.eex templates to heex

License: MIT License

Elixir 100.00%

eextoheex's Introduction

Eextoheex

Eextoheex provides best effort conversion of html.eex templates to .heex templates. Not all .eex templates can be successfully converted and the output is not guaranteed to be correct in the general case. However, for a typical project, eextoheex should work well enough to significantly reduce the burden of manual conversion.

Attributes

Examples of autoconvertible attributes

Eex Heex
<p class=<%= expr %>> <p class={"#{ expr }"}>
<p class="<%= expr %>"> <p class={"#{ expr }"}>
<p class='<%= expr %>'> <p class={"#{ expr }"}>
<p class="foo <%= expr1 %> bar <%= expr2 %> amp <%= expr3 %> fuzz" <p class={"foo #{expr1} bar #{expr2} amp #{expr3} fuzz }"}

Limitations of attribute conversion

The attribute name must be present as a literal. For example, attributes such as <p <%= if @foo do "class='foo'" else "" end %>> cannot be translated.

It is unfortunately not possible to translate attributes like attribute="<%= @foo %>" simply to attribute={ @foo }. This gives the wrong result when @foo is nil or false. For example, if foo is false, then Eex outputs attribute="false", whereas Heex simply omits the attribute attribute altogether. Thus, attribute="<%= @foo %>" has to be translated to attribute={"#{ @foo }"}.

If you would prefer to output the short form and take the (small) additional risk of incorrect output, you may consider using the super-seguros fork.

Live view forms

If the parser finds something like

<%= foo = form_for @changeset, "#", [phx_submit: "save", phx_change: "change"] %>
  ...
</form>

it is converted to

<.form let={foo} for={@changeset} url="#" phx-submit="save" phx-change="change">
  ...
</.form>

Invalid output

The generated heex template may be invalid, either because:

  • the input template is not a suitable candidate for autoconversion; or

  • the input template contains invalid HTML (e.g. a missing closing tag).

Eextoheex always runs the output template through the heex parser, and will report an error in the case where it is invalid.

Building

mix escript.build
./eextoheex check /foo/bar/templates

Usage

check

eextoheex check /foo/bar/templates1 /foo/bar/templates2

Performs a recursive scan for html.(l)eex templates in the provided files or directories and outputs a report showing which of these templates can be automatically converted.

check_inline

Like check, but scans for .ex files that contain ~L""" sigils.

convert

Like check, but also renames each autoconvertible *.html.(l)eex template with a .heex extension and replaces its contents with the autogenerated heex template.

convert_inline

Like check_inline, but also replaces the contents of the .ex file with the output of autoconversion.

run

eextoheex run /foo/bar/foo.html.eex

If the template can be autoconverted, prints the resulting heex template to stdout.

The run command can also be used to convert inline ~L""" templates in .ex files.

eextoheex's People

Contributors

addrummond avatar pjullrich avatar robacourt avatar mavuio avatar hoyon avatar marcandre avatar

Watchers

 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.