-
Notifications
You must be signed in to change notification settings - Fork 4
Python API
The templar.api.publish
module defines a single function called publish
that effectively does the same thing as the command-line interface:
def publish(
config,
source=None,
template=None,
destination=None,
jinja_env=None,
no_write=False):
Given a config, performs an end-to-end publishing pipeline and returns the result:
linking -> compiling -> templating -> writing
Note: at most one of source and template can be None. If both are None, the publisher effectively has nothing to do; a PublishError
is raised.
Parameters:
-
config
: typeConfig
; a context that includes variables, compiler options, and templater information. See Config API for details. -
source
: typestr
; path to a source file, relative to the current working directory. If None, the publisher effectively becomes a templating engine. -
template
: typestr
; path to a Jinja template file. Templar treats the path as relative to the list of template directories inconfig
.If template is None, the publisher effectively becomes a linker and compiler.
-
destination
: typestr
; path for the destination file. -
jinja_env
: typejinja2.Environment
; if None, a Jinja2 Environment is created with a FileSystemLoader that is configured withconfig.template_dirs
. Otherwise, the given Jinja2 Environment is used to retrieve and render the template. -
no_write
: typebool
; if True, the result is not written to a file or printed. If False and destination is provided, the result is written to the provided destination file.
Returns:
- type
str
; the result of the publishing pipeline.