Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Created June 16, 2011 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save noahhendrix/1030466 to your computer and use it in GitHub Desktop.
Save noahhendrix/1030466 to your computer and use it in GitHub Desktop.
Content Block Class
class ContentBlock
attr_accessor :template
delegate :content_tag, :to => :template
def initialize(template, options = {}, block)
@template = template
@title = options[:title] || ''
@block = block
@tabs = []
end
def render!
content_tag(:div, class: 'block') do
render_header + instance_eval(&@block)
end
end
def render_header
content_tag(:div, class: 'head') do
content_tag(:div, '', class: 'bheadl') +
content_tag(:div, '', class: 'bheadr') +
content_tag(:h2, @title) +
content_tag(:ul, class: 'tabs') do
@tabs.map { |tab| content_tag(:li, tab[0]) }.join
end
end
end
def tab(*args, &block)
yield
end
end
def content(options = {}, &block)
ContentBlock.new(self, options, block).render!
end
<%= content(:title => 'Big text box with tabs') do |b| %>
<%= b.tab(:title => 'Tab 1') do %>
<h3>This is the first tab</h3>
<p>Maecenas facilisis interdum rhoncus. Sed laoreet vulputate lacus sit amet aliquam. Praesent vitae sapien orci. Mauris nec purus in mi accumsan convallis non et lorem. Nunc tincidunt consequat risus, ac tincidunt nibh hendrerit at. Nullam sit amet nisi eget magna lacinia ullamcorper non sed sem. Ut ornare consequat commodo. Donec vitae justo risus. Nulla ornare posuere egestas. Nulla varius purus quis lacus placerat tincidunt.</p>
<% end %>
<%= b.tab(:title => 'Tab 2') do %>
<h3>This is the first tab</h3>
<p>Maecenas facilisis interdum rhoncus. Sed laoreet vulputate lacus sit amet aliquam. Praesent vitae sapien orci. Mauris nec purus in mi accumsan convallis non et lorem. Nunc tincidunt consequat risus, ac tincidunt nibh hendrerit at. Nullam sit amet nisi eget magna lacinia ullamcorper non sed sem. Ut ornare consequat commodo. Donec vitae justo risus. Nulla ornare posuere egestas. Nulla varius purus quis lacus placerat tincidunt.</p>
<% end %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment