View Source template_compiler_runtime behaviour (template_compiler v3.5.0)
Simple runtime for the compiled templates. Needs to be copied and adapted for different environments.
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. 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.
Called when a template is rendered (could be from an include) - the return is kept in a trace for displaying template extends recursion information.
Callbacks
-callback builtin_tag(template_compiler:builtin_tag(), term(), Args :: list(), TplVars :: map(), Context :: term()) -> template_compiler:render_result().
-callback custom_tag(Module :: atom(), Args :: list(), TplVars :: map(), Context :: term()) -> template_compiler:render_result().
-callback is_modified(file:filename_all(), calendar:datetime(), term()) -> boolean().
-callback javascript_tag(template_compiler:render_result(), map(), term()) -> template_compiler:render_result().
-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 spaceless_tag(template_compiler:render_result(), map(), term()) -> template_compiler:render_result().
-callback to_render_result(Value :: term(), TplVars :: map(), Context :: term()) -> template_compiler:render_result().
-callback trace_compile(atom(), binary(), template_compiler:options(), term()) -> ok.
-callback trace_render(binary(), template_compiler:options(), term()) -> ok | {ok, iodata(), iodata()}.
Functions
-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.
-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.
-spec compile_map_nested_value(Tokens :: list(), _ContextVar :: string(), Context :: term()) -> NewTokens :: list().
Compile time mapping of nested value lookup
-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.
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.
-spec is_modified(file:filename_all(), calendar:datetime(), term()) -> boolean().
Check if a file has been modified
-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
-spec lookup_translation({trans, [{atom(), binary()}]}, TplVars :: map(), Context :: term()) -> binary().
Find the best fitting translation.
-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.
-spec map_template_all(template_compiler:template(), map(), Context :: term()) -> [template_compiler:template_file()].
Dynamically find all templates matching the template
-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 any contextual arguments from the map or argument list. User for sudo/anondo and language settings
-spec spaceless_tag(template_compiler:render_result(), map(), term()) -> template_compiler:render_result().
Remove spaces between HTML tags
Convert a value to a boolean.
Convert a value to a list.
-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.
Convert a value to a more simpler value like binary, list, boolean.
-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.
-spec trace_compile(atom(), binary(), template_compiler:options(), term()) -> ok.
Called when compiling a module
-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.
-spec trace_render(TemplateFilename, Options, Context) -> ok | {ok, Before, After} when TemplateFilename :: binary(), Options :: template_compiler:options(), Context :: term(), Before :: iodata(), After :: 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.