capcat.core.template_renderer
File: Application/capcat/core/template_renderer.py
Description
Simple Template Renderer for Capcat Replaces variables with actual values from configuration.
Classes
TemplateRenderer
Simple template renderer that replaces variables. Much more reliable than complex logic-based HTML generation.
Methods
init
def __init__(self)
Parameters:
self
_resolve_user_themes_dir
def _resolve_user_themes_dir(self) -> 'Path | None'
Return Config/themes/ if it exists in the project root, else None.
Parameters:
self
| Returns: ‘Path | None’ |
render_template
def render_template(self, template_name: str, context: Dict[str, Any], html_output_path: str = None, html_subfolder: bool = False) -> str
Render a template with the given context variables.
Args: template_name: Name of template file (e.g., “article-with-comments.html”) context: Dictionary of variables to substitute in template
Returns: Rendered HTML content
Parameters:
selftemplate_name(str)context(Dict[str, Any])html_output_path(str) optionalhtml_subfolder(bool) optional
Returns: str
_substitute_variables
def _substitute_variables(self, content: str, context: Dict[str, Any]) -> str
Replace placeholders with actual values.
Args: content: Template content with variables context: Dictionary of variable name -> value mappings
Returns: Content with variables substituted
Parameters:
selfcontent(str)context(Dict[str, Any])
Returns: str
_get_embedded_assets
def _get_embedded_assets(self) -> Dict[str, str]
Read and embed CSS and JavaScript assets into the template context.
Returns: Dictionary containing embedded styles and scripts
Parameters:
self
Returns: Dict[str, str]
_generate_error_template
def _generate_error_template(self, error_message: str) -> str
Generate minimal error page when template rendering fails.
Parameters:
selferror_message(str)
Returns: str
Functions
replace_variable
def replace_variable(match)
Parameters:
match