EEx2Slime

Gem Version Build Status

Script for converting EEx templates to Slime. Slime is a lightweight template language.

Usage

You may convert files using the included executable eex2slime:

$ gem install eex2slime

$ 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
$ eex2slime dir/                           # convert all .eex files recursively
$ eex2slime --delete dir/                  # delete .eex files after convertion. Be sure you have a backup!

Alternatively you could use the following API:

require 'eex2slime'
EEx2Slime.convert('path/to/file')
EEx2Slime.convert_string('<nav class="navbar"></nav>')

Installation

gem install eex2slime

Regards

Huge thanks to Maiz Lulkin and his original html2slim repo.

Does it really work?

It might fail in some cases, but in general yes, it does! I've checked it on the opersourced changelog.com 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.

Known issues

  • Incorrect HTML will break inner HTML parser. Example (notice misplaced slash):

    <img width="75" / height="75">
    
  • Nested interpolation won'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 %>">
    
  • This library doesn't support inline if's interpolation:

    <!-- such constructions aren't supported -->
    <article class="<%= if index == 0 do %>is-active<% end %>"></article>
    
  • With EEx you could do something like this:

    # header.html.eex
    <div class="container">
    
    # body.html.eex
    body content is expected to be inside container div
    
    # footer.html.eex
    </div>
    

    Slime doesn't support this, so eex2slime will produce non-expected output (body won't be nested inside the container). Be wary.

License

This project uses MIT license.