From a6399e7e229e6d1c4823f5bb1670985b4b14975b Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Mon, 20 Sep 2021 20:11:40 -0700 Subject: [PATCH] Refactor template content blocks for greater flexibility There is not much value to be gotten out of creating Jinja blocks and appending them to a list when nothing particularly interesting is done with the list. With changes to move more towards semantic HTML, as well as more ease of access to data in the template engine in the new code, it is preferable to leave block division to the page template by making it a property of the
tag. This also allows creating blocks in Jinja iterators, which is not possible to do cleanly in the idiom being replaced here. --- amanuensis/server/auth/auth.login.jinja | 25 ++++++++++--------- amanuensis/server/home/home.admin.jinja | 3 ++- amanuensis/server/home/home.root.jinja | 17 ++++++------- .../lexicon/characters/characters.edit.jinja | 4 +-- .../lexicon/characters/characters.jinja | 3 ++- .../server/lexicon/lexicon.article.jinja | 11 +++----- .../server/lexicon/lexicon.contents.jinja | 5 ++-- amanuensis/server/lexicon/lexicon.join.jinja | 5 ++-- amanuensis/server/lexicon/lexicon.rules.jinja | 5 ++-- .../server/lexicon/lexicon.statistics.jinja | 5 ++-- .../server/lexicon/settings/settings.jinja | 4 +-- amanuensis/server/page.jinja | 6 +---- 12 files changed, 42 insertions(+), 51 deletions(-) diff --git a/amanuensis/server/auth/auth.login.jinja b/amanuensis/server/auth/auth.login.jinja index f6b6ae2..a06dce7 100644 --- a/amanuensis/server/auth/auth.login.jinja +++ b/amanuensis/server/auth/auth.login.jinja @@ -3,21 +3,22 @@ {% block header %}

Amanuensis - Login

{% endblock %} {% block login_status_attr %}style="display:none"{% endblock %} {% block main %} +
- {{ form.hidden_tag() }} -

{{ form.username.label }}
{{ form.username(size=32) }} - {% for error in form.username.errors %} -
{{ error }} - {% endfor %}

-

{{ form.password.label }}
{{ form.password(size=32) }} - {% for error in form.password.errors %} -
{{ error }} - {% endfor %}

-

{{ form.remember }} {{ form.remember.label }}

-

{{ form.submit() }}

+ {{ form.hidden_tag() }} +

{{ form.username.label }}
{{ form.username(size=32) }} + {% for error in form.username.errors %} +
{{ error }} + {% endfor %}

+

{{ form.password.label }}
{{ form.password(size=32) }} + {% for error in form.password.errors %} +
{{ error }} + {% endfor %}

+

{{ form.remember }} {{ form.remember.label }}

+

{{ form.submit() }}

{% for message in get_flashed_messages() %} {{ message }}
{% endfor %} +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/home/home.admin.jinja b/amanuensis/server/home/home.admin.jinja index 20ff0f2..ad85b95 100644 --- a/amanuensis/server/home/home.admin.jinja +++ b/amanuensis/server/home/home.admin.jinja @@ -9,6 +9,7 @@ {% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %} {% block main %} +

Users:

{% for user in userq.get_all(db) %} {{ macros.dashboard_user_item(user) }} @@ -17,5 +18,5 @@ {% for lexicon in lexiq.get_all(db) %} {{ macros.dashboard_lexicon_item(lexicon) }} {% endfor %} +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/home/home.root.jinja b/amanuensis/server/home/home.root.jinja index 83d7f29..5aad068 100644 --- a/amanuensis/server/home/home.root.jinja +++ b/amanuensis/server/home/home.root.jinja @@ -4,6 +4,13 @@ {% block header %}

Amanuensis - Home

{% endblock %} {% block main %} +{% if current_user.is_site_admin %} +
+Admin dashboard +
+{% endif %} + +

Welcome to Amanuensis!

Amanuensis is a hub for playing Lexicon, the encyclopedia RPG. Log in to access your Lexicon games. If you do not have an account, contact the administrator.

@@ -37,13 +44,5 @@ {% else %}

No public games available.

