Skip to content

Instantly share code, notes, and snippets.

@markevans
Created May 24, 2010 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markevans/411722 to your computer and use it in GitHub Desktop.
Save markevans/411722 to your computer and use it in GitHub Desktop.
# Helper file
class Block < BlockHelpers::Base
def initialize(opts={})
@opts = opts
end
def display(body)
content_tag :div, body, :class => "block #{@opts[:class]}"
end
class Head < BlockHelpers::Base
def display(body)
content_tag :div, body, :class => 'block_head'
end
end
class Content < BlockHelpers::Base
def display(body)
content_tag :div, body, :class => 'block_content'
end
end
end
# Views
<% block :class => 'centre login' do |b| %>
<% b.head do |bh| %>
CONTENT FOR BLOCK_HEAD
<% end %>
<% b.content do |bc| %>
CONTENT FOR BLOCK_CONTENT
<% end %>
<% end %>
# Output
<div class="block centre login">
<div class="block_head">
CONTENT FOR BLOCK_HEAD
</div>
<div class="block_content">
CONTENT FOR BLOCK_CONTENT
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment