class Template::Manager
- Template::Manager
- Reference
- Object
Overview
A template manager. It serves as a repository of template to renders.
Defined in:
ute.crConstructors
-
.new(base : String = nil)
Create a manager.
Class Method Summary
-
.build(scanner, components = [] of Component, anchor_mode = false, expects_end = false)
Extract an array of component of a string scanner It expects to work recursively and so will stop at either end of string OR on '${end}' tags.
-
.normalize(parameters) : Parameters
Convert free form parameters tree to a fixed known type.
Macro Summary
-
build_with_cache(base = nil)
Macro to build a manager with a compile time built cache of all the template found in the base directory relative to the compilation working dir.
-
compile_time_cache(*patterns, base = nil)
Macro used to produce a literal cache of all the templates matched by the glob patterns.
Instance Method Summary
- #cache : Hash(Path, {timestamp: Time, components: Array(Template::Manager::Anchor | Template::Manager::As | Template::Manager::Conditional | Template::Manager::Include | Template::Manager::Loop | Template::Manager::Raw | Template::Manager::Symbol | Template::Manager::Use)})
- #cache=(cache : Hash(Path, NamedTuple(timestamp: Time, components: Array(Template::Manager::Anchor | Template::Manager::As | Template::Manager::Conditional | Template::Manager::Include | Template::Manager::Loop | Template::Manager::Raw | Template::Manager::Symbol | Template::Manager::Use))))
-
#render(components : Array(Component), parameters, dest : IO, anchors : Array(Array(As)) | Nil = nil)
Render a template given its components, the parameters and a destination.
-
#render(path : String | Path, parameters, dest : IO, anchors : Array(Array(As)) | Nil = nil)
Render the given template by its path with the given parameters, into dest.
-
#render(path, parameters = Parameters::Empty) : String
Render the given template by its path with the given parameters, into dest.
Constructor Detail
Create a manager. It will holds its own cache. The base is used as a prefix for template when rendering them. It is not omitted of the templates name in the cache.
Class Method Detail
Extract an array of component of a string scanner It expects to work recursively and so will stop at either end of string OR on '${end}' tags.
Convert free form parameters tree to a fixed known type.
Macro Detail
Macro to build a manager with a compile time built cache of all the template found in the base directory relative to the compilation working dir. If omitted it default to the absolute compilation working dir. It expect the templates files names to ends with the extension ".ut".
Macro used to produce a literal cache of all the templates matched by the glob patterns. If base is provided, the name of the templates in the produced cache will be relative to it.
Instance Method Detail
Render a template given its components, the parameters and a destination. Parameter anchors is a stack of parameters for genereic templates (using anchor tags). The first is the most recent, the direct caller of the current template. If the caller itself is generic, then the stack will contains the parameters that have been given to it, ect.
Render the given template by its path with the given parameters, into dest. Parameters must be any ::Any like type such as Json::Any, Yaml::Any, or the provided Parameters type. In case it is a raw hash, it will attempt to convert it to Parameters.
Render the given template by its path with the given parameters, into dest. If provided, parameters must be any ::Any like type such as Json::Any or the provided Parameters type, or a combiantion of native Hash, Array, String and Bool. Return the rendered template as a string.