Script for converting EEx templates to Slime. Slime is a lightweight template language.
You may convert files using the included executable eex2slime
:
$ gem install eex2slime
# Suggested usage way. Will create .slime files near original .eex ones
$ eex2slime lib/web/templates/
# Optionally delete .eex files after convertion. Be sure you have a backup!
$ eex2slime --delete lib/web/templates/
# Another ways:
$ eex2slime foo.html.eex # outputs to foo.html.slime by default
$ eex2slime foo.html.eex bar.html.slime # outputs to bar.html.slime
$ eex2slime foo.html.eex - # outputs to stdout
$ cat foo.eex | eex2slime # input from stdin, outputs to stdout
Alternatively you could use the following API:
require 'eex2slime'
EEx2Slime.convert('path/to/file')
EEx2Slime.convert_string('<nav class="navbar"></nav>')
gem install eex2slime
Huge thanks to Maiz Lulkin and his original html2slim repo.
It might fail in some cases, but in general yes, it does! I've checked it on the opensourced changelog.com app and the hex.pm app. After a bit of preparing this tool finely converted all EEx templates.
CI runs tests on Rubies 2.2, 1.9.3. Ruby 1.8.7 isn't supported.
Using incorrect html in original templates will break inner HTML parser. Example (notice misplaced slash):
<img width="75" / height="75">
It doesn't play well with Slime. This:
<img src="<%= static_url(@conn, "/images/podcasts/#{@podcast.slug}.svg") %>">
should be rewritten to:
<% image_url = static_url(@conn, "/images/podcasts/#{@podcast.slug}.svg") %>
<img src="<%= image_url %>">
Such constructions aren't supported:
<article class="<%= if index == 0 do %>is-active<% end %>"></article>
# header.html.eex. Notice non-closed div.
<div class="container">
# body.html.eex
body content is expected to be inside container
# footer.html.eex. Closing div.
</div>
Slime doesn't support this, so eex2slime
will produce non-expected output: body won't be nested inside the container. Be wary.
There are three ways to achieve multiline elixir in Slime:
- a = 1
- b = 2
- a = 1 \
b = 2
elixir:
a = 1
b = 2
First approach leads to errors in such cases:
- some_function(first,
- second)
I decided to use the second approach, but technically the third one is possible, too.
This project uses MIT license.