开发者

How HAML can recognize the end of the block?

开发者_如何学Python= 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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