Class: Hensel::Builder
- Inherits:
-
Object
- Object
- Hensel::Builder
- Includes:
- Helpers::TagHelpers
- Defined in:
- lib/hensel/builder.rb,
lib/hensel/builder/item.rb,
lib/hensel/builder/node.rb
Defined Under Namespace
Constant Summary
Constants included from Helpers::TagHelpers
Helpers::TagHelpers::BOOLEAN_ATTRIBUTES, Helpers::TagHelpers::ESCAPE_REGEXP, Helpers::TagHelpers::ESCAPE_VALUES
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#add(*arguments) ⇒ Object
Adds an item to items.
-
#initialize(**options) ⇒ Builder
constructor
A new instance of Builder.
- #item_filters ⇒ Object
- #processed? ⇒ Boolean
-
#remove(text = nil, &block) ⇒ Object
Removes the item from items.
-
#render(&block) ⇒ Object
Renders the breadcrumb html.
Methods included from Helpers::TagHelpers
#append_attribute, #content_tag, #tag
Constructor Details
#initialize(**options) ⇒ Builder
Returns a new instance of Builder.
11 12 13 14 15 |
# File 'lib/hensel/builder.rb', line 11 def initialize(**) @items = [] @options = .empty? ? Hensel.configuration.parent_attributes.dup : instance_eval(&Hensel.configuration.before_load) if Hensel.configuration.before_load end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
9 10 11 |
# File 'lib/hensel/builder.rb', line 9 def items @items end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/hensel/builder.rb', line 9 def @options end |
Instance Method Details
#add(*arguments) ⇒ Object
Adds an item to items
18 19 20 21 22 |
# File 'lib/hensel/builder.rb', line 18 def add(*arguments) items << (item = Item.new(*parse_arguments(arguments))) item.parent = self item end |
#item_filters ⇒ Object
57 58 59 |
# File 'lib/hensel/builder.rb', line 57 def item_filters @item_filters ||= [] end |
#processed? ⇒ Boolean
53 54 55 |
# File 'lib/hensel/builder.rb', line 53 def processed? !!@processed end |
#remove(text = nil, &block) ⇒ Object
Removes the item from items
34 35 36 |
# File 'lib/hensel/builder.rb', line 34 def remove(text = nil, &block) block_given? ? items.delete_if(&block) : items.delete_if{|item| text == item.text } end |
#render(&block) ⇒ Object
Renders the breadcrumb html
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hensel/builder.rb', line 39 def render(&block) process! unless processed? concatenated_items = map_items do |item| if block_given? block.arity.zero? ? item.instance_eval(&block) : block.call(item) else item.render end end.join(Hensel.configuration.indentation? ? "\n" : "") content_tag(Hensel.configuration.parent_element, concatenated_items, ) end |