Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert html.slim views to html.erb - Rails, Slim, ERB

Trying to convert *.html.slim views to *.html.erb. I've looked at these two questions:

  • How can I convert html.slim to html.erb? - getting uninitialized constant when called from the console

  • How can I convert html.slim files to html or html.erb? - parser hits a NoMethodError: undefined method image_tag for nil:NilClass when it comes across the first = image_tag. I am not using any variables inside my call, the image tag points to and svg

I think the latter solution would work best, if the good people of Stack Overflow can help me figure out the image_tag issue.

My code (as requested):

page data-id="foo-page"
  .container
    = image_tag 'bar.svg'
like image 317
dimitry_n Avatar asked Aug 05 '15 15:08

dimitry_n


People also ask

How do I convert HTML slim to HTML ERB?

Start a new pen. Choosing Slim as your HTML Markdown language. Paste in your Slim - then click the view compiled button in your HTML pane. You'll see the straight HTML version of your markup.

What is HTML ERB file?

erb" that means it's an HTML file with ruby code embedded in it and it is similar to ". rhtml" extension of rails file.

What is HTML slim?

What's Slim? Slim is a page-templating language that minimizes markup and syntax. It removes most of the extra "programming-like" symbols from HTML so that your code looks cleaner. Slim also adds if-else statements, loops, includes, and more.


1 Answers

As expected, the latter solution worked. The trick is to pass -e flag, letting the interpreter know that you're converting to erb. So the full command is:

 slimrb -e `foo.html.slim` > foo.html.erb

EDIT:

to make sure that the interperter omits unnecessary calls to Temple::Utils.escape_html((...)) before variables, you can pass the --rails flag like so:

slimrb --rails -e `foo.html.slim` > foo.html.erb
like image 113
dimitry_n Avatar answered Sep 18 '22 02:09

dimitry_n