Class: Tabnav::Tab
- Inherits:
-
Object
- Object
- Tabnav::Tab
- Defined in:
- lib/tabnav/tab.rb
Instance Attribute Summary collapse
-
#link_options ⇒ Object
The link options (if any).
-
#link_url ⇒ Object
The link destination.
-
#name ⇒ Object
The name of this tab.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Returns
true
of this tab is highlighted. -
#highlights_on(rule) ⇒ Object
Adds a highlight condition to this tab.
-
#initialize(template, params, html_options = {}) ⇒ Tab
constructor
:nodoc:.
-
#links_to(url, link_options = {}) ⇒ Object
Sets the link destination.
-
#named(text) ⇒ Object
Sets the name of this tab.
-
#render ⇒ Object
:nodoc:.
Constructor Details
#initialize(template, params, html_options = {}) ⇒ Tab
:nodoc:
4 5 6 7 8 9 10 |
# File 'lib/tabnav/tab.rb', line 4 def initialize(template, params, = {}) # :nodoc: @html_options = @params = params @template = template @name = '' @active = false end |
Instance Attribute Details
#link_options ⇒ Object
The link options (if any)
19 20 21 |
# File 'lib/tabnav/tab.rb', line 19 def @link_options end |
#link_url ⇒ Object
The link destination
16 17 18 |
# File 'lib/tabnav/tab.rb', line 16 def link_url @link_url end |
#name ⇒ Object
The name of this tab
13 14 15 |
# File 'lib/tabnav/tab.rb', line 13 def name @name end |
Instance Method Details
#active? ⇒ Boolean
Returns true
of this tab is highlighted.
51 52 53 |
# File 'lib/tabnav/tab.rb', line 51 def active? @active end |
#highlights_on(rule) ⇒ Object
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.
42 43 44 45 46 47 48 |
# File 'lib/tabnav/tab.rb', line 42 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 = {}) ⇒ Object
Sets the link destination.
link_options
is an option hash of options that will be passed through to the link_to call.
30 31 32 33 |
# File 'lib/tabnav/tab.rb', line 30 def links_to(url, = {}) @link_url = url @link_options = end |
#named(text) ⇒ Object
Sets the name of this tab. This will be used as the contents of the link or span
22 23 24 |
# File 'lib/tabnav/tab.rb', line 22 def named(text) @name = text end |
#render ⇒ Object
:nodoc:
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tabnav/tab.rb', line 55 def render # :nodoc: @html_options[:class] = "#{@html_options[:class]} active".strip if self.active? partial = @html_options.delete(:tab_content_partial) @template.content_tag(:li, @html_options) do if partial @template.render :partial => partial, :locals => {:tab => self} elsif @link_url @template.link_to @name, @link_url, @link_options else @template.content_tag :span, @name end end end |