Class: Navigasmic::Builder::ListBuilder

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

Defined Under Namespace

Classes: Configuration

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ListBuilder.


34
35
36
37
38
# File 'lib/navigasmic/builders/list_builder.rb', line 34

def initialize(context, name, options, &block)
  super
  @options[:id] ||= name.to_s.underscore unless @options.has_key?(:id)
  @options[:class] = merge_classes!(@options, @config.wrapper_class)
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_or_options = nil, options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)

44
45
46
47
48
49
50
51
52
53
# File 'lib/navigasmic/builders/list_builder.rb', line 44

def group(label_or_options = nil, options = {}, &block)
  raise ArgumentError, "Missing block for group" unless block_given?
  if label_or_options.is_a?(Hash)
    options = label_or_options
    label_or_options = nil
  end
  return '' unless visible?(options)

  concat(structure_for(label_or_options, false, options, &block))
end

#item(label, *args, &block) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/navigasmic/builders/list_builder.rb', line 55

def item(label, *args, &block)
  options = args.extract_options!
  options = flatten_and_eval_options(options)
  return '' unless visible?(options)

  item = Navigasmic::Item.new(label, extract_and_determine_link(label, options, *args), visible?(options), options)

  merge_classes!(options, @config.item_class)
  merge_classes!(options, @config.disabled_class) if item.disabled?
  merge_classes!(options, @config.highlighted_class) if item.highlights_on?(@context.request.path, @context.params)

  concat(structure_for(label, item.link? ? item.link : false, options, &block))
end

#renderObject


40
41
42
# File 'lib/navigasmic/builders/list_builder.rb', line 40

def render
  (@config.wrapper_tag, capture(&@definition), @options)
end