Class: Eggshell::Block

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#delimObject (readonly)

Returns the value of attribute delim.



23
24
25
# File 'lib/eggshell/block.rb', line 23

def delim
  @delim
end

#depthObject (readonly)

Returns the value of attribute depth.



23
24
25
# File 'lib/eggshell/block.rb', line 23

def depth
  @depth
end

#linesObject (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

#curObject

Returns the current active block.



26
27
28
# File 'lib/eggshell/block.rb', line 26

def cur
	@stack[-1]
end

#inspectObject



49
50
51
# File 'lib/eggshell/block.rb', line 49

def inspect
	"<BLOCK #{@macro} (#{@depth}) #{@handler.class} | #{@lines.inspect} >"
end

#popObject

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