module Tansu::Render

Private Instance Methods

application_options() click to toggle source
# File lib/tansu/render.rb, line 44
def application_options
  { views: Application[:templates] }
end
render(ext, name, locals = {}, options = {}, &block) click to toggle source
# File lib/tansu/render.rb, line 14
def render(ext, name, locals = {}, options = {}, &block)
  options  = options.merge(renderer_options(ext)) { |k, a, b| a }
  options  = options.merge(application_options) { |k, a, b| a }
  template = renderer(ext, name, options)
  ret      = template.render(self, locals, &block)

  if options[:layout]
    layout = options.delete(:layout)
    layout = :layout if layout == true

    render(ext, layout, locals, options) { ret }
  else
    ret
  end
end
renderer(ext, name, options) click to toggle source
# File lib/tansu/render.rb, line 30
def renderer(ext, name, options)
  basename = "#{name}.#{ext}"
  filename = File.join options[:views], basename

  raise NoRendererError, ext unless template = Tilt[ext]
  raise LayoutMissingError, filename unless File.exist?(filename)

  templates_cache.fetch(filename) { template.new(filename, options) }
end
renderer_options(ext) click to toggle source
# File lib/tansu/render.rb, line 40
def renderer_options(ext)
  Application[ext] || {}
end
templates_cache() click to toggle source
# File lib/tansu/render.rb, line 48
def templates_cache
  Application[:templates_cache] ||= Tilt::Cache.new
end