{% endif %} - +
{% endblock %} -{% set template_content_blocks = [self.main()] %} - -{% if current_user.is_site_admin %} -{% block admin_dash %} -Admin dashboard -{% endblock %} -{% set template_content_blocks = [self.admin_dash()] + template_content_blocks %} -{% endif %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/characters/characters.edit.jinja b/amanuensis/server/lexicon/characters/characters.edit.jinja index b9693d7..aaceb44 100644 --- a/amanuensis/server/lexicon/characters/characters.edit.jinja +++ b/amanuensis/server/lexicon/characters/characters.edit.jinja @@ -2,6 +2,7 @@ {% block title %}Edit {{ character.name }} | {{ lexicon_title }}{% endblock %} {% block main %} +
{{ form.hidden_tag() }}

@@ -19,6 +20,5 @@ {% for message in get_flashed_messages() %} {{ message }}
{% endfor %} - +

{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/characters/characters.jinja b/amanuensis/server/lexicon/characters/characters.jinja index 278324e..bb50ad5 100644 --- a/amanuensis/server/lexicon/characters/characters.jinja +++ b/amanuensis/server/lexicon/characters/characters.jinja @@ -3,6 +3,7 @@ {% block title %}Character | {{ lexicon_title }}{% endblock %} {% block main %} +

Characters

{% set players = memq.get_players_in_lexicon(db, g.lexicon.id)|list %} {% set characters = charq.get_in_lexicon(db, g.lexicon.id)|list %} @@ -30,5 +31,5 @@ {% endfor %} +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/lexicon.article.jinja b/amanuensis/server/lexicon/lexicon.article.jinja index 9fc42d7..5e38840 100644 --- a/amanuensis/server/lexicon/lexicon.article.jinja +++ b/amanuensis/server/lexicon/lexicon.article.jinja @@ -2,17 +2,15 @@ {% block title %}{{ article.title }} | {{ lexicon_title }}{% endblock %} {% block main %} - +
{% for message in get_flashed_messages() %} {{ message }}
{% endfor %}

{{ article.title }}

{{ article.html }} - -{% endblock %} - -{% block citations %} +
+

{% for citation in article.cites %} {{ citation }}{% if not loop.last %} / {% endif %} @@ -23,6 +21,5 @@ {{ citation }}{% if not loop.last %} / {% endif %} {% endfor %}

+
{% endblock %} - -{% set template_content_blocks = [self.main(), self.citations()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/lexicon.contents.jinja b/amanuensis/server/lexicon/lexicon.contents.jinja index a61e87c..1415449 100644 --- a/amanuensis/server/lexicon/lexicon.contents.jinja +++ b/amanuensis/server/lexicon/lexicon.contents.jinja @@ -3,7 +3,7 @@ {% block title %}Index | {{ lexicon_title }}{% endblock %} {% block main %} - +
{% for message in get_flashed_messages() %} {{ message }}
{% endfor %} @@ -20,6 +20,5 @@ {% endif %} {% endfor %} - +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/lexicon.join.jinja b/amanuensis/server/lexicon/lexicon.join.jinja index cdd9b24..cf009fd 100644 --- a/amanuensis/server/lexicon/lexicon.join.jinja +++ b/amanuensis/server/lexicon/lexicon.join.jinja @@ -2,7 +2,7 @@ {% block title %}Join | {{ g.lexicon.full_title }}{% endblock %} {% block main %} - +
{{ form.hidden_tag() }} {% if g.lexicon.join_password %} @@ -16,6 +16,5 @@ {% for message in get_flashed_messages() %} {{ message }}
{% endfor %} - +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/lexicon.rules.jinja b/amanuensis/server/lexicon/lexicon.rules.jinja index 20fc070..932ad98 100644 --- a/amanuensis/server/lexicon/lexicon.rules.jinja +++ b/amanuensis/server/lexicon/lexicon.rules.jinja @@ -3,8 +3,7 @@ {% block title %}Rules | {{ lexicon_title }}{% endblock %} {% block main %} - +
Placeholder text - +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/lexicon.statistics.jinja b/amanuensis/server/lexicon/lexicon.statistics.jinja index e816653..3d3f6f5 100644 --- a/amanuensis/server/lexicon/lexicon.statistics.jinja +++ b/amanuensis/server/lexicon/lexicon.statistics.jinja @@ -3,8 +3,7 @@ {% block title %}Session | {{ lexicon_title }}{% endblock %} {% block main %} - +
Placeholder text - +
{% endblock %} -{% set template_content_blocks = [self.main()] %} \ No newline at end of file diff --git a/amanuensis/server/lexicon/settings/settings.jinja b/amanuensis/server/lexicon/settings/settings.jinja index d143b98..bd1a52a 100644 --- a/amanuensis/server/lexicon/settings/settings.jinja +++ b/amanuensis/server/lexicon/settings/settings.jinja @@ -19,6 +19,7 @@ {% endmacro %} {% block main %} +
{% if current_membership.is_editor %}
  • {{ settings_page_link("player", "Player Settings") }}
  • @@ -172,6 +173,5 @@ {% if page_name == "article" %}

    Article Requirements

    {% endif %} +
{% endblock %} - -{% set template_content_blocks = [self.main()] %} diff --git a/amanuensis/server/page.jinja b/amanuensis/server/page.jinja index df4832e..02f7740 100644 --- a/amanuensis/server/page.jinja +++ b/amanuensis/server/page.jinja @@ -27,11 +27,7 @@ {% block sidebar %}{% endblock %}
- {% if not template_content_blocks %}{% set template_content_blocks = [] %}{% endif %} - {% if not content_blocks %}{% set content_blocks = [] %}{% endif %} - {% for content_block in template_content_blocks + content_blocks -%} -
{{ content_block|safe }} - {% endfor %} + {% block main %}{% endblock %}