Class: Slight::Template

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Template

Returns a new instance of Template.



5
6
7
8
9
10
11
12
13
# File 'lib/slight/template.rb', line 5

def initialize(options = {})
  @options = options
  @output_buffer = @options[:io_out] || ""
  @dsl = DSL.new(@output_buffer)

  @dsl.resolve_shortcutA(@options[:shortcutA])
  @dsl.resolve_shortcutT(@options[:shortcutT])
  @dsl.resolve_blinding(@options[:blinding])
end

Instance Method Details

#render(src_data, src_file, local_vars = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/slight/template.rb', line 15

def render(src_data, src_file, local_vars = {})
  @output_buffer.clear

  local_vars.each_pair do |key, value|
    if key == :__scope then
      scope = value
      scope_vars = scope.instance_variables
      scope_vars.each do |var|
        @dsl.instance_variable_set(var, scope.instance_variable_get(var))
      end
    else
      @dsl.resolve_local(key, value)
    end
  end

  begin
    @dsl.instance_eval(src_data, src_file, __LINE__ - 30)
  rescue => ex
    raise DSLException.new(ex.message)
  end
  @output_buffer
end