Previous topic

ninjecto.config

Next topic

ninjecto.inputs

This Page

ninjecto.core

Core module.

Classes

class ninjecto.core.Ninjecto(config, local, filters, namespaces, libraries, values, source, destination, filename)

Ninjecto Core Class.

Provides an API to render a directory tree, a single file, or arbitrary content.

Parameters
  • config (dict) – Configuration tree. Use ninjecto.config.load_config to get a normalized data structure.
  • local (module) – Loaded ninjeconf.py Python module. Currently unused.
  • filters (OrderedDict) – Dictionary mapping the name of the filter and the function implementing it.
  • namespaces (OrderedDict) – Dictionary mapping the name of the namespace and the function implementing it.
  • libraries (list) – List of Paths to user libraries directories.
  • values (dict) – Arbitrary tree of values to pass to the templates.
  • source (Path) – Source filepath. Either a file or a directory.
  • destination (Path) – Destination filepath. Either a file or a directory.
  • filename (str) – Override the destination filename. Pass None to use the rendered name.

Inheritance

Inheritance diagram of Ninjecto

process(src, dstdir, filename=None, levels=None)

Process a path.

Path can be a single file, or a directory, in which case it will recurse into it.

Parameters
  • src (Path) – Path to the source file or directory.
  • disdir (Path) – Path to the destination directory.
  • filename (str) – Override the destination filename. Pass None to use the rendered name.
  • levels (int) – Maximum numbers of directories levels to recurse into.
Returns

Number of files processed.

Return type

int

render(name, content, filepath=None)

Render a template.

Parameters
  • name (str) – Name of the template. Used as key to fetch the template only.
  • content (str) – The content of the template itself.
  • filepath (Path) – Path to the template file, if any. This is used to call namespaces that depend on the filepath. Namespaces that require a filepath won’t be called if unset.
Returns

The rendered template.

Return type

str

run(dry_run=False, override=False, levels=None)

Execute the rendering of this Ninjecto context.

Parameters
  • dry_run (bool) – Execute rendering without writing any file.
  • override (bool) – Override files if exit.
  • levels (int) – Maximum numbers of directories levels to recurse into.
Returns

Number of files processed.

Return type

int