Sha256: bc9fa922945839db5de47a5398cec1df1b53e30dbef49f9a0c578b0f827c238a
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
module Undies class RootAPIError < RuntimeError; end class RootNode # Used internally to implement the markup tree nodes. Each node caches and # processes nested markup and elements. At each node level in the markup # tree, nodes/markup are cached until the next sibling node or raw markup # is defined, or until the node is flushed. This keeps nodes from bloating # memory on large documents and allows for output streaming. # RootNode is specifically used to handle root document markup. attr_reader :io, :cached def initialize(io) @io = io @cached = nil end def attrs(*args) raise RootAPIError, "can't call '__attrs' at the root node level" end def text(raw) write_cached @cached = "#{@io.line_indent}#{raw.to_s}#{@io.newline}" end def element_node(element_node) write_cached @cached = element_node end def partial(partial) text(partial) end def flush write_cached @cached = nil self end def push @io.push(@cached) @cached = nil end def pop flush end private def write_cached @io << @cached.to_s end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
undies-3.1.0 | lib/undies/root_node.rb |
undies-3.0.0 | lib/undies/root_node.rb |
undies-3.0.0.rc.3 | lib/undies/root_node.rb |