Skip to content

mkapi.renderer

source module mkapi.renderer

Render documentation for Python objects.

Classes

  • TemplateKind Enum representing different types of templates.

Functions

  • load_templates Load Jinja2 templates from the specified directory.

  • render Render a template with the given parameters.

  • render_heading Render a heading for the specified object.

  • render_object Render an object entry using the specified parameters.

  • render_document Render a document using the specified parameters.

  • render_source Render the source code for the specified object.

source load_templates(path: Path | None = None)None

Load Jinja2 templates from the specified directory.

Initialize the templates dictionary with Jinja2 templates loaded from the given directory path. If no path is provided, it defaults to the "templates" directory located in the same directory as the mkapi module.

Parameters

  • path : Path | None The directory path from which to load the templates. If None, defaults to the "templates" directory in the mkapi module.

Returns

  • None None

source enum TemplateKind()

Bases : Enum

Enum representing different types of templates.

Attributes

  • HEADING

  • HEADER

  • OBJECT

  • DOCUMENT

  • SOURCE

source render(name: str, module: str | None, level: int, namespace: str, predicate: Callable[[Parser, TemplateKind], bool] | None = None)str

Render a template with the given parameters.

Render a template based on the provided name, level, namespace, and an optional predicate function. Process the template using the appropriate rendering functions for headings, objects, documents, and source code, depending on the predicate's evaluation.

Parameters

  • name : str The name of the object to render.

  • module : str | None The module of the object to render.

  • level : int The heading level to use for rendering headings.

  • namespace : str The namespace to use for rendering objects.

  • predicate : Callable[[Parser, TemplateKind], bool] | None, optional

    A function that takes a Parser instance and a TemplateKind enum value, and returns a boolean indicating whether to render the corresponding template section. Defaults to None.

Returns

  • str The rendered markdown string.

source render_heading(name_set: NameSet, level: int)str

Render a heading for the specified object.

Render a heading for the specified object using the provided ID, fullname, and level. Use the "heading" template to generate the heading.

Parameters

  • name_set : NameSet The name set containing the object's ID and fullname.

  • level : int The heading level to use for rendering headings.

Returns

  • str The rendered heading as a markdown string.

source render_object(name_set: NameSet, level: int, namespace: str, signature: list[tuple[str, str]])str

Render an object entry using the specified parameters.

Render an object entry using the provided object, name set, namespace, signature, and bases. Use the "object" template to generate the object entry.

Parameters

  • name_set : NameSet The name set containing the object's ID and fullname.

  • level : int The heading level to use for rendering headings.

  • namespace : str The namespace to use for rendering objects.

  • signature : list[tuple[str, str]] The signature of the object.

Returns

  • str The rendered object entry as a markdown string.

source render_document(doc: Doc, bases: list[str])str

Render a document using the specified parameters.

Render a document using the provided document. Use the "document" template to generate the document.

Parameters

  • doc : Doc The document to render.

  • bases : list[str] The bases of the object.

Returns

  • str The rendered document as a markdown string.

source render_source(obj: Object, attr: str = '')str

Render the source code for the specified object.

Render the source code for the specified object using the provided object and attribute name. Use the "source" template to generate the source code.

Parameters

  • obj : Object The object to render.

  • attr : str The attribute name to render.

Returns

  • str The rendered source code as a markdown string.