When using HAML, is there a way to use heredoc or %Q{ … }?

大兔子大兔子 提交于 2019-12-08 06:09:21

问题


Maybe it can be put into a helper but the existing 500 lines of code has everything in the HAML code, so it is better to follow the existing code for the moment (for tight deadlines).

I found the only way working right now is

- meta_tag = %Q{\n |
  <meta ...>\n |
  <meta ...>\n |
    [...]   \n |
  } |

which is to use the "continuation character" and the \n at the same time. It'd be great if it can be simplified.


回答1:


A good way to do this would be to use the :ruby filter or load the needed content into a Ruby variable and pass it into HAML the normal way.




回答2:


I think this is what "the Tin Man" meant.

:ruby                                                                                                                                                                                        
  text =<<-EOT                                                                                                                                                                               
  Hi,                                                                                                                                                                                        
    Please find some heredoc text                                                                                                                                                            
      right here                                                                                                                                                                             

  Bye                                                                                                                                                                                        
  EOT                                                                                                                                                                                        

%pre=text                                                                                                                                                                                    

I could not add this as a comment to his post, sorry!



来源:https://stackoverflow.com/questions/3910593/when-using-haml-is-there-a-way-to-use-heredoc-or-q

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