Class: Undies::NodeStack
- Inherits:
-
Object
- Object
- Undies::NodeStack
- Defined in:
- lib/undies/node_stack.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#cached_node ⇒ Object
Returns the value of attribute cached_node.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#stack ⇒ Object
readonly
Returns the value of attribute stack.
Class Method Summary collapse
-
.create(output) ⇒ Object
the stack first caches new nodes before pushing them onto the stack and node output is buffered as new nodes are pushed.
Instance Method Summary collapse
- #clear_cached ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
- #flush ⇒ Object
-
#initialize(output) ⇒ NodeStack
constructor
A new instance of NodeStack.
- #last ⇒ Object (also: #current)
- #node(node) ⇒ Object
- #pop(*args) ⇒ Object
- #push(node) ⇒ Object
- #size ⇒ Object (also: #level)
Constructor Details
#initialize(output) ⇒ NodeStack
Returns a new instance of NodeStack.
20 21 22 23 24 25 |
# File 'lib/undies/node_stack.rb', line 20 def initialize(output) @stack = [] @cached_node = nil @output = output @written_level = 0 end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
17 18 19 |
# File 'lib/undies/node_stack.rb', line 17 def buffer @buffer end |
#cached_node ⇒ Object
Returns the value of attribute cached_node.
18 19 20 |
# File 'lib/undies/node_stack.rb', line 18 def cached_node @cached_node end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
17 18 19 |
# File 'lib/undies/node_stack.rb', line 17 def output @output end |
#stack ⇒ Object (readonly)
Returns the value of attribute stack.
17 18 19 |
# File 'lib/undies/node_stack.rb', line 17 def stack @stack end |
Class Method Details
Instance Method Details
#clear_cached ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/undies/node_stack.rb', line 64 def clear_cached node_to_push, self.cached_node = self.cached_node, nil if node_to_push push(node_to_push) node_to_push.class.builds(node_to_push).each { |build| build.call } clear_cached pop end end |
#empty? ⇒ Boolean
27 |
# File 'lib/undies/node_stack.rb', line 27 def empty?; @stack.empty?; end |
#first ⇒ Object
29 |
# File 'lib/undies/node_stack.rb', line 29 def first; @stack.first; end |
#flush ⇒ Object
60 61 62 |
# File 'lib/undies/node_stack.rb', line 60 def flush clear_cached end |
#last ⇒ Object Also known as: current
30 |
# File 'lib/undies/node_stack.rb', line 30 def last; @stack.last; end |
#node(node) ⇒ Object
55 56 57 58 |
# File 'lib/undies/node_stack.rb', line 55 def node(node) clear_cached self.cached_node = node end |
#pop(*args) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/undies/node_stack.rb', line 45 def pop(*args) if !empty? node = if @written_level < level @stack.pop.tap { |node| write(node) } else @stack.pop.tap { |node| close(node) } end end end |
#push(node) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/undies/node_stack.rb', line 35 def push(node) if current current.class.set_children(current, node.kind_of?(Element)) end if @written_level < level open(current) end @stack.push(node) end |
#size ⇒ Object Also known as: level
28 |
# File 'lib/undies/node_stack.rb', line 28 def size; @stack.size; end |