Skip to content

orders_of_magnitude.render_site

Render site HTML and CSS from datasets and templates.

PACKAGE_ROOT module-attribute

PACKAGE_ROOT = parent

HTML_TEMPLATE_ROOT module-attribute

HTML_TEMPLATE_ROOT = PACKAGE_ROOT / 'templates'

HTML_TEMPLATE_PATH module-attribute

HTML_TEMPLATE_PATH = HTML_TEMPLATE_ROOT / 'index.html'

CSS_TEMPLATE_PATH module-attribute

CSS_TEMPLATE_PATH = HTML_TEMPLATE_ROOT / 'index.css'

DEFAULT_HTML_FILENAME module-attribute

DEFAULT_HTML_FILENAME = 'orders-of-magnitude.html'

DEFAULT_CSS_FILENAME module-attribute

DEFAULT_CSS_FILENAME = 'orders-of-magnitude.css'

TABLES_PLACEHOLDER module-attribute

TABLES_PLACEHOLDER = '{{ tables }}'

CSS_HREF_PLACEHOLDER module-attribute

CSS_HREF_PLACEHOLDER = '{{ css_href }}'

HTML_PRINT_WIDTH module-attribute

HTML_PRINT_WIDTH = 80

TABLE_HEADERS module-attribute

TABLE_HEADERS: tuple[str, ...] = ('Order of magnitude', 'Name', 'Value', 'Fields', 'Source')

LOGGER module-attribute

LOGGER = getLogger(__name__)

render_site

render_site(html_output_path: Path, css_output_path: Path) -> None

Render site HTML and CSS files to the provided output paths.

Source code in src/orders_of_magnitude/render_site.py
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
def render_site(html_output_path: Path, css_output_path: Path) -> None:
    """Render site HTML and CSS files to the provided output paths."""
    html_action = _write_action(html_output_path)
    css_action = _write_action(css_output_path)
    stylesheet_href = _compute_stylesheet_href(html_output_path, css_output_path)
    loaded_datasets = datasets.load_datasets()
    html_template = HTML_TEMPLATE_PATH.read_text(encoding="utf-8")
    css_template = CSS_TEMPLATE_PATH.read_text(encoding="utf-8")

    html_output_path.write_text(
        _render_html_page(html_template, loaded_datasets, stylesheet_href),
        encoding="utf-8",
    )
    css_output_path.write_text(css_template, encoding="utf-8")
    LOGGER.info("%s HTML file: %s", html_action.capitalize(), html_output_path)
    LOGGER.info("%s CSS file: %s", css_action.capitalize(), css_output_path)

main

main(argv: list[str] | None = None) -> None

CLI entry point for rendering the site assets.

Source code in src/orders_of_magnitude/render_site.py
262
263
264
265
266
def main(argv: list[str] | None = None) -> None:
    """CLI entry point for rendering the site assets."""
    logging.basicConfig(level=logging.INFO, format="%(message)s")
    html_output_path, css_output_path = _parse_cli_args(argv)
    render_site(html_output_path, css_output_path)