Class: Eggshell::Block
- Inherits:
-
Object
- Object
- Eggshell::Block
- Defined in:
- lib/eggshell/block.rb
Overview
For multiline macros, the block collects lines specific to the block (including other nested macros). This allows for proper execution when dealing with loops and branches.
Instance Attribute Summary collapse
-
#delim ⇒ Object
readonly
Returns the value of attribute delim.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Instance Method Summary collapse
- #collect(entry) ⇒ Object
-
#cur ⇒ Object
Returns the current active block.
-
#initialize(macro, handler, args, depth, line_count, delim = nil) ⇒ Block
constructor
A new instance of Block.
- #inspect ⇒ Object
-
#pop ⇒ Object
Removes a nested block.
- #process(buffer, depth = nil) ⇒ Object
-
#push(block, line_count = -1)) ⇒ Object
Adds a nested block to collect lines into.
Constructor Details
#initialize(macro, handler, args, depth, line_count, delim = nil) ⇒ Block
Returns a new instance of Block.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/eggshell/block.rb', line 4 def initialize(macro, handler, args, depth, line_count, delim = nil) @stack = [self] @lines = [] @line_count = line_count @macro = macro @handler = handler @args = args @delim = delim # reverse, and swap out if @delim && @delim[0] == '{' @delim = @delim.reverse.gsub(/\{/, '}').gsub(/\[/, ']') else @delim = nil end @depth = depth end |
Instance Attribute Details
#delim ⇒ Object (readonly)
Returns the value of attribute delim.
23 24 25 |
# File 'lib/eggshell/block.rb', line 23 def delim @delim end |
#depth ⇒ Object (readonly)
Returns the value of attribute depth.
23 24 25 |
# File 'lib/eggshell/block.rb', line 23 def depth @depth end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
23 24 25 |
# File 'lib/eggshell/block.rb', line 23 def lines @lines end |
Instance Method Details
#collect(entry) ⇒ Object
41 42 43 |
# File 'lib/eggshell/block.rb', line 41 def collect(entry) @stack[-1].lines << entry end |
#cur ⇒ Object
Returns the current active block.
26 27 28 |
# File 'lib/eggshell/block.rb', line 26 def cur @stack[-1] end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/eggshell/block.rb', line 49 def inspect "<BLOCK #{@macro} (#{@depth}) #{@handler.class} | #{@lines.inspect} >" end |
#pop ⇒ Object
Removes a nested block.
37 38 39 |
# File 'lib/eggshell/block.rb', line 37 def pop() @stack.pop end |
#process(buffer, depth = nil) ⇒ Object
45 46 47 |
# File 'lib/eggshell/block.rb', line 45 def process(buffer, depth = nil) @handler.process(buffer, @macro, @args, @lines, depth == nil ? @depth : depth) end |
#push(block, line_count = -1)) ⇒ Object
Adds a nested block to collect lines into.
31 32 33 34 |
# File 'lib/eggshell/block.rb', line 31 def push(block, line_count = -1) @stack[-1].lines << block @stack << block end |