ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年9月3日 星期四
block in view, yield, capture
Blocks in View
Pretty Blocks in Rails Views
def admin_area(&block)<br /> if admin?<br /> concat content_tag(:div, capture(&block), :class => 'admin'), block.binding<br /> end<br />end<br />
<br />def link_to(*args,&block)<br /> if block_given?<br /> concat(super(capture(&block), *args), block.binding)<br /> else<br /> super(*args)<br /> end<br />end<br />
<br />show.html.erb<br /><% render(:layout => 'rounded') do %><br /> Rounded corners are so Web 2.0.<br /><% end %><br /><br />_rounded.html.erb:<br /><div class="rounded_box"><br /> <div class="rounded_corner_top"> </div><br /> <div class="rounded_corner_content"><%= yield %></div><br /> <div class="rounded_corner_bottom"> </div><br /></div><br />
<br />_content.html.erb<br />Rounded corners are so Web 2.0.<br /><br />show.html.erb<br /><%= render :partial => "content", :layout => "rounded" %><br />
<br /><% render(:layout => 'rounded', :locals => {:title => "What I think about rounded corners", :id => "rounded_thoughts", :background => true}) do %><br /> Rounded corners are so Web 2.0.<br /><% end %><br /><br /><div class="rounded_box"><br /> <[div class="rounded_corner_top" id="<%= id %>"]> <[/div]><br /> <% if title %><br /> <div class="rounded_title"><%= title %></div><br /> <% end %><br /> <[div class="<%= background ? "rounded_corner_content" : "rounded_corner_no_bg" %>"]><%= yield %><[/div]><br /> <div class="rounded_corner_bottom"> </div><br /></div><br />
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言