class Crinja::Template

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(source : String, env : Crinja = Crinja.new, name : String = "", filename : String? = nil, run_parser = true) #

Creates a new template.


[View source]

Instance Method Detail

def dynamic? #

Returns true if this template contains a template expression. If false, this template is a fixed string and will always render the same output.


[View source]
def env : Crinja #

Crinja environment in which this template is loaded.


[View source]
def filename : String? #

The filename of the template on the file system if it was loaded from there. Otherwise this is nil.


[View source]
def macros : Hash(String, Tag::Macro::MacroFunction) #

This hash gives access to all macros defined by this template.


[View source]
def name : String #

The loading name of the template. If the template was loaded from a string this is nil.


[View source]
def nodes : AST::NodeList #

Returns the root node of this template's abstract syntax tree.


[View source]
def render(io : IO, env : Crinja) #

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.


[View source]
def render(io : IO, bindings = nil) #

Renders this template to io using bindings as local variables scope.


[View source]
def render(bindings = nil) #

Renders this template as a String using bindings as local variables scope.


[View source]
def source : String #

Source string of this template.


[View source]