View Source template_compiler_utils (template_compiler v3.5.0)

Misc support routines.

Summary

Functions

Return the (universal) modification time of file, 0 on enoent

Set the next "Context" variable name in cs for an enclosed block.

Set the next "Vars" variable name in cs for an enclosed block.

Convert a list or binary to an atom.

Expand escape sequences like \n and \t in a string.

Generate an unique variable name

Types

block_owner/0

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

Functions

file_mtime(File)

-spec file_mtime(file:filename_all()) -> calendar:datetime() | 0.

Return the (universal) modification time of file, 0 on enoent

next_context_var(Cs, Ws)

-spec next_context_var(#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()}]}) ->
                          {#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()}]}}.

Set the next "Context" variable name in cs for an enclosed block.

next_vars_var(Cs, Ws)

-spec next_vars_var(#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()}]}) ->
                       {#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()}]}}.

Set the next "Vars" variable name in cs for an enclosed block.

pos(_)

set_pos(SrcPos, Tree)

-spec set_pos({file:filename_all(), pos_integer(), pos_integer()}, term()) -> term().

to_atom(L)

-spec to_atom(string() | binary() | atom()) -> atom().

Convert a list or binary to an atom.

unescape_string_literal(String)

-spec unescape_string_literal(binary()) -> binary().

Expand escape sequences like \n and \t in a string.

var(Ws)

-spec var(#ws{nr :: integer(),
              custom_tags :: term(),
              is_forloop_var :: boolean(),
              is_autoid_var :: boolean(),
              includes :: [binary()],
              debug_points :: [{binary(), integer(), integer()}]}) ->
             {#ws{nr :: integer(),
                  custom_tags :: term(),
                  is_forloop_var :: boolean(),
                  is_autoid_var :: boolean(),
                  includes :: [binary()],
                  debug_points :: [{binary(), integer(), integer()}]},
              string()}.

Generate an unique variable name