11

I have many html.slim files that I would like to convert into html.erb files since I am not familiar with the slim syntax. Is there a converter for slim to erb?

I found a converter for html to slim that has the functionality I am looking for but it does not do slim to erb. http://html2slim.herokuapp.com/

MicFin
  • 2,431
  • 4
  • 32
  • 59

4 Answers4

11

try the slimrb utility...

slimrb --erb html.slim
Abhinav Sood
  • 799
  • 6
  • 23
new publicvoid
  • 121
  • 1
  • 3
2

I believe, you're actually looking for Slim::ERBConverter itself.

  • If you are on rails projects, check out slim-rails how to integrate to your project.

  • If you're on CLI, you even could use slimrb to easily convert many html.slim files into html.erb files with a single command.

  • If you prefer online converter like you refer, there are simple online tools to help you convert e.g Slim to HTML / ERB, which is basically utilized Slim::ERBConverter itself.

gizipp
  • 41
  • 1
  • 5
0

Just to expand on @newpublicvoid answer. I enjoyed removing some slim from a project I took over like this:

slimrb --erb  app/views/shop/cart.html.slim > app/views/shop/cart.html.erb

which Obviously just writes the converted erb to file. it then needs some minor fixing up and beautifying which is easily done, for eg in VS Code with https://github.com/aliariff/vscode-erb-beautify

there is a repo for doing this to all your views at once (https://github.com/berycoin-project/slim2erb/blob/master/slim2erb.sh), but I find that a bit heavy handed and resulted in a lot of fixes being required in one go. Easier just to convert templates as and when I need when maintaining an old site with slim.

btw, I don't think slim is terrible or anything, I just prefer ERB.

Will
  • 4,498
  • 2
  • 38
  • 65
-5

They are both templating engines and they have different functionality.

I doubt there will ever be any kind of such a converter, because it is very complex task that requires "understanding in higher level" of the context, "understanding" why something is made in one template and recreating the same thing in another template engine. There is a reason why programmers will not likely be replaced anytime soon by AI - because it is hard to write a code that "understands in higher level" another code.

I do not see more than a few cases one should need such tool. Such tool would need to support both language functions, but they are not fully compatible (there are stuff, that exists in one, and is not available in another, and visa-versa).

To answer your original question, how you can convert slim to erb, my answer is, that you need to learn both languages and do it manually.

My suggestion is that you learn the one you are planning to use and stick with it (My suggestion would be ERB). If you are newbie, don't jump on different engines, stick with one, learn it to the bone and then, after years of experience, try doing the same or doing better with other engines.

Deele
  • 3,728
  • 2
  • 33
  • 51
  • 3
    Conceptually I believe this answer is accurate, however using the ERBConverter as suggested by Peter was a more actionable answer. Thank you for the help. That is great advice and I will take it! – MicFin Jun 16 '14 at 17:13