module Angelo::Templates

Constants

Tilt

When this code refers to Tilt, use ::Tilt not Angelo::Tilt.

Private Class Methods

included(klass) click to toggle source
# File lib/angelo/templates.rb, line 74
def self.included(klass)
  klass.extend TemplateCaching
end

Public Instance Methods

_erb(view, opts = {}) click to toggle source
# File lib/angelo/templates.rb, line 29
def _erb(view, opts = {})
  render(:erb, view, opts)
end

Private Instance Methods

render(template_type, view, opts = {}) click to toggle source
# File lib/angelo/templates.rb, line 35
def render(template_type, view, opts = {})
  # Extract the options that belong to us.  Any remaining options
  # will be passed to the engine when the template is instantiated.

  locals = opts.delete(:locals) || {}
  layout_engine = opts.delete(:layout_engine) || template_type
  layout = 
    if opts.has_key?(:layout)
      layout = opts.delete(:layout)
      case layout
      when true
        :layout
      when nil
        false
      else
        layout
      end
    else
      # Use the default layout.
      :layout
    end

  template = self.class.get_template(template_type, view, self.class.views_dir, opts)
  if !template
    raise ArgumentError, "Can't find template `#{view}' of type `#{template_type}'"
  end

  render = ->{ template.render(self, locals) }
  if layout
    layout_template = self.class.get_template(layout_engine, layout,
        File.join(self.class.views_dir), opts)
  end
  if layout_template
    layout_template.render(self, &render)
  else
    render.call
  end
end