Module: ActionView::Helpers::TabsHelper::InstanceMethods

Defined in:
lib/simple_tabs.rb

Instance Method Summary collapse

Instance Method Details

#content_tag_with_tabs(name, content_or_options_with_block = nil, options = nil, escape = true, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/simple_tabs.rb', line 76

def (name, content_or_options_with_block = nil, options = nil, escape = true, &block)
  if block_given? && content_or_options_with_block.is_a?(Hash)
    options = content_or_options_with_block
  end

  tab = format_tab(options.try(:delete, :tab))
  #logger.info(tab)

  unless tab.blank?
    @default_tab ||= tab
    @current_tab ||= params[@name]
    options[:class] ||= ''
    options[:class] << (current_tab?(tab) ? ' tab_active' : ' tab_inactive')
    options[:class] << " tab_#{tab}"
  end

  (name, content_or_options_with_block, options, 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

Returns:

  • (Boolean)


54
55
56
57
# File 'lib/simple_tabs.rb', line 54

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/simple_tabs.rb', line 59

def tabs_for(name, tabs=[])
  @tabs = tabs
  @name = name
  @default_tab ||= format_tab(@tabs.try(:first))
  @current_tab ||= format_tab(params[@name])
  #logger.info("TABLIST #{default_tab} #{@default_tab} #{current_tab}")
  (:ul, :class=>'tab_list') do
    safe_join(tabs.map do |tab|
      tab_id = format_tab(tab)
      css_class = current_tab?(tab_id) ? 'active' : 'inactive'
      (:li, :class=>css_class) do
        link_to(tab, params.merge(@name=>tab_id))
      end # li
    end)
  end # ul
end