Class: AudioGlue::TemplateLoader
- Inherits:
-
Object
- Object
- AudioGlue::TemplateLoader
- Defined in:
- lib/audio_glue/template_loader.rb
Overview
Loads .glue templates and caches them.
Constant Summary collapse
- TEMPLATE_EXT =
Extension of template files.
'glue'
Instance Attribute Summary collapse
- #base_path ⇒ Object readonly
- #cache ⇒ Object readonly
Instance Method Summary collapse
-
#get(template_name) ⇒ Class
Load and cache the template from a
.gluetemplate file. -
#initialize(base_path, opts = {}) ⇒ TemplateLoader
constructor
A new instance of TemplateLoader.
-
#reset_cache! ⇒ Hash
Reset the cache.
Constructor Details
#initialize(base_path, opts = {}) ⇒ TemplateLoader
Returns a new instance of TemplateLoader.
24 25 26 27 28 |
# File 'lib/audio_glue/template_loader.rb', line 24 def initialize(base_path, opts = {}) @base_path = base_path @helper = opts.delete(:helper) @cache = {} end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
14 15 16 |
# File 'lib/audio_glue/template_loader.rb', line 14 def base_path @base_path end |
#cache ⇒ Object (readonly)
18 19 20 |
# File 'lib/audio_glue/template_loader.rb', line 18 def cache @cache end |
Instance Method Details
#get(template_name) ⇒ Class
Load and cache the template from a .glue template file.
35 36 37 38 |
# File 'lib/audio_glue/template_loader.rb', line 35 def get(template_name) path = absolute_path(template_name) @cache[path] ||= load_template_from_file(path) end |
#reset_cache! ⇒ Hash
Reset the cache.
43 44 45 |
# File 'lib/audio_glue/template_loader.rb', line 43 def reset_cache! @cache.clear end |