Class: Cutaneous::Template

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

Direct Known Subclasses

CachedTemplate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lexer) ⇒ Template

Returns a new instance of Template.



6
7
8
# File 'lib/cutaneous/template.rb', line 6

def initialize(lexer)
  @lexer = lexer
end

Instance Attribute Details

#lexerObject

Returns the value of attribute lexer.



4
5
6
# File 'lib/cutaneous/template.rb', line 4

def lexer
  @lexer
end

#loaderObject

Returns the value of attribute loader.



4
5
6
# File 'lib/cutaneous/template.rb', line 4

def loader
  @loader
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/cutaneous/template.rb', line 4

def path
  @path
end

Instance Method Details

#block(block_name) ⇒ Object



39
40
41
# File 'lib/cutaneous/template.rb', line 39

def block(block_name)
  compiler.block(block_name)
end

#block_orderObject



35
36
37
# File 'lib/cutaneous/template.rb', line 35

def block_order
  compiler.block_order
end

#compilerObject



10
11
12
# File 'lib/cutaneous/template.rb', line 10

def compiler
  @compiler ||= Compiler.new(lexer, loader)
end

#convert(to_syntax) ⇒ Object



19
20
21
# File 'lib/cutaneous/template.rb', line 19

def convert(to_syntax)
  lexer.convert(to_syntax)
end

#render(context) ⇒ Object



14
15
16
17
# File 'lib/cutaneous/template.rb', line 14

def render(context)
  context.__loader = loader
  context.instance_eval(&template_proc)
end

#scriptObject



31
32
33
# File 'lib/cutaneous/template.rb', line 31

def script
  compiler.script
end

#template_procObject



23
24
25
# File 'lib/cutaneous/template.rb', line 23

def template_proc
  @template_proc ||= eval(template_proc_src, nil, path || "(cutaneous)")
end

#template_proc_srcObject



27
28
29
# File 'lib/cutaneous/template.rb', line 27

def template_proc_src
  "lambda { |context| self.__buf = __buf = ''; #{script}; __buf.to_s }"
end