diff --git a/incorporealcms/lib.py b/incorporealcms/lib.py index 6bf8cd8..3c47cd4 100644 --- a/incorporealcms/lib.py +++ b/incorporealcms/lib.py @@ -39,6 +39,7 @@ def render(template_name_or_list, **context): user_style = request.cookies.get('user-style') logger.debug("user style cookie: %s", user_style) context['user_style'] = page_styles.get(user_style, page_styles.get(app.config['DEFAULT_PAGE_STYLE'])) + context['page_styles'] = page_styles resp = make_response(render_template(template_name_or_list, **context)) if selected_style: diff --git a/incorporealcms/templates/base.html b/incorporealcms/templates/base.html index ef72497..6ba53ba 100644 --- a/incorporealcms/templates/base.html +++ b/incorporealcms/templates/base.html @@ -20,9 +20,9 @@ {% endfor %}
- [dark] - [light] - [plain] + {% for style in page_styles %} + [{{ style }}] + {% endfor %}
{% endblock %} diff --git a/tests/test_pages.py b/tests/test_pages.py index 9a1b0e6..6ce09e9 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -72,6 +72,35 @@ def test_render_with_no_user_theme(app): assert b'/static/css/dark.css' not in render('base.html').data +def test_render_with_theme_defaults_affects_html(app): + """Test that the base themes are all that's presented in the HTML.""" + # test we can remove stuff from the default + with app.test_request_context(): + assert b'?style=light' in render('base.html').data + assert b'?style=dark' in render('base.html').data + assert b'?style=plain' in render('base.html').data + + +def test_render_with_theme_overrides_affects_html(app): + """Test that the overridden themes are presented in the HTML.""" + # test we can remove stuff from the default + restyled_app = create_app(instance_path=os.path.join(HERE, 'instance'), + test_config={'PAGE_STYLES': {'light': 'css/light.css'}}) + with restyled_app.test_request_context(): + assert b'?style=light' in render('base.html').data + assert b'?style=dark' not in render('base.html').data + assert b'?style=plain' not in render('base.html').data + + # test that we can add new stuff too/instead + restyled_app = create_app(instance_path=os.path.join(HERE, 'instance'), + test_config={'PAGE_STYLES': {'cool': 'css/cool.css', + 'warm': 'css/warm.css'}, + 'DEFAULT_PAGE_STYLE': 'warm'}) + with restyled_app.test_request_context(): + assert b'?style=cool' in render('base.html').data + assert b'?style=warm' in render('base.html').data + + def test_render_with_theme_overrides(app): """Test that the loaded themes can be overridden from the default.""" cookie = dump_cookie("user-style", 'cool')