Class: Dimples::Template
Overview
A class for a single ERB template file used on a site.
Constant Summary
Constants inherited from Entry
Entry::DEFAULT_FILENAME, Entry::FRONT_MATTER_PATTERN
Instance Attribute Summary
Attributes inherited from Entry
#contents, #metadata, #path, #rendered_contents
Instance Method Summary collapse
-
#initialize(path:) ⇒ Template
constructor
A new instance of Template.
- #render(context:) ⇒ Object
Methods inherited from Entry
#method_missing, #parse_metadata, #respond_to_missing?
Constructor Details
#initialize(path:) ⇒ Template
Returns a new instance of Template.
8 9 10 |
# File 'lib/dimples/template.rb', line 8 def initialize(path:) super(source: Pathname.new(path)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Dimples::Entry
Instance Method Details
#render(context:) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dimples/template.rb', line 12 def render(context:) context.merge!() context.each do |key, value| instance_variable_set("@#{key}", value) end erb = ERB.new(contents) erb.result(binding) end |