Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Multiverse-io/eextoheex
Automatic conversion of html.eex templates to heex
https://github.com/Multiverse-io/eextoheex
Last synced: 28 days ago
JSON representation
Automatic conversion of html.eex templates to heex
- Host: GitHub
- URL: https://github.com/Multiverse-io/eextoheex
- Owner: Multiverse-io
- License: mit
- Created: 2021-08-19T10:31:26.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-11T14:25:31.000Z (9 months ago)
- Last Synced: 2024-08-04T01:17:55.969Z (4 months ago)
- Language: Elixir
- Size: 2.08 MB
- Stars: 37
- Watchers: 9
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- beamtoolbox - [ex
README
# 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
---------------------------------------------------------------------|-------------------------------------------------------------
`>` | `
`
`` | `
`
`` | `
`
`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](https://github.com/super-seguros/eextoheex).## Live view forms
If the parser finds something like
```
<%= foo = form_for @changeset, "#", [phx_submit: "save", phx_change: "change"] %>
...```
it is converted to
```
<.form let={foo} for={@changeset} action="#" phx-submit="save" phx-change="change">
...```
## 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
```sh
mix escript.build
./eextoheex check /foo/bar/templates
```## Usage
### `check`
```sh
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`
```sh
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.