Class: SilkLayout::HTML::Node
- Inherits:
-
Object
- Object
- SilkLayout::HTML::Node
- Defined in:
- lib/silk_layout/html/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#computed_style ⇒ Object
Returns the value of attribute computed_style.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
- .build_element_node(node, parent) ⇒ Object
- .build_text_node(node, parent) ⇒ Object
- .from_nokogiri(node, parent = nil) ⇒ Object
Instance Method Summary collapse
- #element? ⇒ Boolean
-
#initialize(tag:, attributes:, children:, text: nil, parent: nil) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(tag:, attributes:, children:, text: nil, parent: nil) ⇒ Node
Returns a new instance of Node.
10 11 12 13 14 15 16 |
# File 'lib/silk_layout/html/node.rb', line 10 def initialize(tag:, attributes:, children:, text: nil, parent: nil) @tag = tag @attributes = attributes @children = children @text = text @parent = parent end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/silk_layout/html/node.rb', line 6 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
7 8 9 |
# File 'lib/silk_layout/html/node.rb', line 7 def children @children end |
#computed_style ⇒ Object
Returns the value of attribute computed_style.
8 9 10 |
# File 'lib/silk_layout/html/node.rb', line 8 def computed_style @computed_style end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/silk_layout/html/node.rb', line 7 def parent @parent end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
6 7 8 |
# File 'lib/silk_layout/html/node.rb', line 6 def tag @tag end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/silk_layout/html/node.rb', line 6 def text @text end |
Class Method Details
.build_element_node(node, parent) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/silk_layout/html/node.rb', line 43 def self.build_element_node(node, parent) element = new( tag: node.name, attributes: node.attributes.transform_values(&:value), children: [], parent: parent ) element.children = node.children.map { |child| from_nokogiri(child, element) }.compact element end |
.build_text_node(node, parent) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/silk_layout/html/node.rb', line 30 def self.build_text_node(node, parent) text = node.text.to_s return nil if text.empty? new( tag: nil, attributes: {}, children: [], text: text, parent: parent ) end |
.from_nokogiri(node, parent = nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/silk_layout/html/node.rb', line 22 def self.from_nokogiri(node, parent = nil) if node.text? build_text_node(node, parent) else build_element_node(node, parent) end end |
Instance Method Details
#element? ⇒ Boolean
18 19 20 |
# File 'lib/silk_layout/html/node.rb', line 18 def element? !tag.nil? end |