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 Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
Instance Method Summary collapse
-
#initialize(input, toplevel: nil, locals: nil) ⇒ 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, toplevel: nil, locals: nil) ⇒ Template
Returns a new instance of Template.
30 31 32 33 34 35 36 37 38 |
# File 'lib/hyde/template.rb', line 30 def initialize(input, toplevel: nil, locals: nil) @template = input.is_a?(File) ? input.read : input input.close if input.is_a? File @binding = toplevel or binding locals&.each do |k, v| @binding.local_variable_set(k,v) end @context = TemplateContext.new(self) end |
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
74 75 76 |
# File 'lib/hyde/template.rb', line 74 def binding @binding end |
Instance Method Details
#local_variable_get(key) ⇒ Object
Get local variable
50 51 52 |
# File 'lib/hyde/template.rb', line 50 def local_variable_get(key) @binding.local_variable_get(key) end |
#local_variable_set(key, value) ⇒ Object
Set local variable
43 44 45 |
# File 'lib/hyde/template.rb', line 43 def local_variable_set(key, value) @binding.local_variable_set(key, value) end |
#local_variables ⇒ Array(Symbol)
Get an array of defined local variables
56 57 58 |
# File 'lib/hyde/template.rb', line 56 def local_variables @binding.local_variables end |
#override_locals(vars) ⇒ Object
Override binding variables.
62 63 64 65 66 |
# File 'lib/hyde/template.rb', line 62 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
70 71 72 |
# File 'lib/hyde/template.rb', line 70 def run # ... (stub) end |