Class: Fume::Nav::NavTag
- Inherits:
-
Object
- Object
- Fume::Nav::NavTag
- Defined in:
- lib/fume/nav/nav_tag.rb
Instance Attribute Summary collapse
-
#active_class ⇒ Object
Returns the value of attribute active_class.
-
#current ⇒ Object
Returns the value of attribute current.
-
#helper ⇒ Object
Returns the value of attribute helper.
-
#hide_if_empty ⇒ Object
Returns the value of attribute hide_if_empty.
-
#inactive_class ⇒ Object
Returns the value of attribute inactive_class.
Instance Method Summary collapse
- #apply(value, &block) ⇒ Object
- #apply_active_options(value, options) ⇒ Object
- #apply_content(value, &block) ⇒ Object
- #content_tag(value, tag_name, options = {}, &block) ⇒ Object
- #hide? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ NavTag
constructor
A new instance of NavTag.
- #li_tag(value, options = {}, &block) ⇒ Object
- #link_to(value, *args, &block) ⇒ Object
- #match?(source, target) ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ NavTag
Returns a new instance of NavTag.
6 7 8 9 10 11 |
# File 'lib/fume/nav/nav_tag.rb', line 6 def initialize(attributes = {}) attributes.each_pair do |name, value| send("#{name}=", value) end @empty = true end |
Instance Attribute Details
#active_class ⇒ Object
Returns the value of attribute active_class.
4 5 6 |
# File 'lib/fume/nav/nav_tag.rb', line 4 def active_class @active_class end |
#current ⇒ Object
Returns the value of attribute current.
4 5 6 |
# File 'lib/fume/nav/nav_tag.rb', line 4 def current @current end |
#helper ⇒ Object
Returns the value of attribute helper.
4 5 6 |
# File 'lib/fume/nav/nav_tag.rb', line 4 def helper @helper end |
#hide_if_empty ⇒ Object
Returns the value of attribute hide_if_empty.
4 5 6 |
# File 'lib/fume/nav/nav_tag.rb', line 4 def hide_if_empty @hide_if_empty end |
#inactive_class ⇒ Object
Returns the value of attribute inactive_class.
4 5 6 |
# File 'lib/fume/nav/nav_tag.rb', line 4 def inactive_class @inactive_class end |
Instance Method Details
#apply(value, &block) ⇒ Object
55 56 57 58 |
# File 'lib/fume/nav/nav_tag.rb', line 55 def apply(value, &block) result = match?(value, current) block.call(result ? active_class : inactive_class) end |
#apply_active_options(value, options) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fume/nav/nav_tag.rb', line 32 def (value, ) apply(value) do |cls| if [:class] [:class] += " #{cls}" else [:class] = "#{cls}" end end @empty = false end |
#apply_content(value, &block) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/fume/nav/nav_tag.rb', line 60 def apply_content(value, &block) @empty = false apply(value) do |cls| helper.capture(cls, &block) end end |
#content_tag(value, tag_name, options = {}, &block) ⇒ Object
27 28 29 30 |
# File 'lib/fume/nav/nav_tag.rb', line 27 def content_tag(value, tag_name, = {}, &block) (value, ) helper.content_tag(tag_name, , &block) end |
#hide? ⇒ Boolean
13 14 15 |
# File 'lib/fume/nav/nav_tag.rb', line 13 def hide? hide_if_empty && @empty end |
#li_tag(value, options = {}, &block) ⇒ Object
17 18 19 |
# File 'lib/fume/nav/nav_tag.rb', line 17 def li_tag(value, = {}, &block) content_tag(value, :li, , &block) end |
#link_to(value, *args, &block) ⇒ Object
21 22 23 24 25 |
# File 'lib/fume/nav/nav_tag.rb', line 21 def link_to(value, *args, &block) = args. (value, ) helper.link_to(*args, , &block) end |
#match?(source, target) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fume/nav/nav_tag.rb', line 44 def match?(source, target) case source when Array source.each_with_index.all? { |value, index| match?(value, target[index]) } when Regexp source.match(target) else source.to_s == target.to_s end end |