View Source template_compiler_runtime behaviour (template_compiler v2.12.0)

Simple runtime for the compiled templates. Needs to be copied and adapted for different environments.

Link to this section Summary

Functions

Render image/image_url/image_data_url/media/url/lib/lib_url 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) - this can be changed to more complex runtime lookups.
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 the value of key in some structure.
Set the context name for this context, used for flush or recompile all templates belonging to a certain context (like a single site).
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
Set any contextual arguments from the map or argument list. User for sudo/anondo and language settings
Remove spaces between HTML tags
Convert a value to a boolean.
Convert a value to a list.
Convert a value to an render_result, used for converting values in {{ ... }} expressions.
Convert a value to a more simpler value like binary, list, boolean.
Called when a block function is called
Called when compiling a module
Called when a template is rendered (could be from an include) - the return is kept in a trace for displaying template extends recursion information.

Link to this section Callbacks

-callback builtin_tag(template_compiler:builtin_tag(),
            term(),
            Args :: list(),
            TplVars :: map(),
            Context :: term()) ->
               template_compiler:render_result().
-callback cache_tag(Seconds :: integer(),
          Name :: binary(),
          Args :: list(),
          function(),
          TplVars :: map(),
          Context :: term()) ->
             template_compiler:render_result().
Link to this callback

compile_map_nested_value/3

View Source
-callback compile_map_nested_value(Tokens :: list(), ContextVar :: string(), Context :: term()) ->
                            NewTokens :: list().
-callback custom_tag(Module :: atom(), Args :: list(), TplVars :: map(), Context :: term()) ->
              template_compiler:render_result().
-callback escape(iodata() | undefined, Context :: term()) -> iodata().
-callback find_nested_value(Keys :: list(), TplVars :: term(), Context :: term()) -> term().
-callback find_nested_value(BaseValue :: term(), Keys :: list(), TplVars :: term(), Context :: term()) ->
                     term().
-callback find_value(Key :: term(), Vars :: term(), TplVars :: map(), Context :: term()) -> term().
-callback get_context_name(Context :: term()) -> atom().
-callback get_translations(Text :: binary(), Context :: term()) -> binary() | {trans, [{atom(), binary()}]}.
-callback is_modified(file:filename_all(), calendar:datetime(), term()) -> boolean().
-callback javascript_tag(template_compiler:render_result(), map(), term()) ->
                  template_compiler:render_result().
-callback lookup_translation({trans, [{atom(), binary()}]}, TplVars :: map(), Context :: term()) -> binary().
-callback map_template(template_compiler:template(), map(), term()) ->
                {ok, template_compiler:template_file()} | {error, enoent | term()}.
-callback map_template_all(template_compiler:template(), map(), term()) ->
                    [template_compiler:template_file()].
-callback model_call(Model :: atom(), Path :: list(), Payload :: term(), Context :: term()) ->
              template_compiler:model_return().
-callback set_context_vars(map() | list(), Context :: term()) -> Context :: term().
-callback spaceless_tag(template_compiler:render_result(), map(), term()) ->
                 template_compiler:render_result().
-callback to_bool(Value :: term(), Context :: term()) -> boolean().
-callback to_list(Value :: term(), Context :: term()) -> list().
-callback to_render_result(Value :: term(), TplVars :: map(), Context :: term()) ->
                    template_compiler:render_result().
-callback to_simple_value(Value :: term(), Context :: term()) -> term().
-callback trace_block({binary(), integer(), integer()}, atom(), atom(), term()) ->
               ok | {ok, iodata(), iodata()}.
-callback trace_compile(atom(), binary(), template_compiler:options(), term()) -> ok.
-callback trace_render(binary(), template_compiler:options(), term()) -> ok | {ok, iodata(), iodata()}.

Link to this section Functions

Link to this function

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

View Source
-spec builtin_tag(template_compiler:builtin_tag(),
            Expr :: term(),
            Args :: list(),
            Vars :: map(),
            Context :: term()) ->
               template_compiler:render_result().
Render image/image_url/image_data_url/media/url/lib/lib_url tag. The Expr is the media item or dispatch rule.
Link to this function

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

