Class: Cutaneous::Compiler::BlockSet

Inherits:
Object
  • Object
show all
Defined in:
lib/cutaneous/compiler.rb

Overview

Represents the block structure of a top-level master template, i.e. one with no ‘extends` call.

Direct Known Subclasses

ExtendedBlockSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBlockSet



35
36
37
38
39
# File 'lib/cutaneous/compiler.rb', line 35

def initialize
  @block_order = []
  @block_store = {}
  block_start
end

Instance Attribute Details

#current_blockObject (readonly)

Returns the value of attribute current_block.



32
33
34
# File 'lib/cutaneous/compiler.rb', line 32

def current_block
  @current_block
end

#loaderObject

Returns the value of attribute loader.



33
34
35
# File 'lib/cutaneous/compiler.rb', line 33

def loader
  @loader
end

Instance Method Details

#block(name) ⇒ Object



63
64
65
# File 'lib/cutaneous/compiler.rb', line 63

def block(name)
  @block_store[name]
end

#block_endObject



47
48
49
# File 'lib/cutaneous/compiler.rb', line 47

def block_end
  block_start
end

#block_orderObject



55
56
57
# File 'lib/cutaneous/compiler.rb', line 55

def block_order
  @block_order
end

#block_start(name = Object.new) ⇒ Object



41
42
43
44
45
# File 'lib/cutaneous/compiler.rb', line 41

def block_start(name = Object.new)
  @current_block = Block.new(name)
  @block_order << name
  @block_store[name] = @current_block
end

#each_blockObject



67
68
69
70
71
# File 'lib/cutaneous/compiler.rb', line 67

def each_block
  block_order.each do |block_name|
    yield block(block_name)
  end
end

#push(tag) ⇒ Object



51
52
53
# File 'lib/cutaneous/compiler.rb', line 51

def push(tag)
  @current_block << tag
end

#super_blockObject

Raises:



59
60
61
# File 'lib/cutaneous/compiler.rb', line 59

def super_block
  raise CompilationError.new("Invalid 'blocksuper' call from top-level template")
end

#to_scriptObject



73
74
75
76
77
78
79
# File 'lib/cutaneous/compiler.rb', line 73

def to_script
  script = ""
  each_block do |block|
    script << block.to_script
  end
  script
end