class Producer::Core::Template

Constants

RENDERERS
SEARCH_PATH

Public Class Methods

new(path, search_path: SEARCH_PATH, renderers: RENDERERS) click to toggle source
# 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

Public Instance Methods

render(variables = {}) click to toggle source
# 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

Protected Instance Methods

candidates() click to toggle source
# File lib/producer/core/template.rb, line 28
def candidates
  if @path.to_s =~ /\A\.\//
    glob_candidates_by_prefix @path
  else
    glob_candidates_by_prefix @search_path + @path
  end
end
glob_candidates_by_prefix(path_prefix) click to toggle source
# File lib/producer/core/template.rb, line 36
def glob_candidates_by_prefix path_prefix
  Pathname.glob(path_prefix.to_s + ?*)
end