class Volt::Templates

Attributes

template_loader[W]

On the server, we can delay loading the views until they are actually requeted. This sets up an instance variable to call to load.

Public Class Methods

new() click to toggle source
# File lib/volt/volt/templates.rb, line 8
def initialize
  @templates = {}
end

Public Instance Methods

[](key) click to toggle source
# File lib/volt/volt/templates.rb, line 12
def [](key)
  templates[key]
end
add_template(name, template, bindings) click to toggle source
# File lib/volt/volt/templates.rb, line 16
def add_template(name, template, bindings)
  # First template gets priority.  The backend will load templates in order so
  # that local templates come in before gems (so they can be overridden).
  #
  # TODO: Currently this means we will send templates to the client that will
  # not get used because they are being overridden.  Need to detect that and
  # not send them.
  unless @templates[name]
    @templates[name] = { 'html' => template, 'bindings' => bindings }
  end
end
templates() click to toggle source

Load the templates on first use if a loader was specified

# File lib/volt/volt/templates.rb, line 29
def templates
  if @template_loader
    # Load the templates
    @template_loader.call
    @template_loader = nil
  end

  @templates
end