class Diecut::Template

Attributes

path[R]
template_string[R]

Public Class Methods

new(path, template_string) click to toggle source
# File lib/diecut/template.rb, line 6
def initialize(path, template_string)
  @path = path
  @template_string = template_string
  @reduced = nil
  @context_class = nil
  @context = nil
end

Public Instance Methods

add_subcontext(nesting, other) click to toggle source
# File lib/diecut/template.rb, line 23
def add_subcontext(nesting, other)
  other.field_names.each do |field|
    context_class.build_setting(nesting + [field])
  end
end
build_context_class() click to toggle source
# File lib/diecut/template.rb, line 41
def build_context_class
  klass = Configurable.build_subclass(path)

  reduced.leaf_fields.each do |field|
    klass.build_setting(field, reduced.sections.include?(field))
  end
  klass
end
context() click to toggle source
# File lib/diecut/template.rb, line 50
def context
  @context ||= context_class.new
end
context_class() click to toggle source
# File lib/diecut/template.rb, line 29
def context_class
  @context_class ||= build_context_class
end
partial_context(other) click to toggle source
# File lib/diecut/template.rb, line 16
def partial_context(other)
  reduced.partials.each do |path, nesting|
    next unless path == other.path
    add_subcontext(nesting, other.context_class)
  end
end
partials() click to toggle source
# File lib/diecut/template.rb, line 37
def partials
  reduced.partials
end
reduced() click to toggle source
# File lib/diecut/template.rb, line 33
def reduced
  @reduced ||= TemplateReducer.new(Mustache::Parser.new.compile(template_string))
end
render(renderer) click to toggle source
# File lib/diecut/template.rb, line 54
def render(renderer)
  renderer.render(template_string, context.to_hash)
end