Skip to content

textconf.config

source module textconf.config

Provide tools for configuration and template-based rendering.

This module defines a base configuration class for text along with functions to locate and render templates using these configurations. It supports dynamic discovery of template methods within classes.

Classes

  • Renderable — Represent a renderable class.

  • BaseConfig — Represent a base configuration for text.

source dataclass Renderable()

Bases : ABC

Represent a renderable class.

Methods

  • context — Get the context for rendering.

  • render — Render the given configuration and return a string.

source classmethod Renderable.context(cfg: Renderable) → dict[str, Any]

Get the context for rendering.

source classmethod Renderable.render(cfg: Renderable, *args: Any, **kwargs: Any) → str

Render the given configuration and return a string.

source dataclass BaseConfig(template: str = '')

Bases : Renderable

Represent a base configuration for text.

This class provides a structure for storing configuration parameters and methods for updating and rendering text based on templates.

Attributes

  • template : str | Path — The name or path of the template file.

Methods

  • set_environment — Set the environment for the Template.

  • render — Render text from the specified configuration.

source classmethod BaseConfig.set_environment(env: Environment) → None

Set the environment for the Template.

source classmethod BaseConfig.render(cfg: Self, *args: dict[str, Any] | list[str], **kwargs: Any) → str

Render text from the specified configuration.

This method locates the template file, updates the configuration, and renders the text using the template and additional keyword arguments provided. It supports dynamic template methods defined in the class.

Parameters

  • cfg : Self — The configuration instance to render the text from.

  • *args : dict[str, Any] | list[str] — Additional positional arguments to include in the template context.

  • **kwargs : Any — Additional keyword arguments to pass to the template rendering.

Returns

  • str — The rendered text as a string.

Raises

  • FileNotFoundError — If the template file does not exist in any of the searched directories.