Class: Amp::Support::FileTemplate
- Defined in:
- lib/amp/templates/template.rb
Overview
FileTemplate
Class for loading a template from a file and registering it in the system. Is smart enough that if the filename ends in a known extension, the appropriate renderer will be used. Otherwise, you will have to specify the renderer.
Constant Summary collapse
- KNOWN_EXTENSIONS =
["erb", "haml"]
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Attributes inherited from Template
Instance Method Summary collapse
-
#initialize(name, file, renderer = nil) ⇒ FileTemplate
constructor
Initializes a new FileTemplate with different.
- #save! ⇒ Object
Methods inherited from Template
[], ensure_templates_loaded, load_default_templates, register, #render, templates_loaded?, unregister
Constructor Details
#initialize(name, file, renderer = nil) ⇒ FileTemplate
Initializes a new FileTemplate with different
135 136 137 138 139 140 141 142 |
# File 'lib/amp/templates/template.rb', line 135 def initialize(name, file, renderer = nil) if renderer.nil? renderer = KNOWN_EXTENSIONS.select {|ext| file.end_with? ext}.first end raise ArgumentError.new("No renderer specified for #{file.inspect}") if renderer.nil? @file = file super(name, renderer, File.read(file)) end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
131 132 133 |
# File 'lib/amp/templates/template.rb', line 131 def file @file end |