View Source
-spec cache_tag(Seconds :: 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.
Link to this function

compile_map_nested_value(Tokens, _ContextVar, Context)

View Source
-spec compile_map_nested_value(Tokens :: list(), _ContextVar :: string(), Context :: term()) ->
                            NewTokens :: list().
Compile time mapping of nested value lookup
Link to this function

custom_tag(Tag, Args, Vars, Context)

View Source
-spec custom_tag(Tag :: atom(), Args :: list(), Vars :: map(), Context :: term()) ->
              template_compiler:render_result().
Render a custom tag (Zotonic scomp) - this can be changed to more complex runtime lookups.
-spec escape(Value :: iodata() | undefined, Context :: term()) -> iodata().
HTML escape a value
Link to this function

find_nested_value(Ks, TplVars, Context)

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

find_nested_value(V, Ks, TplVars, Context)

View Source
Link to this function

find_value(Key, Vars, TplVars, Context)

View Source
-spec find_value(Key :: term(), Vars :: term(), TplVars :: map(), Context :: term()) -> term().
Find the value of key in some structure.
Link to this function

get_context_name(Context)

View Source
-spec get_context_name(term()) -> atom().
Set the context name for this context, used for flush or recompile all templates belonging to a certain context (like a single site).
Link to this function

get_translations(Text, Context)

View Source
-spec get_translations(binary(), term()) -> binary() | {trans, [{atom(), binary()}]}.
Fetch the translations for the given text.
Link to this function

is_modified(Filename, Mtime, Context)

View Source
-spec is_modified(file:filename_all(), calendar:datetime(), term()) -> boolean().
Check if a file has been modified
Link to this function

javascript_tag(Javascript, TplVars, Context)

View Source
-spec javascript_tag(template_compiler:render_result(), map(), term()) ->
                  template_compiler:render_result().
Render a script block, for Zotonic this is added to the scripts in the Context
Link to this function

lookup_translation(_, TplVars, Context)

View Source
-spec lookup_translation({trans, [{atom(), binary()}]}, TplVars :: map(), Context :: term()) -> binary().
Find the best fitting translation.
Link to this function

map_template(Template_file, Vars, Context)

View Source
-spec map_template(template_compiler:template(), map(), Context :: term()) ->
                {ok, template_compiler:template_file()} | {error, enoent | term()}.
Dynamic mapping of a template to a template name, context sensitive on the template vars.
Link to this function

map_template_all(Template, Vars, Context)

View Source
-spec map_template_all(template_compiler:template(), map(), Context :: term()) ->
                    [template_compiler:template_file()].
Dynamically find all templates matching the template
Link to this function

model_call(Model, Path, Payload, Context)

View Source
-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
Link to this function

set_context_vars(Args, Context)

View Source
-spec set_context_vars(map() | list(), term()) -> term().
Set any contextual arguments from the map or argument list. User for sudo/anondo and language settings
Link to this function

spaceless_tag(Value, TplVars, Context)

View Source
-spec spaceless_tag(template_compiler:render_result(), map(), term()) ->
                 template_compiler:render_result().
Remove spaces between HTML tags
-spec to_bool(Value :: term(), Context :: term()) -> boolean().
Convert a value to a boolean.
-spec to_list(Value :: term(), Context :: term()) -> list().
Convert a value to a list.
Link to this function

to_render_result(Value, TplVars, Context)

View Source
-spec to_render_result(Value :: term(), TplVars :: map(), Context :: term()) ->
                    template_compiler:render_result().
Convert a value to an render_result, used for converting values in {{ ... }} expressions.
Link to this function

to_simple_value(Value, Context)

View Source
-spec to_simple_value(Value :: term(), Context :: term()) -> term().
Convert a value to a more simpler value like binary, list, boolean.
Link to this function

trace_block(SrcPos, Name, Module, Context)

View Source
-spec trace_block({binary(), integer(), integer()}, atom(), atom(), term()) ->
               ok | {ok, iodata(), iodata()}.
Called when a block function is called
Link to this function

trace_compile(Module, Filename, Options, Context)

View Source
-spec trace_compile(atom(), binary(), template_compiler:options(), term()) -> ok.
Called when compiling a module
Link to this function

trace_render(Filename, Options, Context)

View Source
-spec trace_render(binary(), template_compiler:options(), term()) -> ok | {ok, iodata(), iodata()}.
Called when a template is rendered (could be from an include) - the return is kept in a trace for displaying template extends recursion information.