The Transformer class¶
-
class
ferenda.Transformer(transformertype, template, templatedir, resourceloader=None, documentroot=None, config=None)[source]¶ Transforms parsed “pure content” documents into “browser-ready” HTML5 files with site branding and navigation, using a template of some kind.
Parameters: - transformertype (str) – The engine to be used for transforming. Right now only
"XSLT"is supported. - resourceloader – The
ResourceLoaderinstance used to find template files. - template (str) – The name of the main template file.
- templatedir (str) – Directory for supporting templates to the main template.
- documentroot (str) – The base directory for all generated files – used to make relative references to CSS/JS files correct.
- config – Any configuration information used by the
transforming engine. Can be a path to a config
file, a python data structure, or anything else
compatible with the engine selected by
transformertype.
Note
An initialized Transformer object only transforms using the template file provided at initialization. If you need to use another template file, create another Transformer object.
-
transform(indata, depth, parameters=None, uritransform=None)[source]¶ Perform the transformation. This method always operates on the “native” datastructure – this might be different depending on the transformer engine. For XSLT, which is implemented through lxml, its in- and outdata are lxml trees
If you need an engine-indepent API, use
transform_stream()ortransform_file()insteadParameters: - indata – The document to be transformed
- depth (int) – The directory nesting level, compared to
documentroot - parameters (dict) – Any parameters that should be provided to the template
- uritransform (callable) – A function, when called with an URI, returns a transformed URI/URL (such as the relative path to a static file) – used when transforming to files used for static offline use.
Returns: The transformed document
- transformertype (str) – The engine to be used for transforming. Right now only