Class: Tabnav::Tab
- Inherits:
-
Object
- Object
- Tabnav::Tab
- Defined in:
- lib/tabnav/tab.rb
Direct Known Subclasses
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
if this tab is highlighted. -
#has_link? ⇒ Boolean
Returns true if this tab has had a link set on it.
-
#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 11 |
# File 'lib/tabnav/tab.rb', line 4 def initialize(template, params, = {}) # :nodoc: @partial = .delete(:tab_content_partial) @html_options = @params = params @template = template @name = '' @active = false end |
Instance Attribute Details
#link_options ⇒ Object
The link options (if any)
20 21 22 |
# File 'lib/tabnav/tab.rb', line 20 def @link_options end |
#link_url ⇒ Object
The link destination
17 18 19 |
# File 'lib/tabnav/tab.rb', line 17 def link_url @link_url end |
#name ⇒ Object
The name of this tab
14 15 16 |
# File 'lib/tabnav/tab.rb', line 14 def name @name end |
Instance Method Details
#active? ⇒ Boolean
Returns true
if this tab is highlighted.
57 58 59 |
# File 'lib/tabnav/tab.rb', line 57 def active? @active end |
#has_link? ⇒ Boolean
Returns true if this tab has had a link set on it.
23 24 25 |
# File 'lib/tabnav/tab.rb', line 23 def has_link? !! @link_url 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.
48 49 50 51 52 53 54 |
# 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 = {}) ⇒ Object
Sets the link destination.
link_options
is an option hash of options that will be passed through to the link_to call.
36 37 38 39 |
# File 'lib/tabnav/tab.rb', line 36 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
28 29 30 |
# File 'lib/tabnav/tab.rb', line 28 def named(text) @name = text end |
#render ⇒ Object
:nodoc:
61 62 63 64 65 66 67 |
# File 'lib/tabnav/tab.rb', line 61 def render # :nodoc: = @html_options.dup [:class] = "#{[:class]} active".strip if self.active? @template.content_tag(:li, ) do render_tab end end |