class Crinja::Loader::ChoiceLoader
- Crinja::Loader::ChoiceLoader
- Crinja::Loader
- Reference
- Object
Overview
Load templates from first matching loader. If a template could not be found by one loader the next one is tried.
loader = ChoiceLoader.new([
FileSystemLoader.new("/path/to/user/templates"),
FileSystemLoader.new("/path/to/system/templates"),
BakedFileLoader.new(MyBakedTemplateFileSystem),
])
This is useful if you want to allow users to override builtin templates
from a different location or baked-in templates (see BakedFileLoader
).
Defined in:
loader.crConstructors
Instance Method Summary
- #choices : Array(Loader)
-
#get_source(env : Crinja, template : String) : ::Tuple(String, String?)
Get the template source, filename and reload helper for a template.
-
#list_templates
Iterates over all templates.
Instance methods inherited from class Crinja::Loader
get_source(env : Crinja, template : String) : ::Tuple(String, String?)
get_source,
list_templates : Iterable(String)
list_templates,
load(env, name)
load
Constructor Detail
Instance Method Detail
Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form {source : String, filename : String?}
or raise a
TemplateNotFoundError
if it can't locate the template.
The source part of the returned tuple must be the source of the
template as string. The filename should be the name of the file on
the filesystem if it was loaded from there, otherwise nil
.
The filename is used for the tracebacks if no loader extension is used.
Iterates over all templates. If the loader does not support that
it should raise a TypeError
which is the default behavior.