Module template_compiler_runtime

Simple runtime for the compiled templates.

Copyright © 2016-2020 Marc Worrell

This module defines the template_compiler_runtime behaviour.
Required callback functions: map_template/3, map_template_all/3, is_modified/3, compile_map_nested_value/3, find_nested_value/3, find_nested_value/4, find_value/4, get_context_name/1, set_context_vars/2, get_translations/2, lookup_translation/3, custom_tag/4, builtin_tag/5, cache_tag/6, javascript_tag/3, spaceless_tag/3, to_bool/2, to_list/2, to_simple_value/2, to_render_result/3, escape/2, trace_compile/4, trace_render/3, trace_block/4.

Authors: Marc Worrell (marc@worrell.nl).

Description

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

Function Index

builtin_tag/5Render image/image_url/image_data_url/media/url/lib/lib_url tag.
cache_tag/6Render a block, cache the result for some time.
compile_map_nested_value/3Compile time mapping of nested value lookup.
custom_tag/4Render a custom tag (Zotonic scomp) - this can be changed to more complex runtime lookups.
escape/2HTML escape a value.
find_nested_value/3Find 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/4
find_value/4Find the value of key in some structure.
get_context_name/1Set the context name for this context, used for flush or recompile all templates beloging to a certain context (like a single site).
get_translations/2Fetch the translations for the given text.
is_modified/3Check if a file has been modified.
javascript_tag/3Render a script block, for Zotonic this is added to the scripts in the Context.
lookup_translation/3Find the best fitting translation.
map_template/3Dynamic mapping of a template to a template name, context sensitive on the template vars.
map_template_all/3Dynamically find all templates matching the template.
set_context_vars/2Set any contextual arguments from the map or argument list.
spaceless_tag/3Remove spaces between HTML tags.
to_bool/2Convert a value to a boolean.
to_list/2Convert a value to a list.
to_render_result/3Convert a value to an render_result, used for converting values in {{ ...
to_simple_value/2Convert a value to a more simpler value like binary, list, boolean.
trace_block/4
trace_compile/4Called when compiling a module.
trace_render/3

Function Details

builtin_tag/5

builtin_tag(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.

cache_tag/6

cache_tag(Seconds::integer(), Name::binary(), Args::list(), Fun::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/3

compile_map_nested_value(Tokens::list(), _ContextVar::string(), Context::term()) -> NewTokens::list()

Compile time mapping of nested value lookup

custom_tag/4

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.

escape/2

escape(Value::iodata() | undefined, Context::term()) -> iodata()

HTML escape a value

find_nested_value/3

find_nested_value(Ks, TplVars, Context) -> any()

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/4

find_nested_value(V, Ks, TplVars, Context) -> any()

find_value/4

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

Find the value of key in some structure.

get_context_name/1

get_context_name(Context::term()) -> atom()

Set the context name for this context, used for flush or recompile all templates beloging to a certain context (like a single site).

get_translations/2

get_translations(Text::binary(), Context::term()) -> binary() | {trans, [{atom(), binary()}]}

Fetch the translations for the given text.

is_modified/3

is_modified(Filename::file:filename_all(), Mtime::calendar:datetime(), Context::term()) -> boolean()

Check if a file has been modified

javascript_tag/3

javascript_tag(Javascript::template_compiler:render_result(), TplVars::map(), Context::term()) -> template_compiler:render_result()

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

lookup_translation/3

lookup_translation(X1::{trans, [{atom(), binary()}]}, TplVars::map(), Context::term()) -> binary()

Find the best fitting translation.

map_template/3

map_template(Template_file::template_compiler:template(), Vars::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.

map_template_all/3

map_template_all(Template::template_compiler:template(), Vars::map(), Context::term()) -> [template_compiler:template_file()]

Dynamically find all templates matching the template

set_context_vars/2

set_context_vars(Args::map() | list(), Context::term()) -> term()

Set any contextual arguments from the map or argument list. User for sudo/anondo and language settings

spaceless_tag/3

spaceless_tag(Value::template_compiler:render_result(), TplVars::map(), Context::term()) -> template_compiler:render_result()

Remove spaces between HTML tags

to_bool/2

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

Convert a value to a boolean.

to_list/2

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

Convert a value to a list.

to_render_result/3

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.

to_simple_value/2

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

Convert a value to a more simpler value like binary, list, boolean.

trace_block/4

trace_block(SrcPos::{binary(), integer(), integer()}, Name::atom(), Module::atom(), Context::term()) -> ok | {ok, iodata(), iodata()}

trace_compile/4

trace_compile(Module::atom(), Filename::binary(), Options::template_compiler:options(), Context::term()) -> ok

Called when compiling a module

trace_render/3

trace_render(Filename::binary(), Options::template_compiler:options(), Context::term()) -> ok | {ok, iodata(), iodata()}


Generated by EDoc