Overview
The template engine module provides a flexible Jinja2-based rendering system for generating README files and other documentation. It supports custom template directories and provides a convenient helper function for README generation. Source:docugen/templates/engine.py
TemplateEngine
Parameters
Custom directory containing template files. If
None, uses the built-in templates directory (docugen/templates/).Attributes
Configured Jinja2 environment with:
autoescape=False- No automatic HTML escapingtrim_blocks=True- Remove first newline after blocklstrip_blocks=True- Strip leading whitespace from blocks
Methods
render()
Name of the template file to render (e.g.,
"default_readme.md.j2").Dictionary of variables to pass to the template.
Rendered template content with trailing newline.
Example
render_readme()
TemplateEngine instance and renders the default_readme.md.j2 template with standardized context variables.
Parameters
AI-generated documentation content. Automatically stripped of leading/trailing whitespace.
Name of the project being documented.
Optional metadata dictionary (e.g., file counts, statistics). Defaults to empty dict if not provided.
Returns
Rendered README content with trailing newline.
Example
Constants
Default template filename used by
render_readme().Template Context
When usingrender_readme(), the following variables are available in templates:
| Variable | Type | Description |
|---|---|---|
project_name | str | Project name |
ai_content | str | Generated documentation (trimmed) |
summary | dict | Metadata dictionary |
Related
- Configuration Manager - Runtime configuration
- CLI Reference - Command-line interface
