class Template::Manager

Overview

A template manager. It serves as a repository of template to renders.

Defined in:

ute.cr

Constructors

Class Method Summary

Macro Summary

Instance Method Summary

Constructor Detail

def self.new(base : String = nil) #

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.


[View source]

Class Method Detail

def self.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.


[View source]
def self.normalize(parameters) : Parameters #

Convert free form parameters tree to a fixed known type.


[View source]

Macro Detail

macro 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. If omitted it default to the absolute compilation working dir. It expect the templates files names to ends with the extension ".ut".


[View source]
macro compile_time_cache(*patterns, base = nil) #

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.


[View source]

Instance Method Detail


[View source]

[View source]
def render(components : Array(Component), parameters, dest : IO, anchors : Array(Array(As)) | Nil = nil) #

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.


[View source]
def 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. 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.


[View source]
def render(path, parameters = Parameters::Empty) : String #

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.


[View source]