Skip to content

Instantly share code, notes, and snippets.

@weyus
Created January 25, 2010 21:47
Show Gist options
  • Save weyus/286289 to your computer and use it in GitHub Desktop.
Save weyus/286289 to your computer and use it in GitHub Desktop.
def show_flash(level = :notice)
unless flash[level].nil?
html = <<-EOT
<blockquote id="flash-#{level.to_s}" class="#{level.to_s}">
<p>#{flash[level]}</p>
</blockquote>
EOT
unless level == :error
html << update_page_tag do |page|
page.delay(10) { page["flash-#{level.to_s}"].visual_effect(:fade) }
end
end
html
end
end
module Tabnav
module TabnavHelper
protected
# renders the tabnav
def tabnav(tabnav_sym)
tn = tabnav_sym.to_tabnav
tabs = tn.tabs
result = tag('div', tn.html_options ,true)
result << tag('ul', {} , true)
tabs.each do |t|
tab = t.deep_clone # I need this in order to avoid binding sharing issues
tab.page=self
if tab.visible?
tab.html_options[:class] = 'active' if tab.highlighted?(params)
tab.html_options[:title] = tab.title if tab.title
li_options = tab.html_options[:id] ? {:id => tab.html_options[:id] + '_container'} : {}
result << tag('li', li_options, true)
if tab.link.empty?
result << content_tag('span', tab.name, tab.html_options)
else
result << link_to(tab.name, tab.link, tab.html_options)
end
result << "</li> \n"
end
end
result << "</ul></div>"
css = ''
begin
css = capture do
render :partial => "tabnav/#{tn.html_options[:class]}",
:locals => { :tabs => tabnav_sym.to_tabnav.tabs }
end
rescue
end
result + css
end
# adds the content div
def start_tabnav(tabnav_sym)
tn = tabnav_sym.to_tabnav
result = tabnav(tabnav_sym)
result << "\n"
result << tag('div', {:id => tn.html_options[:id] + '_content',
:class => tn.html_options[:class] + '_content'}, true)
result
end
def end_tabnav
"</div>"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment