Class: Hyde::Template Abstract
- Inherits:
-
Object
- Object
- Hyde::Template
- Defined in:
- lib/hyde/template.rb
Overview
This class is abstract.
does not represent any actual template engine.
Interface for Template engines
Direct Known Subclasses
Instance Method Summary collapse
-
#import(filepath) ⇒ Object
Import a template from within current template.
-
#initialize(input, vars = {}, parent:) ⇒ Template
constructor
A new instance of Template.
-
#local_variable_get(key) ⇒ Object
Get local variable.
-
#local_variable_set(key, value) ⇒ Object
Set local variable.
-
#local_variables ⇒ Array(Symbol)
Get an array of defined local variables.
-
#override_locals(vars) ⇒ Object
Override binding variables.
-
#run ⇒ Object
Run the template.
Constructor Details
#initialize(input, vars = {}, parent:) ⇒ Template
Returns a new instance of Template.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hyde/template.rb', line 39 def initialize(input, vars = {}, parent:) @template = input.is_a?(File) ? input.read : input @context = TemplateContext.new(parent, self) @parent = parent input.close if input.is_a? File @binding = @context.binding vars.each do |k, v| @binding.local_variable_set(k, v) end end |
Instance Method Details
#import(filepath) ⇒ Object
Import a template from within current template
85 86 87 88 89 |
# File 'lib/hyde/template.rb', line 85 def import(filepath) newtemp = self.class.new(filepath, {}, parent: @parent) newtemp.binding = @binding newtemp end |
#local_variable_get(key) ⇒ Object
Get local variable
60 61 62 |
# File 'lib/hyde/template.rb', line 60 def local_variable_get(key) @binding.local_variable_get(key) end |
#local_variable_set(key, value) ⇒ Object
Set local variable
53 54 55 |
# File 'lib/hyde/template.rb', line 53 def local_variable_set(key, value) @binding.local_variable_set(key, value) end |
#local_variables ⇒ Array(Symbol)
Get an array of defined local variables
66 67 68 |
# File 'lib/hyde/template.rb', line 66 def local_variables @binding.local_variables end |
#override_locals(vars) ⇒ Object
Override binding variables.
72 73 74 75 76 |
# File 'lib/hyde/template.rb', line 72 def override_locals(vars) vars.each do |k, v| @binding.local_variable_set(k, v) end end |
#run ⇒ Object
Note:
This method is a stub.
Run the template
80 81 82 |
# File 'lib/hyde/template.rb', line 80 def run # ... (stub) end |