Created
June 16, 2011 22:39
-
-
Save noahhendrix/1030466 to your computer and use it in GitHub Desktop.
Content Block Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def content(options = {}, &block) | |
ContentBlock.new(self, options, block).render! | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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