don't hardcode styles to present, use config

now that we can override the styles in practice, we also need to only
present what is possible in the HTML
This commit is contained in:
Brian S. Stephan 2022-12-31 09:53:22 -06:00
parent fd0fb390ff
commit 4a2f650a33
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
3 changed files with 33 additions and 3 deletions

View File

@ -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:

View File

@ -20,9 +20,9 @@
{% endfor %}
</div>
<div class="styles">
<a href="?style=dark">[dark]</a>
<a href="?style=light">[light]</a>
<a href="?style=plain">[plain]</a>
{% for style in page_styles %}
<a href="?style={{ style }}">[{{ style }}]</a>
{% endfor %}
</div>
</div>
{% endblock %}

View File

@ -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')