class Fume::Nav::NavTag

Attributes

active_class[RW]
current[RW]
helper[RW]
hide_if_empty[RW]
inactive_class[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# 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

Public Instance Methods

apply(value, &block) click to toggle source
# 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) click to toggle source
# File lib/fume/nav/nav_tag.rb, line 32
def apply_active_options(value, options)
  apply(value) do |cls|
    if options[:class]
      options[:class] += " #{cls}"
    else
      options[:class] = "#{cls}"
    end
  end

  @empty = false
end
apply_content(value, &block) click to toggle source
# 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) click to toggle source
# File lib/fume/nav/nav_tag.rb, line 27
def content_tag(value, tag_name, options = {}, &block)
  apply_active_options(value, options)
  helper.content_tag(tag_name, options, &block)
end
hide?() click to toggle source
# File lib/fume/nav/nav_tag.rb, line 13
def hide?
  hide_if_empty && @empty
end
li_tag(value, options = {}, &block) click to toggle source
# File lib/fume/nav/nav_tag.rb, line 17
def li_tag(value, options = {}, &block)
  content_tag(value, :li, options, &block)
end
match?(source, target) click to toggle source
# 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