class Crinja::Template
- Crinja::Template
- Reference
- Object
Overview
This class represents a compiled template and is used to evaluate it.
Normally the template object is generated from an Crinja
environment
by Crinja#from_string
or Crinja#get_template
. But it also has a constructor
that makes it possible to create a template instance directly.
Every template object has a few methods and members that are guaranteed to exist. However it’s important that a template object should be considered immutable. Modifications on the object are not supported.
Defined in:
template.crConstructors
-
.new(source : String, env : Crinja = Crinja.new, name : String = "", filename : String? = nil, run_parser = true)
Creates a new template.
Instance Method Summary
-
#dynamic?
Returns
true
if this template contains a template expression. -
#env : Crinja
Crinja environment in which this template is loaded.
-
#filename : String?
The filename of the template on the file system if it was loaded from there.
-
#macros : Hash(String, Tag::Macro::MacroFunction)
This hash gives access to all macros defined by this template.
-
#name : String
The loading name of the template.
-
#nodes : AST::NodeList
Returns the root node of this template's abstract syntax tree.
-
#render(io : IO, env : Crinja)
Renders this template to io in the environment env.
-
#render(io : IO, bindings = nil)
Renders this template to io using bindings as local variables scope.
-
#render(bindings = nil)
Renders this template as a
String
using bindings as local variables scope. -
#source : String
Source string of this template.
Constructor Detail
Creates a new template.
Instance Method Detail
Returns true
if this template contains a template expression. If false
, this template is a fixed string and will always render the same output.
The filename of the template on the file system if it was loaded from there. Otherwise this is nil
.
This hash gives access to all macros defined by this template.
The loading name of the template. If the template was loaded from a string this is nil
.
Renders this template to io in the environment env. This method might return unexpected results if env differs from the original environment this template was parsed with.
Renders this template to io using bindings as local variables scope.
Renders this template as a String
using bindings as local variables scope.