Class: Bemer::Tree
- Inherits:
-
Object
- Object
- Bemer::Tree
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/bemer/tree.rb,
lib/bemer/tree/node.rb,
lib/bemer/tree/base_node.rb,
lib/bemer/tree/text_node.rb
Defined Under Namespace
Classes: BaseNode, Node, TextNode
Instance Attribute Summary collapse
-
#node_metadata ⇒ Object
readonly
Returns the value of attribute node_metadata.
-
#parent_node ⇒ Object
Returns the value of attribute parent_node.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
Instance Method Summary collapse
- #add(node) ⇒ Object
- #add_node(block = '', element = nil, bem_cascade: nil, **options, &content) ⇒ Object
- #add_text_node(content = nil, &callback) ⇒ Object
-
#initialize(template_catalog, **params) ⇒ Tree
constructor
A new instance of Tree.
- #print ⇒ Object
- #render(&block) ⇒ Object
-
#replace(node) ⇒ Object
rubocop:disable Metrics/AbcSize.
Constructor Details
Instance Attribute Details
#node_metadata ⇒ Object (readonly)
Returns the value of attribute node_metadata.
17 18 19 |
# File 'lib/bemer/tree.rb', line 17 def @node_metadata end |
#parent_node ⇒ Object
Returns the value of attribute parent_node.
16 17 18 |
# File 'lib/bemer/tree.rb', line 16 def parent_node @parent_node end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
17 18 19 |
# File 'lib/bemer/tree.rb', line 17 def pipeline @pipeline end |
Instance Method Details
#add(node) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bemer/tree.rb', line 53 def add(node) if need_replace_parent_node? parent_node.replacers << node else (node.object_id) parent_node.nil? ? root_nodes << node : parent_node.children << node end nil end |
#add_node(block = '', element = nil, bem_cascade: nil, **options, &content) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/bemer/tree.rb', line 65 def add_node(block = '', element = nil, bem_cascade: nil, **, &content) bem_cascade = inherited_bem_cascade if bem_cascade.nil? = { **params, bem_cascade: bem_cascade, ** } add Node.new(self, block, element, , &content) end |
#add_text_node(content = nil, &callback) ⇒ Object
72 73 74 |
# File 'lib/bemer/tree.rb', line 72 def add_text_node(content = nil, &callback) add TextNode.new(self, content, &callback) end |
#print ⇒ Object
49 50 51 |
# File 'lib/bemer/tree.rb', line 49 def print root_nodes.each(&:print) end |
#render(&block) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/bemer/tree.rb', line 27 def render(&block) return unless block_given? builder = Builders::Tree.new(self) output = ::ActionView::OutputBuffer.new output << block.binding.receiver.capture(builder, &block) output << render_root_nodes end |
#replace(node) ⇒ Object
rubocop:disable Metrics/AbcSize
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bemer/tree.rb', line 37 def replace(node) # rubocop:disable Metrics/AbcSize siblings = parent_node.nil? ? root_nodes : parent_node.children = .delete(node.object_id) position = [:position] offset = position + node.replacers.length (position, [:last], node.replacers) (offset, siblings[position..-1]) siblings[position - 1...position] = node.replacers end |