From 76b1800155d4116f77783ff4db7124534c004488 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 15 Mar 2025 14:01:02 -0500 Subject: [PATCH] static site generator part 6 --- start testing stuff Signed-off-by: Brian S. Stephan --- incorporealcms/__init__.py | 7 +- incorporealcms/config.py | 2 +- incorporealcms/markdown.py | 12 +- incorporealcms/templates/base.html | 8 +- tests/conftest.py | 26 --- tests/functional_tests.py | 244 ------------------------- tests/instance/config.json | 3 +- tests/test_factory.py | 78 +------- tests/test_markdown.py | 106 +++++++++++ tests/test_pages.py | 282 ----------------------------- 10 files changed, 130 insertions(+), 638 deletions(-) delete mode 100644 tests/conftest.py delete mode 100644 tests/functional_tests.py create mode 100644 tests/test_markdown.py delete mode 100644 tests/test_pages.py diff --git a/incorporealcms/__init__.py b/incorporealcms/__init__.py index 3aee430..5f1f90b 100644 --- a/incorporealcms/__init__.py +++ b/incorporealcms/__init__.py @@ -8,16 +8,10 @@ import logging import os from logging.config import dictConfig -from jinja2 import Environment, PackageLoader, select_autoescape from termcolor import cprint from incorporealcms.config import Config -env = Environment( - loader=PackageLoader('incorporealcms'), - autoescape=select_autoescape(), -) - def init_instance(instance_path: str, extra_config: dict = None): """Create the instance context, with allowances for customizing path and test settings.""" @@ -30,6 +24,7 @@ def init_instance(instance_path: str, extra_config: dict = None): Config.update(config_dict) if extra_config: + cprint(f"splicing {extra_config} into the config", 'yellow') Config.update(extra_config) # stash some stuff diff --git a/incorporealcms/config.py b/incorporealcms/config.py index 43a8efb..6bdba05 100644 --- a/incorporealcms/config.py +++ b/incorporealcms/config.py @@ -67,7 +67,7 @@ class Config(object): # feed settings AUTHOR = {'name': 'Test Name', 'email': 'admin@example.com'} - # specify FAVICON in your instance config.py to override the provided icon + FAVICON = '/static/img/favicon.png' @classmethod def update(cls, config: dict): diff --git a/incorporealcms/markdown.py b/incorporealcms/markdown.py index 9c9723f..176516b 100644 --- a/incorporealcms/markdown.py +++ b/incorporealcms/markdown.py @@ -9,13 +9,18 @@ import os import re import markdown +from jinja2 import Environment, PackageLoader, select_autoescape from markupsafe import Markup -from incorporealcms import env from incorporealcms.config import Config logger = logging.getLogger(__name__) +jinja_env = Environment( + loader=PackageLoader('incorporealcms'), + autoescape=select_autoescape(), +) + def get_meta_str(md, key): """Provide the page's (parsed in Markup obj md) metadata for the specified key, or '' if unset.""" @@ -96,15 +101,12 @@ def handle_markdown_file_path(path: str) -> str: if redirect_url: raise ValueError("redirects in markdown are unsupported!") - template = env.get_template(template_name) + template = jinja_env.get_template(template_name) return template.render(title=page_title, config=Config, description=get_meta_str(md, 'description'), image=get_meta_str(md, 'image'), content=content, - stylesheet=(Config.DEFAULT_PAGE_STYLE, - Config.PAGE_STYLES.get(Config.DEFAULT_PAGE_STYLE)), - page_styles=Config.PAGE_STYLES, base_url=Config.BASE_HOST + instance_resource_path_to_request_path(path), navs=parent_navs, mtime=mtime.strftime('%Y-%m-%d %H:%M:%S %Z'), diff --git a/incorporealcms/templates/base.html b/incorporealcms/templates/base.html index 5e3a761..ed44bc4 100644 --- a/incorporealcms/templates/base.html +++ b/incorporealcms/templates/base.html @@ -13,11 +13,11 @@ SPDX-License-Identifier: AGPL-3.0-or-later {% if image %}{% endif %} - -{% for style, stylesheet in page_styles.items() %} - + +{% for style, stylesheet in config.PAGE_STYLES.items() %} + {% endfor %} - +