View Source template_compiler (template_compiler v3.5.0)

Main template compiler entry points.

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

Force recheck of all templates which are compiled with debug points enabled.

Force recheck of debug-compiled templates for a specific context name.

Ping that a template has been changed

Extract compiler options and handle possible defaults.

Return syntax highlighted HTML for an in-memory template source.

Return syntax highlighted HTML for an in-memory template source.

Return syntax highlighted HTML for a template source file.

Return syntax highlighted HTML for a compiled template module, including checkbox inputs for the module's debug points.

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 template. This looks up the templates needed, ensures compilation and returns the rendering result. Start with a block-map to find some predefined blocks.

Render a named block, defined in a template

Fetch all translatable strings from a template file.

Types

block_element/0

-type block_element() ::
          {block, identifier_token(), elements()} | {fragment, identifier_token(), elements()}.

block_owner/0

-type block_owner() :: atom() | {useblock, atom() | binary(), {binary(), integer(), integer()}}.

builtin_tag/0

-type builtin_tag() :: image | image_url | image_data_url | media | url | lib.

element/0

-type element() :: block_element() | true | false | undefined | term().

elements/0

-type elements() :: [element()].

identifier_token/0

-type identifier_token() :: {identifier, linecol(), binary()}.

linecol/0

-type linecol() :: {Line :: integer(), Column :: integer(), file:filename_all()}.

model_return/0

-type model_return() :: {ok, {term(), list()}} | {error, term()}.

option/0

-type option() ::
          {runtime, atom()} |
          {context_name, term()} |
          {context_vars, [binary()]} |
          {debug_points, all | [{integer(), integer()}] | map()} |
          {trace_position, {Filename :: binary(), Line :: integer(), Col :: integer()}}.

options/0

-type options() :: [option()].

render_result/0

-type render_result() :: binary() | string() | term() | [render_result()].

template/0

-type template() ::
          binary() |
          string() |
          {cat, binary() | string()} |
          {cat, binary() | string(), term()} |
          {overrules, binary() | string(), file:filename_all()} |
          template_file().

template_file/0

-type template_file() :: #template_file{template :: binary(), filename :: file:filename_all()}.

template_key/0

-type template_key() :: {ContextName :: term(), Runtime :: atom(), template()}.

translation_message/0

-type translation_message() ::
          {Text :: binary(),
           Args :: proplists:proplist(),
           {Filename :: file:filename(), Line :: pos_integer(), Column :: pos_integer()}}.

Functions

compile_binary(TemplateBin, Filename, Options, Context)

-spec compile_binary(TemplateBin, Filename, Options, Context) -> {ok, Module} | {error, term()}
                        when
                            TemplateBin :: binary(),
                            Filename :: file:filename_all(),
                            Options :: options(),
                            Context :: term(),
                            Module :: module().

Compile a in-memory template to a module.

compile_blocks(Blocks, Cs)

-spec compile_blocks([block_element()],
                     #cs{filename :: binary(),
                         module :: atom(),
                         block_owner :: undefined | block_owner(),
                         block :: atom(),
                         blocks ::
                             [{atom(),
                               erl_syntax:syntaxTree(),
                               #ws{nr :: integer(),
                                   custom_tags :: term(),
                                   is_forloop_var :: boolean(),
                                   is_autoid_var :: boolean(),
                                   includes :: [binary()],
                                   debug_points :: [{binary(), integer(), integer()}]}}],
                         runtime :: atom(),
                         context :: term(),
                         vars_var :: string(),
                         context_var :: string(),
                         context_vars :: [binary()],
                         is_autoescape :: boolean(),
                         enabled_debug_points :: all | map()}) ->
                        {#ws{nr :: integer(),
                             custom_tags :: term(),
                             is_forloop_var :: boolean(),
                             is_autoid_var :: boolean(),
                             includes :: [binary()],
                             debug_points :: [{binary(), integer(), integer()}]},
                         [{atom(),
                           erl_syntax:syntaxTree(),
                           #ws{nr :: integer(),
                               custom_tags :: term(),
                               is_forloop_var :: boolean(),
                               is_autoid_var :: boolean(),
                               includes :: [binary()],
                               debug_points :: [{binary(), integer(), integer()}]}}]}.

compile_file(Filename, Options, Context)

-spec compile_file(Filename, Options, Context) -> {ok, Module} | {error, term()}
                      when
                          Filename :: file:filename_all(),
                          Options :: options(),
                          Context :: term(),
                          Module :: module().

Compile a template to a module. The template is the path of the template to be compiled.

flush()

-spec flush() -> ok.

Remove all template lookups, forces recheck.

flush_context_name(ContextName)

-spec flush_context_name(ContextName :: term()) -> ok.

Ping that a template has been changed

flush_debug()

-spec flush_debug() -> ok.

Force recheck of all templates which are compiled with debug points enabled.

flush_debug(ContextName)

-spec flush_debug(ContextName :: term()) -> ok.

Force recheck of debug-compiled templates for a specific context name.

flush_file(Filename)

-spec flush_file(file:filename_all()) -> ok.

Ping that a template has been changed

get_option(Option, Options)

-spec get_option(Option :: atom(), Options :: options()) -> term().

Extract compiler options and handle possible defaults.

highlight_binary(Bin)

-spec highlight_binary(binary()) -> {ok, binary()} | {error, term()}.

Return syntax highlighted HTML for an in-memory template source.

highlight_binary(Bin, Filename)

-spec highlight_binary(binary(), file:filename_all()) -> {ok, binary()} | {error, term()}.

Return syntax highlighted HTML for an in-memory template source.

highlight_file(Filename)

-spec highlight_file(file:filename_all()) -> {ok, binary()} | {error, term()}.

Return syntax highlighted HTML for a template source file.

highlight_module(Module)

-spec highlight_module(module()) -> {ok, binary()} | {error, term()}.

Return syntax highlighted HTML for a compiled template module, including checkbox inputs for the module's debug points.

is_enabled_debug_points(DebugPoints)

is_template_module(X)

-spec is_template_module(binary() | string() | atom()) -> boolean().

Check if the modulename looks like a module generated by the template compiler.

lookup(Filename, Options, Context)

-spec lookup(Filename, Options, Context) -> {ok, Module} | {error, term()}
                when Filename :: binary(), Options :: options(), Context :: term(), Module :: module().

Find the module of a compiled template, if not yet compiled then compile the template.

namespace_fragment_blocks(FragmentName, Elements)

render(Template, Vars, Options, Context)

-spec render(Template, Vars, Options, Context) -> {ok, render_result()} | {error, term()}
                when
                    Template :: template(),
                    Vars :: map() | list(),
                    Options :: options(),
                    Context :: term().

Render a template. This looks up the templates needed, ensures compilation and returns the rendering result.

render(Template, BlockMap, Vars, Options, Context)

-spec render(Template, BlockMap, Vars, Options, Context) -> {ok, render_result()} | {error, term()}
                when
                    Template :: template(),
                    BlockMap :: map(),
                    Vars :: map() | list(),
                    Options :: options(),
                    Context :: term().

Render a template. This looks up the templates needed, ensures compilation and returns the rendering result. Start with a block-map to find some predefined blocks.

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

-spec render_block(Block, Template, Vars, Options, Context) -> {ok, render_result()} | {error, term()}
                      when
                          Block :: atom(),
                          Template :: template(),
                          Vars :: map() | list(),
                          Options :: options(),
                          Context :: term().

Render a named block, defined in a template

translations(Filename)

-spec translations(file:filename_all()) -> {ok, [translation_message()]} | {error, term()}.

Fetch all translatable strings from a template file.