Class: Landline::Templates::ERB

Inherits:
Landline::Template show all
Defined in:
lib/landline/template/erb.rb

Overview

ERB Template language adapter

Instance Method Summary collapse

Methods inherited from Landline::Template

#import, #local_variable_get, #local_variable_set, #local_variables, #override_locals

Constructor Details

#initialize(input, vars = nil, parent:, filename:) ⇒ ERB



11
12
13
14
15
16
17
18
19
# File 'lib/landline/template/erb.rb', line 11

def initialize(input, vars = nil, parent:, filename:)
  super
  varname = "_part_#{SecureRandom.hex(10)}".to_sym
  while @binding.local_variable_defined? varname
    varname = "_part_#{SecureRandom.hex(10)}".to_sym
  end
  @template = ::ERB.new(@template, eoutvar: varname)
  @template.filename = input.is_a?(File) ? input.path : "(Inline)"
end

Instance Method Details

#runObject

Run the template.



22
23
24
25
# File 'lib/landline/template/erb.rb', line 22

def run
  @template.filename = @filename
  @template.result @binding
end