Class: Undies::ElementNode
- Inherits:
-
Object
- Object
- Undies::ElementNode
- Defined in:
- lib/undies/element_node.rb
Instance Attribute Summary collapse
-
#cached ⇒ Object
readonly
ElementNode is specifically used to handle nested element markup.
-
#element ⇒ Object
readonly
ElementNode is specifically used to handle nested element markup.
-
#io ⇒ Object
readonly
ElementNode is specifically used to handle nested element markup.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attrs(*args) ⇒ Object
- #element_node(element_node) ⇒ Object
- #flush ⇒ Object
-
#initialize(io, element) ⇒ ElementNode
constructor
A new instance of ElementNode.
- #partial(partial) ⇒ Object
- #pop ⇒ Object
- #push ⇒ Object
- #text(raw) ⇒ Object
- #to_s ⇒ Object
-
#to_str(*args) ⇒ Object
(also: #inspect)
overriding this because the base Node class defines a ‘to_s’ method that needs to be honored.
Constructor Details
#initialize(io, element) ⇒ ElementNode
Returns a new instance of ElementNode.
17 18 19 20 21 22 23 |
# File 'lib/undies/element_node.rb', line 17 def initialize(io, element) @io = io @cached = nil @element = element @start_tag_written = false end |
Instance Attribute Details
#cached ⇒ Object (readonly)
ElementNode is specifically used to handle nested element markup.
15 16 17 |
# File 'lib/undies/element_node.rb', line 15 def cached @cached end |
#element ⇒ Object (readonly)
ElementNode is specifically used to handle nested element markup.
15 16 17 |
# File 'lib/undies/element_node.rb', line 15 def element @element end |
#io ⇒ Object (readonly)
ElementNode is specifically used to handle nested element markup.
15 16 17 |
# File 'lib/undies/element_node.rb', line 15 def io @io end |
Instance Method Details
#==(other) ⇒ Object
78 79 80 81 |
# File 'lib/undies/element_node.rb', line 78 def ==(other) other.instance_variable_get("@io") == @io && other.instance_variable_get("@element") == @element end |
#attrs(*args) ⇒ Object
25 26 27 |
# File 'lib/undies/element_node.rb', line 25 def attrs(*args) @element.__attrs(*args) end |
#element_node(element_node) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/undies/element_node.rb', line 33 def element_node(element_node) if !@start_tag_written # with newline # -1 level offset b/c we are operating on the element build one deep write_start_tag(@io.newline, -1) end write_cached @cached = element_node end |
#flush ⇒ Object
47 48 49 50 51 |
# File 'lib/undies/element_node.rb', line 47 def flush write_cached @cached = nil self end |
#partial(partial) ⇒ Object
43 44 45 |
# File 'lib/undies/element_node.rb', line 43 def partial(partial) element_node(partial) end |
#pop ⇒ Object
58 59 60 61 62 |
# File 'lib/undies/element_node.rb', line 58 def pop flush @io.pop write_end_tag end |
#push ⇒ Object
53 54 55 56 |
# File 'lib/undies/element_node.rb', line 53 def push @io.push(@cached) @cached = nil end |
#text(raw) ⇒ Object
29 30 31 |
# File 'lib/undies/element_node.rb', line 29 def text(raw) raise ElementAPIError, "can't insert text markup in an element build block - pass in as a content argument instead" end |
#to_s ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/undies/element_node.rb', line 64 def to_s @io.push(self) @element.__build flush @io.pop write_end_tag # needed so the `write_cached` calls on ElementNode and RootNode won't add # anything else to the IO return "" end |
#to_str(*args) ⇒ Object Also known as: inspect
overriding this because the base Node class defines a ‘to_s’ method that needs to be honored
85 86 87 |
# File 'lib/undies/element_node.rb', line 85 def to_str(*args) "Undies::ElementNode:#{self.object_id} @element=#{@element.inspect}" end |