Class: Volt::Templates
Instance Attribute Summary collapse
-
#template_loader ⇒ Object
writeonly
On the server, we can delay loading the views until they are actually requeted.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_template(name, template, bindings) ⇒ Object
-
#initialize ⇒ Templates
constructor
A new instance of Templates.
-
#templates ⇒ Object
Load the templates on first use if a loader was specified.
Constructor Details
#initialize ⇒ Templates
Returns a new instance of Templates.
8 9 10 |
# File 'lib/volt/volt/templates.rb', line 8 def initialize @templates = {} end |
Instance Attribute Details
#template_loader=(value) ⇒ Object (writeonly)
On the server, we can delay loading the views until they are actually requeted. This sets up an instance variable to call to load.
6 7 8 |
# File 'lib/volt/volt/templates.rb', line 6 def template_loader=(value) @template_loader = value end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/volt/volt/templates.rb', line 12 def [](key) templates[key] end |
#add_template(name, template, bindings) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
Load the templates on first use if a loader was specified
29 30 31 32 33 34 35 36 37 |
# 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 |