Class: Dimples::Template

Inherits:
Entry
  • Object
show all
Defined in:
lib/dimples/template.rb

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

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
# File 'lib/dimples/template.rb', line 12

def render(payload: nil)
  payload ||= {}

  instance_variable_set("@this", Context.from_hash(payload.merge()))
  ERB.new(contents).result(binding)
end