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