class Navigasmic::Builder::CrumbBuilder

Public Class Methods

new(context, name, options, &block) click to toggle source
Calls superclass method
# File lib/navigasmic/builders/crumb_builder.rb, line 23
def initialize(context, name, options, &block)
  super
  @path = []
  @crumb_path = []
end

Public Instance Methods

group(label = nil, options = {}, &block) click to toggle source
# File lib/navigasmic/builders/crumb_builder.rb, line 34
def group(label = nil, options = {}, &block)
  if block_given?
    @crumb_path << label_for(label, false, false, options) if label
    capture(&block)
  end
end
item(label, *args, &block) click to toggle source
# File lib/navigasmic/builders/crumb_builder.rb, line 41
def item(label, *args, &block)
  options = args.extract_options!
  options = flatten_and_eval_options(options)
  return '' unless visible?(options)

  merge_classes!(options, @config.item_class)
  item = Navigasmic::Item.new(label, extract_and_determine_link(label, options, *args), visible?(options), options)

  if item.highlights_on?(@context.request.path, @context.params)
    @crumb_path << label_for(label, false, false, options)
    @path += @crumb_path
    @crumb_path = []
  end

  if block_given?
    @crumb_path << label_for(label, item.link? ? item.link : false, false, options) if label
    capture(&block)
  end
end
render() click to toggle source
# File lib/navigasmic/builders/crumb_builder.rb, line 29
def render
  capture(&@definition)
  @path.join(' ').html_safe
end

Private Instance Methods

label_for(label, link, is_nested = false, options = {}) click to toggle source
# File lib/navigasmic/builders/crumb_builder.rb, line 63
def label_for(label, link, is_nested = false, options = {})
  if label.present?
    label = @context.instance_exec(label, options, !!link, is_nested, &@config.label_generator).html_safe
  end
  label = @context.instance_exec(label, link, options.delete(:link_html) || {}, is_nested, &@config.link_generator).html_safe if link
  label
end
merge_classes!(hash, classname) click to toggle source
# File lib/navigasmic/builders/crumb_builder.rb, line 71
def merge_classes!(hash, classname)
  return if classname.blank?
  hash[:class] = (hash[:class] ? "#{hash[:class]} " : '') << classname
end