z_template_compiler_runtime (zotonic_core v1.0.0-rc.17)

Runtime for the compiled templates with Zotonic specific interfaces.

Summary

Functions

Render image/image_url/media/url/lib tag. The Expr is the media item or dispatch rule.

Render a block, cache the result for some time. Caching should be implemented by the runtime.

Compile time mapping of nested value lookup

Render a custom tag (Zotonic scomp)

HTML escape a value

Find a list of values at once, easier and more efficient than a nested find_value/4 Add pattern matching here for nested lookups.

Find a list of values at once, easier and more efficient than a nested find_value/4 Add pattern matching here for nested lookups.

Find the value of key in some structure.

Fetch the translations for the given text.

Check if a file has been modified

Render a script block, for Zotonic this is added to the scripts in the Context

Find the best fitting translation.

Dynamic mapping of a template to a template name, context sensitive on the template vars.

Dynamically find all templates matching the template

A model call with optional payload. Compiled from m.model.path::payload

Remove spaces between HTML tags

Convert a value to a boolean.

Convert a value to a list.

Convert a value to an iolist, used for converting values in {{ ... }} expressions.

Convert a value to something that can be handled as an argument to scomps.

Convert an argument list's values to something that can be handled as an argument to scomps.

Called when a block function is called. The optionally returned prefix and postfix are inserted into the output stream before and after the block content, respectively.

Called when compiling a module

Called when an enabled template debug checkpoint is hit. The development module will observe this notification and register the variable values at the breakpoints. The debug checkpoints are disabled if the current controller has the 'sensitive' option set, unless the environment is development for which tracing is always allowed.

Called when a template is rendered (could be from an include). Optionally inserts text before and after the text inclusion into the output stream.

Functions

builtin_tag(Tag, Expr, Args, Vars, Context)

-spec builtin_tag(template_compiler:builtin_tag(),
                  Expr :: term(),
                  Args :: list(),
                  Vars :: map(),
                  Context :: term()) ->
                     template_compiler:render_result().

Render image/image_url/media/url/lib tag. The Expr is the media item or dispatch rule.

cache_tag(MaxAge, Name, Args, Fun, TplVars, Context)

-spec cache_tag(MaxAge :: integer(),
                Name :: binary(),
                Args :: list(),
                function(),
                TplVars :: map(),
                Context :: term()) ->
                   template_compiler:render_result().

Render a block, cache the result for some time. Caching should be implemented by the runtime.

compile_map_nested_value(Tokens, ContextVar, Context)

-spec compile_map_nested_value(Tokens :: list(), ContextVar :: string(), Context :: term()) ->
                                  NewTokens :: list().

Compile time mapping of nested value lookup

custom_tag(Tag, Args, Vars, Context)

-spec custom_tag(Tag :: atom(), Args :: list(), Vars :: map(), Context :: term()) ->
                    template_compiler:render_result().

Render a custom tag (Zotonic scomp)

escape(Value, Context)

-spec escape(Value :: iodata() | undefined, Context :: z:context()) -> iodata().

HTML escape a value

find_nested_value(Ks, TplVars, Context)

Find a list of values at once, easier and more efficient than a nested find_value/4 Add pattern matching here for nested lookups.

find_nested_value(V, Ks, TplVars, Context)

Find a list of values at once, easier and more efficient than a nested find_value/4 Add pattern matching here for nested lookups.

find_value(Key, Vars, TplVars, Context)

-spec find_value(Key :: term(), Vars :: term(), TplVars :: map(), Context :: term()) -> term().

Find the value of key in some structure.

get_context_name(Context)

-spec get_context_name(term()) -> atom().

get_translations(Text, Context)

-spec get_translations(binary(), term()) -> z:trans().

Fetch the translations for the given text.

is_modified(Filename, Mtime, Context)

-spec is_modified(file:filename_all(), calendar:datetime(), term()) -> boolean().

Check if a file has been modified

javascript_tag(Block, TplVars, Context)

Render a script block, for Zotonic this is added to the scripts in the Context

lookup_translation(Trans, TplVars, Context)

-spec lookup_translation(z:trans(), TplVars :: map(), Context :: term()) -> binary() | undefined.

Find the best fitting translation.

map_template(Template_file, Vars, Context)

-spec map_template(template_compiler:template(), map(), term()) ->
                      {ok, template_compiler:template_file()} | {error, enoent | term()}.

Dynamic mapping of a template to a template name, context sensitive on the template vars.

map_template_all(Template, Vars, Context)

-spec map_template_all(template_compiler:template(), map(), term()) ->
                          [template_compiler:template_file()].

Dynamically find all templates matching the template

model_call(Model, Path, Payload, Context)

-spec model_call(Model :: atom(), Path :: list(), Payload :: term(), Context :: term()) ->
                    template_compiler:model_return().

A model call with optional payload. Compiled from m.model.path::payload

set_context_vars(Args, Context)

-spec set_context_vars(map() | list(), term()) -> term().

spaceless_tag(Value, TplVars, Context)

Remove spaces between HTML tags

to_bool(Value, Context)

-spec to_bool(Value :: term(), Context :: term()) -> boolean().

Convert a value to a boolean.

to_list(Value, Context)

-spec to_list(Value :: term(), Context :: term()) -> list().

Convert a value to a list.

to_render_result(Value, TplVars, Context)

-spec to_render_result(Value :: term(), TplVars :: map(), Context :: term()) ->
                          template_compiler:render_result().

Convert a value to an iolist, used for converting values in {{ ... }} expressions.

to_simple_value(Value, Context)

-spec to_simple_value(Value :: term(), Context :: term()) -> term().

Convert a value to something that can be handled as an argument to scomps.

to_simple_values(Args, Context)

-spec to_simple_values(Args :: list(), Context :: term()) -> list().

Convert an argument list's values to something that can be handled as an argument to scomps.

trace_block(SrcPos, BlockName, Module, Context)

-spec trace_block(SrcPos, BlockName, Module, Context) -> ok | {ok, Before, After}
                     when
                         SrcPos :: {Filename, Line, Column},
                         Filename :: binary(),
                         Line :: integer(),
                         Column :: integer(),
                         BlockName :: atom(),
                         Module :: atom(),
                         Context :: term(),
                         Before :: iodata(),
                         After :: iodata().

Called when a block function is called. The optionally returned prefix and postfix are inserted into the output stream before and after the block content, respectively.

trace_compile(Module, Filename, Options, Context)

-spec trace_compile(atom(), binary(), template_compiler:options(), z:context()) -> ok.

Called when compiling a module

trace_debug(SrcPos, Vars, Context)

-spec trace_debug(SrcPos, Vars, Context) -> ok
                     when
                         SrcPos :: {File, Line, Col},
                         File :: binary(),
                         Line :: integer(),
                         Col :: integer(),
                         Vars :: map(),
                         Context :: term().

Called when an enabled template debug checkpoint is hit. The development module will observe this notification and register the variable values at the breakpoints. The debug checkpoints are disabled if the current controller has the 'sensitive' option set, unless the environment is development for which tracing is always allowed.

trace_render(TemplateFilename, Options, Context)

-spec trace_render(TemplateFilename, Options, Context) -> ok | {ok, Before, After}
                      when
                          TemplateFilename :: binary(),
                          Options :: template_compiler:options(),
                          Context :: z:context(),
                          Before :: iodata(),
                          After :: iodata().

Called when a template is rendered (could be from an include). Optionally inserts text before and after the text inclusion into the output stream.