latest package¶
latest
is a LaTeX-oriented template engine.
Submodules¶
latest.config module¶
config
module contains configuration functions and classes for latest
package.
latest
is completely customizable even in its syntax.
Configuration file is found by default in ~/.latest/latest.cfg but one can use his configuration objects/files.
The section lang of the configuration file is where one can define its own syntax.
Available options in lang section are:
- code_entry
- code_exit
- ns_operator
- block_entry
- block_exit
-
latest.config.
create_config
(config_file=None)¶
latest.core module¶
core
contains core functions for templating.
-
latest.core.
eval_code
(code, ctx, config=<latest.config._Config object>)¶ Parses and evaluates code converting output to a string.
Parameters: - code (str) – the code to be evaluated.
- ctx (dict) – the context to be evaluated in.
- config (config._Config) – configuration object.
Returns: the output converted to a string.
Return type: str
Raises: CodeError
– raised if aSyntaxError
is raised by the builtineval()
function.ContextError
– raised when the context names do not match code names and aNameError
is raised by the builtineval()
function.
-
latest.core.
eval_expr
(expr, ctx, config=<latest.config._Config object>)¶ Evaluate a
latest
expression.An expression is a string of normal text with eventual code islands in between. The evaluation proceeds evaluating code islands and then concatenating the results with the fragments of plain text.
Parameters: - expr (str) – the expression to be evaluated.
- ctx (dict) – the context to be evaluated in.
- config (config._Config) – configuration object.
Returns: the output obtained concatenating the plain text fragments with the evaluation of code islands.
Return type: str
-
latest.core.
eval_namespace
(ns, ctx, config=<latest.config._Config object>)¶ Translate a namespace to a list of context dictionaries.
A namespace is a branch of a main context dictionary.
The following rules apply:
- if the path specified points to a scalar it is first converted to a dict with the ‘_value’ key set to the scalar and a one-element list filled by the dict is returned
- if the path specified points to a vector the vector is returned by the elements are treated according to these rules
- if the path specified points to a tensor (dict or object) a one-element list filled with the tensor is returned
Parameters: - ns (str) – the path for the namespace.
- ctx (dict) – the main context object.
- config (config._Config) – configuration object.
Returns: a list of context dictionaries.
Return type: list
-
latest.core.
eval_block
(block, ctx, config=<latest.config._Config object>)¶ Evaluate a
latest
block.- A block is a special
latest
syntax formed by two parts: - the namespace (optional) that define the branch of the context dictionary in which the expression must be evaluated.
- the expression to be evaluated.
Parameters: - block (str) – the block to be evaluated.
- ctx (dict) – the context to be evaluated in.
- config (config._Config) – configuration object.
Returns: the output obtained evaluating the expression within the namespace.
Return type: str
- A block is a special
-
latest.core.
eval_template
(template, ctx, config=<latest.config._Config object>)¶ Evaluates an entire template.
Parameters: - template (str) – the template.
- ctx (dict) – the context.
- config (config._Config) – configuration object.
Returns: the evaluated document.
Return type: str
latest.exceptions module¶
exceptions
module contains exceptions classes defined for latest
package.
-
exception
latest.exceptions.
CodeError
¶ Bases:
latest.exceptions.LatestError
Exception raised when bad syntax code is parsed in a template.
-
exception
latest.exceptions.
ContextError
¶ Bases:
latest.exceptions.LatestError
Exception raised when context dictionary doesn’t match names required by a template.
latest.shortcuts module¶
shortcuts
module contains shortcut functions built upon core functionality of latest
package.
-
latest.shortcuts.
render
(template_filename, data_filename, config=<latest.config._Config object>)¶ Render a template in a file within a context defined by a yaml data file.
Parameters: - template_filename (str) – the path of the template file.
- data_filename (str) – the path of the data .yaml file.
- config (config._Config) – configuration object.
Returns: the output of the evaluation process as defined by
latest
core functions.Return type: str