Class: Bemer::Tree::Node
Instance Attribute Summary collapse
-
#applied_modes ⇒ Object
readonly
Returns the value of attribute applied_modes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#content_replaced ⇒ Object
(also: #content_replaced?)
Returns the value of attribute content_replaced.
-
#need_replace ⇒ Object
(also: #need_replace?)
Returns the value of attribute need_replace.
-
#params ⇒ Object
Returns the value of attribute params.
-
#replacers ⇒ Object
readonly
Returns the value of attribute replacers.
Attributes inherited from BaseNode
#entity, #entity_builder, #tree
Instance Method Summary collapse
- #add_child_nodes ⇒ Object
- #apply(mode, template, **params) ⇒ Object
- #apply_next(template, **params) ⇒ Object
- #first? ⇒ Boolean
-
#initialize(tree, block = '', element = nil, **options, &content) ⇒ Node
constructor
A new instance of Node.
- #last? ⇒ Boolean
- #position ⇒ Object
- #print(level = 0) ⇒ Object
- #replace_parent_and_execute ⇒ Object
Methods inherited from BaseNode
Constructor Details
#initialize(tree, block = '', element = nil, **options, &content) ⇒ Node
Returns a new instance of Node.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bemer/tree/node.rb', line 14 def initialize(tree, block = '', element = nil, **, &content) super(tree, block, element, , &content) @applied_modes = Pipeline::MODES.map { |mode| [mode, false] }.to_h @children = [] @content_replaced = false @need_replace = false @params = tree.parent_node.nil? ? {} : Hash[tree.parent_node.params] @replacers = [] end |
Instance Attribute Details
#applied_modes ⇒ Object (readonly)
Returns the value of attribute applied_modes.
9 10 11 |
# File 'lib/bemer/tree/node.rb', line 9 def applied_modes @applied_modes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
9 10 11 |
# File 'lib/bemer/tree/node.rb', line 9 def children @children end |
#content_replaced ⇒ Object Also known as: content_replaced?
Returns the value of attribute content_replaced.
8 9 10 |
# File 'lib/bemer/tree/node.rb', line 8 def content_replaced @content_replaced end |
#need_replace ⇒ Object Also known as: need_replace?
Returns the value of attribute need_replace.
8 9 10 |
# File 'lib/bemer/tree/node.rb', line 8 def need_replace @need_replace end |
#params ⇒ Object
Returns the value of attribute params.
8 9 10 |
# File 'lib/bemer/tree/node.rb', line 8 def params @params end |
#replacers ⇒ Object (readonly)
Returns the value of attribute replacers.
9 10 11 |
# File 'lib/bemer/tree/node.rb', line 9 def replacers @replacers end |
Instance Method Details
#add_child_nodes ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/bemer/tree/node.rb', line 37 def add_child_nodes return content unless content.respond_to?(:call) builder = Builders::Tree::Element.new(tree, block) if block? content.binding.receiver.capture(builder, &content) end |
#apply(mode, template, **params) ⇒ Object
68 69 70 |
# File 'lib/bemer/tree/node.rb', line 68 def apply(mode, template, **params) tree.pipeline.apply(mode, template, self, params) end |
#apply_next(template, **params) ⇒ Object
64 65 66 |
# File 'lib/bemer/tree/node.rb', line 64 def apply_next(template, **params) tree.pipeline.apply_next(template, self, params) end |
#first? ⇒ Boolean
29 30 31 |
# File 'lib/bemer/tree/node.rb', line 29 def first? position.eql?(1) end |
#last? ⇒ Boolean
25 26 27 |
# File 'lib/bemer/tree/node.rb', line 25 def last? tree.[object_id][:last] end |
#position ⇒ Object
33 34 35 |
# File 'lib/bemer/tree/node.rb', line 33 def position tree.[object_id][:position] end |
#print(level = 0) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/bemer/tree/node.rb', line 56 def print(level = 0) super(level) children.each do |node| node.print(level + 1) end end |
#replace_parent_and_execute ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/bemer/tree/node.rb', line 45 def replace_parent_and_execute return unless block_given? old_parent_node = tree.parent_node tree.parent_node = self yield ensure tree.parent_node = old_parent_node end |