Class: Landline::Template Abstract
- Inherits:
-
Object
- Object
- Landline::Template
- Defined in:
- lib/landline/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(file) ⇒ Landline::Template
Import a template from within current template.
-
#initialize(input, vars = {}, parent:, filename:) ⇒ 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:, filename:) ⇒ Template
Returns a new instance of Template.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/landline/template.rb', line 40 def initialize(input, vars = {}, parent:, filename:) @template, @filename = if input.is_a?(File) [input.read, input.path] else [input, filename] end @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(file) ⇒ Landline::Template
Import a template from within current template.
92 93 94 95 96 97 98 99 |
# File 'lib/landline/template.rb', line 92 def import(file) newtemp = self.class.new(file, {}, parent: @parent, filename: file.path) newtemp.binding = @binding newtemp end |
#local_variable_get(key) ⇒ Object
Get local variable
65 66 67 |
# File 'lib/landline/template.rb', line 65 def local_variable_get(key) @binding.local_variable_get(key) end |
#local_variable_set(key, value) ⇒ Object
Set local variable
58 59 60 |
# File 'lib/landline/template.rb', line 58 def local_variable_set(key, value) @binding.local_variable_set(key, value) end |
#local_variables ⇒ Array(Symbol)
Get an array of defined local variables
71 72 73 |
# File 'lib/landline/template.rb', line 71 def local_variables @binding.local_variables end |
#override_locals(vars) ⇒ Object
Override binding variables.
77 78 79 80 81 |
# File 'lib/landline/template.rb', line 77 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
85 86 87 |
# File 'lib/landline/template.rb', line 85 def run # ... (stub) end |