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, #site
Instance Method Summary collapse
-
#initialize(site:, path:) ⇒ Template
constructor
A new instance of Template.
- #render(payload: nil) ⇒ Object
Methods inherited from Entry
#generate, #method_missing, #parse_metadata, #respond_to_missing?, #template
Constructor Details
#initialize(site:, path:) ⇒ Template
Returns a new instance of Template.
8 9 10 |
# File 'lib/dimples/template.rb', line 8 def initialize(site:, path:) super(site:, 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(payload: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dimples/template.rb', line 12 def render(payload: nil) payload ||= {} @entries.each { |key| remove_instance_variable(key) } unless @entries.nil? @entries = [] payload.each do |key, value| key = "@#{key}".to_sym instance_variable_set(key, value) @entries.append(key) end ERB.new(contents).result(binding) end |