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
-type block_element() :: {block, identifier_token(), elements()} | {fragment, 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 linecol() :: {Line :: integer(), Column :: integer(), file:filename_all()}.
-type options() :: [option()].
-type render_result() :: binary() | string() | term() | [render_result()].
-type template_file() :: #template_file{template :: binary(), filename :: file:filename_all()}.
-type translation_message() :: {Text :: binary(), Args :: proplists:proplist(), {Filename :: file:filename(), Line :: pos_integer(), Column :: pos_integer()}}.
Functions
-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.
-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()}]}}]}.
-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.
-spec flush() -> ok.
Remove all template lookups, forces recheck.
-spec flush_context_name(ContextName :: term()) -> ok.
Ping that a template has been changed
-spec flush_debug() -> ok.
Force recheck of all templates which are compiled with debug points enabled.
-spec flush_debug(ContextName :: term()) -> ok.
Force recheck of debug-compiled templates for a specific context name.
-spec flush_file(file:filename_all()) -> ok.
Ping that a template has been changed
Extract compiler options and handle possible defaults.
Return syntax highlighted HTML for an in-memory template source.
-spec highlight_binary(binary(), file:filename_all()) -> {ok, binary()} | {error, term()}.
Return syntax highlighted HTML for an in-memory template source.
-spec highlight_file(file:filename_all()) -> {ok, binary()} | {error, term()}.
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.
-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.
-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.
-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.
-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
-spec translations(file:filename_all()) -> {ok, [translation_message()]} | {error, term()}.
Fetch all translatable strings from a template file.