Class: Landline::Templates::Erubi
- Inherits:
-
Landline::Template
- Object
- Landline::Template
- Landline::Templates::Erubi
- Defined in:
- lib/landline/template/erubi.rb
Overview
Erubi (ERB) template language adapter
Instance Method Summary collapse
-
#initialize(input, vars = nil, **ext) ⇒ Erubi
constructor
A new instance of Erubi.
-
#run ⇒ Object
Run the template.
Methods inherited from Landline::Template
#import, #local_variable_get, #local_variable_set, #local_variables, #override_locals
Constructor Details
#initialize(input, vars = nil, **ext) ⇒ Erubi
Returns a new instance of Erubi.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/landline/template/erubi.rb', line 11 def initialize(input, vars = nil, **ext) super(input, vars, parent: ext[:parent], filename: ext[:filename]) varname = "_part_#{SecureRandom.hex(10)}" while @binding.local_variable_defined? varname.to_sym varname = "_part_#{SecureRandom.hex(10)}" end properties = { bufvar: varname, freeze: ext.fetch(:freeze, true) } capture = ext.fetch(:capture, false) engine = capture ? ::Erubi::CaptureEndEngine : ::Erubi::Engine @template = engine.new(@template, properties) end |
Instance Method Details
#run ⇒ Object
Run the template.
29 30 31 |
# File 'lib/landline/template/erubi.rb', line 29 def run @binding.eval(@template.src, @filename) end |