Skip to content

templates

tit.reporting.core.templates

CSS and JavaScript templates for TI-Toolbox reports.

This module contains the default styling and interactivity for generated reports.

get_html_template

get_html_template(title: str, content: str, toc_html: str = '', metadata_html: str = '', footer_html: str = '', custom_css: str = '', custom_js: str = '') -> str

Generate a complete HTML document with the report content.

Parameters:

Name Type Description Default
title str

The report title

required
content str

The main HTML content

required
toc_html str

Table of contents HTML

''
metadata_html str

Header metadata HTML

''
footer_html str

Footer HTML

''
custom_css str

Additional CSS styles

''
custom_js str

Additional JavaScript

''

Returns:

Type Description
str

Complete HTML document as a string

Source code in tit/reporting/core/templates.py
def get_html_template(
    title: str,
    content: str,
    toc_html: str = "",
    metadata_html: str = "",
    footer_html: str = "",
    custom_css: str = "",
    custom_js: str = "",
) -> str:
    """
    Generate a complete HTML document with the report content.

    Args:
        title: The report title
        content: The main HTML content
        toc_html: Table of contents HTML
        metadata_html: Header metadata HTML
        footer_html: Footer HTML
        custom_css: Additional CSS styles
        custom_js: Additional JavaScript

    Returns:
        Complete HTML document as a string
    """
    css = DEFAULT_CSS_STYLES
    if custom_css:
        css += f"\n/* Custom Styles */\n{custom_css}"

    js = DEFAULT_JS_SCRIPTS
    if custom_js:
        js += f"\n// Custom Scripts\n{custom_js}"

    nav_html = ""
    if toc_html:
        nav_html = f"""
        <nav class="report-nav">
            <h2>Contents</h2>
            {toc_html}
        </nav>
        """

    footer = footer_html or """
        <footer class="report-footer">
            <p>Generated by <a href="https://github.com/idossha/TI-toolbox" target="_blank">TI-Toolbox</a></p>
        </footer>
    """

    return f"""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{title}</title>
    <style>
{css}
    </style>
</head>
<body>
    <div class="report-container">
        <header class="report-header">
            <h1>{title}</h1>
            {metadata_html}
        </header>

        {nav_html}

        <main class="report-main">
            {content}
        </main>

        {footer}
    </div>

    <script>
{js}
    </script>
</body>
</html>
"""