class Eggshell::Block

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.

Attributes

delim[R]
depth[R]
lines[R]

Public Class Methods

new(macro, handler, args, depth, line_count, delim = nil) click to toggle source
# 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

Public Instance Methods

collect(entry) click to toggle source
# File lib/eggshell/block.rb, line 41
def collect(entry)
        @stack[-1].lines << entry
end
cur() click to toggle source

Returns the current active block.

# File lib/eggshell/block.rb, line 26
def cur
        @stack[-1]
end
inspect() click to toggle source
# File lib/eggshell/block.rb, line 49
def inspect
        "<BLOCK #{@macro} (#{@depth}) #{@handler.class} | #{@lines.inspect} >"
end
pop() click to toggle source

Removes a nested block.

# File lib/eggshell/block.rb, line 37
def pop()
        @stack.pop
end
process(buffer, depth = nil) click to toggle source
# 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) click to toggle source

Adds a nested block to collect lines into.

# File lib/eggshell/block.rb, line 31
def push(block, line_count = -1)
        @stack[-1].lines << block
        @stack << block
end