Module: Cadenza::Context::Loaders
- Included in:
- Cadenza::Context
- Defined in:
- lib/cadenza/context/loaders.rb
Instance Attribute Summary collapse
-
#loaders ⇒ Array
readonly
The list of loaders.
-
#whiny_template_loading ⇒ Boolean
True if a TemplateNotFoundError should still be raised if not calling the bang form of #load_source or #load_template.
Instance Method Summary collapse
-
#add_load_path(path) ⇒ Loader
constructs a FilesystemLoader with the string given as its path and adds the loader to the end of the loader list.
-
#add_loader(loader) ⇒ Object
adds the given loader to the end of the loader list.
-
#clear_loaders ⇒ Object
removes all loaders from the context.
-
#load_source(template_name) ⇒ String
loads and returns the given template but does not parse it.
-
#load_source!(template_name) ⇒ String
loads and returns the given template but does not parse it.
-
#load_template(template_name) ⇒ DocumentNode
loads, parses and returns the given template.
-
#load_template!(template_name) ⇒ DocumentNode
loads, parses and returns the given template.
Instance Attribute Details
#loaders ⇒ Array (readonly)
Returns the list of loaders.
22 23 24 |
# File 'lib/cadenza/context/loaders.rb', line 22 def loaders @loaders ||= [] end |
#whiny_template_loading ⇒ Boolean
Returns true if a TemplateNotFoundError should still be raised if not calling the bang form of #load_source or #load_template.
12 13 14 |
# File 'lib/cadenza/context/loaders.rb', line 12 def whiny_template_loading @whiny_template_loading ||= false end |
Instance Method Details
#add_load_path(path) ⇒ Loader
constructs a FilesystemLoader with the string given as its path and adds the loader to the end of the loader list.
31 32 33 34 35 |
# File 'lib/cadenza/context/loaders.rb', line 31 def add_load_path(path) loader = FilesystemLoader.new(path) add_loader(loader) loader end |
#add_loader(loader) ⇒ Object
adds the given loader to the end of the loader list.
41 42 43 44 |
# File 'lib/cadenza/context/loaders.rb', line 41 def add_loader(loader) loaders.push loader nil end |
#clear_loaders ⇒ Object
removes all loaders from the context
48 49 50 51 |
# File 'lib/cadenza/context/loaders.rb', line 48 def clear_loaders loaders.reject! { true } nil end |
#load_source(template_name) ⇒ String
loads and returns the given template but does not parse it
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cadenza/context/loaders.rb', line 59 def load_source(template_name) source = nil loaders.each do |loader| source = loader.load_source(template_name) break if source end if source.nil? and whiny_template_loading raise TemplateNotFoundError.new(template_name) else return source end end |
#load_source!(template_name) ⇒ String
loads and returns the given template but does not parse it
79 80 81 |
# File 'lib/cadenza/context/loaders.rb', line 79 def load_source!(template_name) load_source(template_name) || raise(TemplateNotFoundError.new(template_name)) end |
#load_template(template_name) ⇒ DocumentNode
loads, parses and returns the given template
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/cadenza/context/loaders.rb', line 90 def load_template(template_name) template = nil loaders.each do |loader| template = loader.load_template(template_name) break if template end if template.nil? and whiny_template_loading raise TemplateNotFoundError.new(template_name) else return template end end |
#load_template!(template_name) ⇒ DocumentNode
loads, parses and returns the given template
110 111 112 |
# File 'lib/cadenza/context/loaders.rb', line 110 def load_template!(template_name) load_template(template_name) || raise(TemplateNotFoundError.new(template_name)) end |