View Source template_compiler (template_compiler v2.8.0)

Main template compiler entry points.

Link to this section Summary

Functions

Compile a in-memory template to a module.
Compile a template to a module. The template is the path of the template to be compiled.
Remove all template lookups, forces recheck.
Ping that a template has been changed
Ping that a template has been changed
Extract compiler options and handle possible defaults.
Check if the modulename looks like a module generated by the template compiler.
Find the module of a compiled template, if not yet compiled then compile the template.
Render a template. This looks up the templates needed, ensures compilation and returns the rendering result.
Render a named block, defined in a template
Fetch all translatable strings from a template.

Link to this section Types

-type block_element() :: {block, identifier_token(), elements()}.
-type builtin_tag() :: image | image_url | image_data_url | media | url | lib.
-type element() :: block_element() | true | false | undefined | term().
-type elements() :: [element()].
-type identifier_token() :: {identifier, linecol(), binary()}.
-type linecol() :: {Line :: integer(), Column :: integer(), file:filename_all()}.
-type model_return() :: {ok, {term(), list()}} | {error, term()}.
-type option() ::
    {runtime, atom()} |
    {context_name, term()} |
    {trace_position, {Filename :: binary(), Line :: integer(), Col :: integer()}} |
    {context_vars, [binary()]}.
-type options() :: [option()].
-type render_result() :: binary() | string() | term() | [render_result()].
-type template() ::
    binary() |
    string() |
    {cat, binary() | string()} |
    {cat, binary() | string(), term()} |
    {overrules, binary() | string(), file:filename_all()} |
    template_file().
-type template_file() :: #template_file{}.
-type template_key() :: {ContextName :: term(), Runtime :: atom(), template()}.
-type translation_message() ::
    {Text :: binary(),
     Args :: proplists:proplist(),
     {Filename :: file:filename(), Line :: pos_integer(), Column :: pos_integer()}}.

Link to this section Functions

Link to this function

compile_binary(Tpl, Filename, Options, Context)

View Source
-spec compile_binary(binary(), file:filename_all(), options(), term()) -> {ok, atom()} | {error, term()}.
Compile a in-memory template to a module.
Link to this function

compile_file(Filename, Options, Context)

View Source
-spec compile_file(file:filename_all(), options(), term()) -> {ok, atom()} | {error, term()}.
Compile a template to a module. The template is the path of the template to be compiled.
-spec flush() -> ok.
Remove all template lookups, forces recheck.
Link to this function

flush_context_name(ContextName)

View Source
-spec flush_context_name(ContextName :: term()) -> ok.
Ping that a template has been changed
-spec flush_file(file:filename_all()) -> ok.
Ping that a template has been changed
Link to this function

get_option(Option, Options)

View Source
-spec get_option(Option :: atom(), Options :: options()) -> term().
Extract compiler options and handle possible defaults.
-spec is_template_module(binary() | string() | atom()) -> boolean().
Check if the modulename looks like a module generated by the template compiler.
Link to this function

lookup(Filename, Options, Context)

View Source
-spec lookup(binary(), options(), term()) -> {ok, atom()} | {error, term()}.
Find the module of a compiled template, if not yet compiled then compile the template.
Link to this function

render(Template, Vars, Options, Context)

View Source
-spec render(Template :: template(), Vars :: map() | list(), Options :: options(), Context :: term()) ->
          {ok, render_result()} | {error, term()}.
Render a template. This looks up the templates needed, ensures compilation and returns the rendering result.
Link to this function

render_block(Block, Template, Vars, Options, Context)

View Source
-spec render_block(Block :: atom(),
             Template :: template(),
             Vars :: map() | list(),
             Options :: options(),
             Context :: term()) ->
                {ok, render_result()} | {error, term()}.
Render a named block, defined in a template
-spec translations(file:filename_all()) -> {ok, [translation_message()]} | {error, term()}.
Fetch all translatable strings from a template.