Class: Navigasmic::Builder::CrumbBuilder

Inherits:
Base
  • Object
show all
Defined in:
lib/navigasmic/builders/crumb_builder.rb

Defined Under Namespace

Classes: Configuration

Instance Method Summary collapse

Constructor Details

#initialize(context, name, options, &block) ⇒ CrumbBuilder

Returns a new instance of CrumbBuilder.



23
24
25
26
27
# File 'lib/navigasmic/builders/crumb_builder.rb', line 23

def initialize(context, name, options, &block)
  super
  @path = []
  @crumb_path = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Navigasmic::Builder::Base

Instance Method Details

#group(label = nil, options = {}, &block) ⇒ Object



34
35
36
37
38
39
# 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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

#renderObject



29
30
31
32
# File 'lib/navigasmic/builders/crumb_builder.rb', line 29

def render
  capture(&@definition)
  @path.join(' ').html_safe
end