How can I convert html.slim files to html or html.erb?
Asked Answered
S

4

12

I need to convert the html.slim files in my Ruby on Rails application to html.erb. Is there any easy way to do it? I tried many options listed in Stack Overflow and other sites. But nothing worked for me. I found a converter http://slim2html.raving.systems/ and a html to slim converter http://html2slim.herokuapp.com/ . It is not of my use since it does not work the other way around. Should I have to do it manually? Please help.

Stagemanage answered 4/2, 2015 at 7:44 Comment(0)
B
14

You can!

First, make sure you have already installed slim-rails. You can install it by calling gem install slim-rails.

Then write something in the input.html

Finally, you open the terminal and call:

echo `slimrb input.html` > output.html

NOTE: it is `, not ' or "

Open file output.html, that's what you looking for!

Brody answered 6/5, 2015 at 8:50 Comment(0)
G
29

I just did it using Codepen.io

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.

You can then copy that out.

Gunplay answered 27/5, 2016 at 21:57 Comment(1)
Just a friendly reminder that all the data you fill on Codepen is sent to their server. Make sure to not paste confidential data on Codepen or any other similar web tool. Happy Cyber Security Awareness Month. :)Marked
B
14

You can!

First, make sure you have already installed slim-rails. You can install it by calling gem install slim-rails.

Then write something in the input.html

Finally, you open the terminal and call:

echo `slimrb input.html` > output.html

NOTE: it is `, not ' or "

Open file output.html, that's what you looking for!

Brody answered 6/5, 2015 at 8:50 Comment(0)
B
4

@duykhoa's answer is best and best for converting a whole file, but you can also use the inspector to see and copy the compiled HTML (CTRL+SHIFT+I in Chrome or right-click and then click on inspect to inspect an element).

Bullhead answered 5/7, 2016 at 12:54 Comment(0)
A
4
slimrb -e foo.html.slim foo.html.erb

so on my ubuntu/git bash console, this is what is do it , easily

mike@mike-PORTEGE-Z30t-A:~/workspace/demo$ slimrb -e app/views/layouts/_header.html.slim app/views/layouts/_header.html.erb

and i get my new converted .erb file for .slim file.

Automate answered 8/3, 2020 at 3:19 Comment(1)
The -e switch was exactly what I needed to keep function calls and the likes. Thanks! :)Sticky

© 2022 - 2024 — McMap. All rights reserved.