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: Self)dict[str, Any]

Get the context for rendering.

source classmethod Renderable.render(cfg: Self, *args, **kwargs)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

  • render Render text from the specified configuration.

source classmethod BaseConfig.render(cfg: Self, *args: dict[str, Any] | list[str], **kwargs)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 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.