Class: Makanai::Template
- Inherits:
-
Object
- Object
- Makanai::Template
- Defined in:
- lib/makanai/template.rb
Defined Under Namespace
Classes: UnsupportedException
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path:, engine: :erb, locals: {}) ⇒ Template
constructor
A new instance of Template.
- #render ⇒ Object
Constructor Details
#initialize(path:, engine: :erb, locals: {}) ⇒ Template
Returns a new instance of Template.
7 8 9 10 11 |
# File 'lib/makanai/template.rb', line 7 def initialize(path:, engine: :erb, locals: {}) @path = path @engine = engine @locals = locals end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
13 14 15 |
# File 'lib/makanai/template.rb', line 13 def engine @engine end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
13 14 15 |
# File 'lib/makanai/template.rb', line 13 def locals @locals end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/makanai/template.rb', line 13 def path @path end |
Instance Method Details
#render ⇒ Object
15 16 17 18 |
# File 'lib/makanai/template.rb', line 15 def render template_file = File.read("#{path}.#{engine}") engine_class.new(text: template_file, locals: locals).result end |