Skip to content
albert12132 edited this page Dec 23, 2015 · 2 revisions

Publishing

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: type Config; a context that includes variables, compiler options, and templater information. See Config API for details.

  • source: type str; path to a source file, relative to the current working directory. If None, the publisher effectively becomes a templating engine.

  • template: type str; path to a Jinja template file. Templar treats the path as relative to the list of template directories in config.

    If template is None, the publisher effectively becomes a linker and compiler.

  • destination: type str; path for the destination file.

  • jinja_env: type jinja2.Environment; if None, a Jinja2 Environment is created with a FileSystemLoader that is configured with config.template_dirs. Otherwise, the given Jinja2 Environment is used to retrieve and render the template.

  • no_write: type bool; 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.
Clone this wiki locally