module Armadillo

Constants

DEFAULT_OPTIONS
VERSION

Public Class Methods

render(template_path, locals = {}, options = {}) click to toggle source

Render the erb template.

@param template_path [String] @param locals [Hash] @option options [Object] :scope (Object.new)

Any object you want to bound to the template scope.

@option options [String, nil] :base_path (nil)

The path of the directory for which the templates are going to be
searched on.

@note

options also accepts any options offered by the Erubis templating system.

@return [String] @api public

# File lib/armadillo.rb, line 144
def self.render(template_path, locals = {}, options = {})
  scope = options.fetch(:scope) { Object.new }
  context = TemplateContext.new(scope, options)
  _render(template_path, locals, context, options)
end

Private Class Methods

_render(template_path, locals, context, options) click to toggle source

Render the erb template with the given context.

@param template_path [String] @param context [Armadillo::TemplateContext] @param locals [Hash] @option options [String] :base_path (nil)

@note

options also accepts any options offered by the Erubis templating system.

@api private

# File lib/armadillo.rb, line 161
def self._render(template_path, locals, context, options)
  context.create_frame
  template_path = "#{template_path}.erb"
  if (base_path = options.fetch(:base_path, nil))
    template_path = File.join(base_path, template_path)
  end
  template = _templates_cache.fetch(template_path) do
    Tilt::ErubisTemplate.new(template_path, 1, DEFAULT_OPTIONS.merge(options))
  end

  content = template.render(context, locals)

  if context.extends?
    template_path, locals = context.extract_extends_data
    content = _render(template_path, locals, context, options)
  end

  content
end
_templates_cache() click to toggle source

Get Tilt templates cache.

@return [Tilt::Cache]

@api private

# File lib/armadillo.rb, line 187
def self._templates_cache
  Thread.current[:tilt_cache] ||= Tilt::Cache.new
end