Module: ActionView::Helpers::TabsHelper::InstanceMethods
- Defined in:
- lib/simple_tabs.rb
Instance Method Summary collapse
- #content_tag_with_tabs(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
-
#current_tab?(tab) ⇒ Boolean
@current_tab = nil def current_tab=(tab) @current_tab = tab.blank? ? nil : tab end.
- #tabs_for(name, tabs = []) ⇒ Object
Instance Method Details
#content_tag_with_tabs(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/simple_tabs.rb', line 74 def content_tag_with_tabs(name, = nil, = nil, escape = true, &block) if block_given? && .is_a?(Hash) = end tab = format_tab(.try(:delete, :tab)) #logger.info(tab) unless tab.blank? @default_tab ||= tab @current_tab ||= params[@name] [:class] ||= '' [:class] << (current_tab?(tab) ? ' tab_active' : ' tab_inactive') [:class] << " tab_#{tab}" end content_tag_without_tabs(name, , , escape, &block) end |
#current_tab?(tab) ⇒ Boolean
@current_tab = nil
def current_tab=(tab)
@current_tab = tab.blank? ? nil : tab
end
def default_tab=(tab)
@default_tab = tab.blank? ? nil : tab
end
def default_tab
@default_tab
end
52 53 54 55 |
# File 'lib/simple_tabs.rb', line 52 def current_tab?(tab) #logger.info("Comparing #{tab} to #{@current_tab.inspect} and #{@default_tab.inspect}") tab.to_s.casecmp(@current_tab || @default_tab || '') == 0 end |
#tabs_for(name, tabs = []) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/simple_tabs.rb', line 57 def tabs_for(name, tabs=[]) @tabs = tabs @name = name @default_tab ||= @tabs.try(:first) @current_tab ||= params[@name] #logger.info("TABLIST #{default_tab} #{@default_tab} #{current_tab}") content_tag(:ul, :class=>'tab_list') do safe_join(tabs.map do |tab| tab_id = format_tab(tab) css_class = current_tab?(tab_id) ? 'active' : 'inactive' content_tag(:li, :class=>css_class) do link_to(tab, params.merge(@name=>tab_id)) end # li end) end # ul end |