class Rodakase::View::Renderer

Constants

TemplateNotFoundError

Attributes

dir[R]
engine[R]
root[R]
tilts[R]

Public Class Methods

new(dir, options = {}) click to toggle source
# File lib/rodakase/view/renderer.rb, line 17
def initialize(dir, options = {})
  @dir = dir
  @root = options.fetch(:root, dir)
  @engine = options[:engine]
  @tilts = self.class.tilts
end
tilts() click to toggle source
# File lib/rodakase/view/renderer.rb, line 13
def self.tilts
  @__engines__ ||= {}
end

Public Instance Methods

call(template, scope, &block) click to toggle source
# File lib/rodakase/view/renderer.rb, line 24
def call(template, scope, &block)
  path = lookup(template)

  if path
    render(path, scope, &block)
  else
    raise TemplateNotFoundError, "Template #{template} could not be looked up within #{root}"
  end
end
chdir(dirname) click to toggle source
# File lib/rodakase/view/renderer.rb, line 62
def chdir(dirname)
  self.class.new(dir.join(dirname), engine: engine, root: root)
end
lookup(name) click to toggle source
# File lib/rodakase/view/renderer.rb, line 42
def lookup(name)
  template?(name) || template?("shared/#{name}") || !root? && chdir('..').lookup(name)
end
path(name) click to toggle source
# File lib/rodakase/view/renderer.rb, line 58
def path(name)
  dir.join("#{name}.#{engine}")
end
render(path, scope, &block) click to toggle source
# File lib/rodakase/view/renderer.rb, line 34
def render(path, scope, &block)
  tilt(path).render(scope, &block)
end
root?() click to toggle source
# File lib/rodakase/view/renderer.rb, line 46
def root?
  dir == root
end
template?(name) click to toggle source
# File lib/rodakase/view/renderer.rb, line 50
def template?(name)
  template_path = path(name)

  if File.exist?(template_path)
    template_path
  end
end
tilt(path) click to toggle source
# File lib/rodakase/view/renderer.rb, line 38
def tilt(path)
  tilts.fetch(path) { tilts[path] = Tilt[engine].new(path) }
end