Class: Producer::Core::Template
- Inherits:
-
Object
- Object
- Producer::Core::Template
- Defined in:
- lib/producer/core/template.rb,
lib/producer/core/template/erb_renderer.rb,
lib/producer/core/template/raw_renderer.rb,
lib/producer/core/template/yaml_renderer.rb
Defined Under Namespace
Classes: ERBRenderer, RawRenderer, YAMLRenderer
Constant Summary collapse
- SEARCH_PATH =
'templates'.freeze
- RENDERERS =
{ /\.erb\z/ => ERBRenderer, /\.yaml\z/ => YAMLRenderer, // => RawRenderer }.freeze
Instance Method Summary collapse
-
#initialize(path, search_path: SEARCH_PATH, renderers: RENDERERS) ⇒ Template
constructor
A new instance of Template.
- #render(variables = {}) ⇒ Object
Constructor Details
#initialize(path, search_path: SEARCH_PATH, renderers: RENDERERS) ⇒ Template
Returns a new instance of Template.
11 12 13 14 15 |
# File 'lib/producer/core/template.rb', line 11 def initialize path, search_path: SEARCH_PATH, renderers: RENDERERS @path = Pathname.new(path) @search_path = Pathname.new(search_path) @renderers = renderers end |
Instance Method Details
#render(variables = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/producer/core/template.rb', line 17 def render variables = {} candidates.each do |c| _, r = @renderers.find { |k, _| c.to_s =~ k } return r.render c, variables if r end fail TemplateMissingError, "template `#{@path}' not found" end |