class Tabnav::Tab
Attributes
link_options[RW]
The link options (if any)
link_url[RW]
The link destination
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
has_link?()
click to toggle source
Returns true if this tab has had a link set on it.
# File lib/tabnav/tab.rb, line 23 def has_link? !! @link_url 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
links_to(url, link_options = {})
click to toggle source
Sets the link destination.
link_options
is an option hash of options that will be passed through to the link_to call.
# File lib/tabnav/tab.rb, line 36 def links_to(url, link_options = {}) @link_url = url @link_options = link_options 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