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

混江龙づ霸主 提交于 2019-12-04 13:14:15

问题


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'

回答1:


I was using gitbash on windows,

and this worked for me,

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



回答2:


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


来源:https://stackoverflow.com/questions/31837220/convert-html-slim-views-to-html-erb-rails-slim-erb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!