class Tabnav::Tab

Attributes

name[RW]

The name of this tab

Public Instance Methods

active?() click to toggle source

Returns true if this tab is highlighted.

# File lib/tabnav/tab.rb, line 57
def active?
  @active
end
highlights_on(rule) click to toggle source

Adds a highlight condition to this tab. rule can be one of the following:

  • A Hash: The tab will be highlighted if all the values in the given hash match the params hash (strings and symbols are treated as equivelent).

  • A Proc: The proc will be called, and the tab will be highlighted if it returns true.

If multiple highlight conditions are given, the tab will be highlighted if any of them match.

# File lib/tabnav/tab.rb, line 48
def highlights_on(rule)
  if rule.is_a?(Hash)
    @active |= rule.with_indifferent_access.all? {|k, v| @params[k].to_s == v.to_s}
  elsif rule.is_a?(Proc)
    @active |= rule.call
  end
end
named(text) click to toggle source

Sets the name of this tab. This will be used as the contents of the link or span

# File lib/tabnav/tab.rb, line 28
def named(text)
  @name = text
end

Private Instance Methods

render_tab() click to toggle source
# File lib/tabnav/tab.rb, line 71
def render_tab
  if @partial
    @template.render :partial => @partial, :locals => {:tab => self}
  elsif has_link?
    @template.link_to @name, @link_url, @link_options
  else
    @template.content_tag :span, @name
  end
end