Class: WLang::Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Template

Creates a template instance



14
15
16
17
18
19
20
21
# File 'lib/wlang/template.rb', line 14

def initialize(source, options = {})
  @options          = options
  @dialect          = @options.delete(:dialect) || WLang::Html
  @dialect_instance = @dialect.new(options, self)
  @compiler         = Compiler.new(dialect_instance)
  @source           = Source.new(source, self).with_front_matter(yaml_front_matter?)
  @compiled         = to_ruby_proc
end

Instance Attribute Details

#compiledObject (readonly)

Returns the value of attribute compiled.



54
55
56
# File 'lib/wlang/template.rb', line 54

def compiled
  @compiled
end

#compilerObject (readonly)

The underlying template compiler



11
12
13
# File 'lib/wlang/template.rb', line 11

def compiler
  @compiler
end

#dialectObject (readonly)

The dialect class to use



8
9
10
# File 'lib/wlang/template.rb', line 8

def dialect
  @dialect
end

#dialect_instanceObject (readonly)

Returns the value of attribute dialect_instance.



54
55
56
# File 'lib/wlang/template.rb', line 54

def dialect_instance
  @dialect_instance
end

#optionsObject (readonly)

Compilation options for the template, as initially passed to ‘new`



5
6
7
# File 'lib/wlang/template.rb', line 5

def options
  @options
end

#sourceObject (readonly)

Returns the value of attribute source.



54
55
56
# File 'lib/wlang/template.rb', line 54

def source
  @source
end

Instance Method Details

#call(*args) ⇒ Object Also known as: render



47
48
49
50
# File 'lib/wlang/template.rb', line 47

def call(*args)
  scope, buffer = call_args_conventions(args)
  dialect_instance.dup.render compiled, scope, buffer
end

#localsObject



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

def locals
  @source.locals
end

#pathObject



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

def path
  @options[:path] || @source.path
end

#template_contentObject



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

def template_content
  @source.template_content
end

#to_astObject



43
44
45
# File 'lib/wlang/template.rb', line 43

def to_ast
  compiler.to_ast(template_content)
end

#to_ruby_codeObject



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

def to_ruby_code
  compiler.to_ruby_code(template_content)
end

#to_ruby_procObject



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

def to_ruby_proc
  compiler.to_ruby_proc(template_content)
end