Class: Boxing::Template
- Inherits:
-
Object
- Object
- Boxing::Template
- Defined in:
- lib/boxing/template.rb
Overview
Generate file from template
Constant Summary collapse
- TEMPLATE_DIR =
File.('../../templates', __dir__)
Instance Method Summary collapse
-
#content ⇒ String
private
Get template content.
-
#engine ⇒ ERB
private
Create template engine.
-
#initialize(template) ⇒ Template
constructor
A new instance of Template.
-
#render(context = nil) ⇒ String
private
Render template.
Constructor Details
#initialize(template) ⇒ Template
Returns a new instance of Template.
17 18 19 |
# File 'lib/boxing/template.rb', line 17 def initialize(template) @template = template end |
Instance Method Details
#content ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get template content
37 38 39 |
# File 'lib/boxing/template.rb', line 37 def content @content ||= File.read("#{TEMPLATE_DIR}/#{@template}") end |
#engine ⇒ ERB
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create template engine
27 28 29 |
# File 'lib/boxing/template.rb', line 27 def engine @engine ||= ERB.new(content, trim_mode: '-') end |
#render(context = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Render template
47 48 49 50 |
# File 'lib/boxing/template.rb', line 47 def render(context = nil) context = context.to_binding if context.respond_to?(:to_binding) engine.result(context) end |