Sha256: ee4d8187ef03595a48f18ca5f87bc0553ae53e2cd08182af0311d3b6ceaf7e0c

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 KB

Contents

# The Templates class holds all loaded templates.
module Volt
  class Templates
    # On the server, we can delay loading the views until they are actually requeted.  This
    # sets up an instance variable to call to load.
    attr_writer :template_loader

    def initialize
      @templates = {}
    end

    def [](key)
      templates[key]
    end

    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

    # Load the templates on first use if a loader was specified
    def templates
      if @template_loader
        # Load the templates
        @template_loader.call
        @template_loader = nil
      end

      @templates
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
volt-0.9.6.pre1 lib/volt/volt/templates.rb
volt-0.9.5 lib/volt/volt/templates.rb
volt-0.9.5.pre12 lib/volt/volt/templates.rb
volt-0.9.5.pre11 lib/volt/volt/templates.rb
volt-0.9.5.pre9 lib/volt/volt/templates.rb
volt-0.9.5.pre8 lib/volt/volt/templates.rb
volt-0.9.5.pre7 lib/volt/volt/templates.rb
volt-0.9.5.pre6 lib/volt/volt/templates.rb
volt-0.9.5.pre5 lib/volt/volt/templates.rb
volt-0.9.5.pre4 lib/volt/volt/templates.rb
volt-0.9.5.pre3 lib/volt/volt/templates.rb
volt-0.9.5.pre2 lib/volt/volt/templates.rb
volt-0.9.5.pre1 lib/volt/volt/templates.rb
volt-0.9.4 lib/volt/volt/templates.rb
volt-0.9.4.pre5 lib/volt/volt/templates.rb