class Crinja::Loader::PrefixLoader
- Crinja::Loader::PrefixLoader
- Crinja::Loader
- Reference
- Object
Overview
Load templates from other loaders based on prefix.
Defined in:
loader.crConstructors
-
.new(mapping : Hash(String, Crinja::Loader), delimiter : String = "/")
The prefix is delimited from the template by a slash per default, which can be changed by setting the delimiter argument.
Instance Method Summary
-
#get_source(env : Crinja, template : String) : ::Tuple(String, String?)
Get the template source, filename and reload helper for a template.
- #mapping : Hash(String, Loader)
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
The prefix is delimited from the template by a slash per
default, which can be changed by setting the delimiter argument.
loader = PrefixLoader.new({
"app1" => FileSystemLoader("app1"),
"app2" => FileSystemLoader("../otherapp")
})
By loading app1/index.html
the file path app1/index.html
is loaded
by loading app2/index.html
the file path ../otherapp/index.html
.
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.