How HAML can recognize the end of the block?

狂风中的少年 提交于 2019-12-13 15:19:42

问题


= form_for(:subject, :url => {:action => "create"}) do |f|
    = render :partial => "form", :locals => {:f => f}
    #form_buttons= submit_tag "Create Subject"

Noticed that form_for has a "do",so it needs a "end", but how does HAML knows where to end the "end" ?

Sorry about my English,hope you can understand what am I talking about!


回答1:


HAML uses indentation to delimit blocks in the same way the Python language does. Perhaps you should read a basic tutorial or WIKI for more information.

= form_for(:subject, :url => {:action => "create"}) do |f|
    = render :partial => "form", :locals => {:f => f}
    #you can use f here
# you can't use f here



回答2:


HAML uses indentation for block structure.
More simply put, when the code actually 'outdents' it's an implied end (either to the html tag OR the ruby do-end block). So what in html/ruby would be

...
loop1
  loop2
    code_for_loop2
  end # of loop2
end # of loop1
...

in haml becomes
...
loop1
  loop2
    code for loop2
...

p.s. indent by 2 also, spaces not tabs.



来源:https://stackoverflow.com/questions/5770546/how-haml-can-recognize-the-end-of-the-block

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