class Undies::ElementNode
Attributes
cached[R]
ElementNode
is specifically used to handle nested element markup.
element[R]
ElementNode
is specifically used to handle nested element markup.
io[R]
ElementNode
is specifically used to handle nested element markup.
Public Class Methods
new(io, element)
click to toggle source
# File lib/undies/element_node.rb, line 17 def initialize(io, element) @io = io @cached = nil @element = element @start_tag_written = false end
Public Instance Methods
==(other)
click to toggle source
# 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)
click to toggle source
# File lib/undies/element_node.rb, line 25 def attrs(*args) @element.__attrs(*args) end
element_node(element_node)
click to toggle source
# 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()
click to toggle source
# File lib/undies/element_node.rb, line 47 def flush write_cached @cached = nil self end
partial(partial)
click to toggle source
# File lib/undies/element_node.rb, line 43 def partial(partial) element_node(partial) end
pop()
click to toggle source
# File lib/undies/element_node.rb, line 58 def pop flush @io.pop write_end_tag end
push()
click to toggle source
# File lib/undies/element_node.rb, line 53 def push @io.push(@cached) @cached = nil end
text(raw)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
overriding this because the base Node class defines a 'to_s' method that needs to be honored
# File lib/undies/element_node.rb, line 85 def to_str(*args) "Undies::ElementNode:#{self.object_id} @element=#{@element.inspect}" end
Also aliased as: inspect
Private Instance Methods
write_cached()
click to toggle source
# File lib/undies/element_node.rb, line 92 def write_cached @io << @cached.to_s end
write_content()
click to toggle source
# File lib/undies/element_node.rb, line 101 def write_content @io << @element.__content end
write_end_tag(level_offset=0)
click to toggle source
# File lib/undies/element_node.rb, line 105 def write_end_tag(level_offset=0) if !@start_tag_written write_start_tag('', level_offset) write_content @io << "#{@element.__end_tag}#{@io.newline}" else @io << "#{@io.line_indent(level_offset)}#{@element.__end_tag}#{@io.newline}" end end
write_start_tag(newline='', level_offset=0)
click to toggle source
# File lib/undies/element_node.rb, line 96 def write_start_tag(newline='', level_offset=0) @io << "#{@io.line_indent(level_offset)}#{@element.__start_tag}#{newline}" @start_tag_written = true end