Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Latest commit

 

History

History
318 lines (211 loc) · 9.23 KB

plugin_api.rst

File metadata and controls

318 lines (211 loc) · 9.23 KB

Plugin API

All complex custom content in Imprint is generated by the plugins <introduction-layers-plugins>. Plugins are implemented by special configurable :pycallable objects called handlers that follow a specific interface, which allows them to be referenced by the appropriate tags in the configuration-xml.

Three types of content are supported out of the box: plugins-figures, plugins-tables and plugins-strings. Each type of plugin accepts a mapping of keywords from the configuration-ipc (and the xml-spec-tags-expr tags in the configuration-xml), and a dictionary of data configuration values from the configuration-idc that defines the behavior of the plugin. Beyond that, each type of handler has a different interface.

In fact, any custom :py~imprint.core.tags.TagDescriptor may define its own plugin interface. What makes a tag pluggable is its reliance on a function that accepts a data configuration. This technically makes the plugin API an implementation of a very distinct part of the tag_api.

Contents

Data Configuration

The data configuration is the second argument to every handler. The data configuration is a mapping set for every plugin in the configuration-idc. The name of the configuration dictionary is in the id attribute <configuration-idc-names> of the corresponding xml-spec-tags-figure, xml-spec-tags-table or xml-spec-tags-string placeholder tag in the configuration-xml. Custom tags may be registered as configurable plugins by setting the :py~imprint.core.tags.TagDescriptor.data_config attribute of their :py~imprint.core.tags.TagDescriptor.

Data configuration values can contain any type of values, as long as they are meaningful to the plugin. Plugins may require some keys to be present in the configuration, and should raise a :py~imprint.core.KnownError, optionally caused by a :pyKeyError in response to missing keys. Most plugins will require some sort of data source, such as a file name, but again, this is not required.

Some values are special, in that they can override XML attibutes used by the :py~imprint.core.tags.TagDescriptor. In particular, the handler attribute can be overridden by a key with the similar name in the configuration-idc. Overridable values are noted for each builtin tag <xml-spec-tags> in the xml_spec.

Handlers

Handlers are named by the handler attribute of the corresponding xml-spec-tags-figure, xml-spec-tags-table or xml-spec-tags-string placeholder tag in the configuration-xml. The exact class name (including package) is searched for the handler. If not found, a prefix of imprint.handlers is prepended to the nominal package name.

The handler can be overridden in the plugins-data-configuration dictionary. Normally, all configuration keys are interpreted directly by the handler. However, a special handler key will processed before a handler is found, and can override the setting in the XML. This mechanism is provided by each of the tag-api-descriptors for plugins-figures, plugins-tables and plugins-strings. It allows for more flexible debugging, and modification of existing templates. New tag-api-descriptors can use the :py~imprint.core.tags.get_handler function to implement the same functionality, although it is not stritcly required.

Figures

Some built-in figure handler examples can be found in imprint.handlers.figure.

XML Tag

xml-spec-tags-figure

Handler Signature

Tables

Some built-in table handler examples can be found in imprint.handlers.table.

XML Tag

xml-spec-tags-table

Handler Signature

Strings

Some built-in string handler examples can be found in imprint.handlers.string.

XML Tag

xml-spec-tags-string

Handler Signature

Errors

Since plugins implement a subset of the tag-processing functionality, the same rules apply to plugin errors at to generic tag errors. See tag-api-descriptor-errors in the tag_api section.

Builtin Plugins

imprint.handlers

Figures

imprint.handlers.figure

ImageFile

Submodules

imprint.handlers.figure.images

Tables

imprint.handlers.table

CSVFile

DataFrame

Submodules

imprint.handlers.table.tables

Strings

imprint.handlers.string

TextFile

Submodules

imprint.handlers.string.strings

Utilities

imprint.handlers.utilities