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 configurable both programmatically and through a configuration file.
Configurations are contained in a _Config object. Constructor (__init__ method) of this class
accepts the optional keyword argument config_file to specify the location of the configuration file.
If no configuration file is specified, defaults are set in code.
A default configuration object (config) is defined in this module and can be imported to be used elsewhere.
I suggest an import statement like
from latest.config import config as Config
so that you can think of it as a class with many static attributes and methods.
To create an alternate configuration object you can use the public function create_config(config_file=None).
Configuration file is found by default (config looks for this location)
in ~/.latest/latest.cfg but one can use his own configuration files.
The formatting of a configuration file must be ini format.
Useful sections of a configuration file are:
- general
- lang
The section lang of a configuration file is where one can define its own syntax. Available options in lang section are:
- pyexpr_entry: the regex indicating the start of a python expression block.
- pyexpr_exit: the regex indicating the end of a python expression block.
- env_entry: the regex indicating the start of a latest environment.
- env_exit: the regex indicating the end of a latest environment.
-
latest.config.create_config(config_file=None)¶
latest.core module¶
core contains core functions for templating.
-
class
latest.core.Context(*args, **kwargs)¶ Bases:
dict
-
latest.core.contextify(obj)¶
-
latest.core.listify(context)¶
-
class
latest.core.ParserHandler(toks)¶ Bases:
object
-
class
latest.core.GrammarHandler(toks)¶ Bases:
latest.core.ParserHandler-
eval(context, config=<latest.config._Config object>, **options)¶
-
-
class
latest.core.PyExprHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
-
class
latest.core.StrPyExprHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
-
class
latest.core.OptHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
-
class
latest.core.OptsHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
-
class
latest.core.EnvHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
-
class
latest.core.TxtHandler(toks)¶ Bases:
latest.core.ParserHandler-
initialize()¶
-
eval(context)¶
-
latest.exceptions module¶
exceptions module contains exceptions classes defined for latest package.
-
exception
latest.exceptions.PyExprSyntaxError¶ Bases:
latest.exceptions.LatestErrorException raised when bad syntax code is parsed in a template.
-
exception
latest.exceptions.ContextError¶ Bases:
latest.exceptions.LatestErrorException 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 json or yaml formatted data file.
Parameters: - template_filename (str) – the path of the template file.
- data_filename (str) – the path of the json or yaml data file.
- config (config._Config) – configuration object.
Returns: the output of the evaluation process as defined by
latestcore functions.Return type: str