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 <section> tag. This also allows creating blocks in
Jinja iterators, which is not possible to do cleanly in the idiom being
replaced here.
This commit is contained in:
Tim Van Baak 2021-09-20 20:11:40 -07:00
parent ffaf881707
commit a6399e7e22
12 changed files with 42 additions and 51 deletions

View File

@ -3,21 +3,22 @@
{% block header %}<h2>Amanuensis - Login</h2>{% endblock %} {% block header %}<h2>Amanuensis - Login</h2>{% endblock %}
{% block login_status_attr %}style="display:none"{% endblock %} {% block login_status_attr %}style="display:none"{% endblock %}
{% block main %} {% block main %}
<section>
<form action="" method="post" novalidate> <form action="" method="post" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<p>{{ form.username.label }}<br>{{ form.username(size=32) }} <p>{{ form.username.label }}<br>{{ form.username(size=32) }}
{% for error in form.username.errors %} {% for error in form.username.errors %}
<br><span style="color: #ff0000">{{ error }}</span> <br><span style="color: #ff0000">{{ error }}</span>
{% endfor %}</p> {% endfor %}</p>
<p>{{ form.password.label }}<br>{{ form.password(size=32) }} <p>{{ form.password.label }}<br>{{ form.password(size=32) }}
{% for error in form.password.errors %} {% for error in form.password.errors %}
<br><span style="color: #ff0000">{{ error }}</span> <br><span style="color: #ff0000">{{ error }}</span>
{% endfor %}</p> {% endfor %}</p>
<p>{{ form.remember }} {{ form.remember.label }}</p> <p>{{ form.remember }} {{ form.remember.label }}</p>
<p>{{ form.submit() }}</p> <p>{{ form.submit() }}</p>
</form> </form>
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<span style="color: #ff0000">{{ message }}</span><br> <span style="color: #ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -9,6 +9,7 @@
{% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %} {% set template_sidebar_rows = [self.sb_home(), self.sb_create()] %}
{% block main %} {% block main %}
<section>
<p>Users:</p> <p>Users:</p>
{% for user in userq.get_all(db) %} {% for user in userq.get_all(db) %}
{{ macros.dashboard_user_item(user) }} {{ macros.dashboard_user_item(user) }}
@ -17,5 +18,5 @@
{% for lexicon in lexiq.get_all(db) %} {% for lexicon in lexiq.get_all(db) %}
{{ macros.dashboard_lexicon_item(lexicon) }} {{ macros.dashboard_lexicon_item(lexicon) }}
{% endfor %} {% endfor %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -4,6 +4,13 @@
{% block header %}<h2>Amanuensis - Home</h2>{% endblock %} {% block header %}<h2>Amanuensis - Home</h2>{% endblock %}
{% block main %} {% block main %}
{% if current_user.is_site_admin %}
<section>
<a href="{{ url_for('home.admin') }}" style="display:block; text-align:center;">Admin dashboard</a>
</section>
{% endif %}
<section>
<h1>Welcome to Amanuensis!</h1> <h1>Welcome to Amanuensis!</h1>
<p>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.</p> <p>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.</p>
@ -37,13 +44,5 @@
{% else %} {% else %}
<p>No public games available.</p> <p>No public games available.</p>
{% endif %} {% endif %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}
{% if current_user.is_site_admin %}
{% block admin_dash %}
<a href="{{ url_for('home.admin') }}" style="display:block; text-align:center;">Admin dashboard</a>
{% endblock %}
{% set template_content_blocks = [self.admin_dash()] + template_content_blocks %}
{% endif %}

View File

@ -2,6 +2,7 @@
{% block title %}Edit {{ character.name }} | {{ lexicon_title }}{% endblock %} {% block title %}Edit {{ character.name }} | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
<form action="" method="post" novalidate> <form action="" method="post" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<p> <p>
@ -19,6 +20,5 @@
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -3,6 +3,7 @@
{% block title %}Character | {{ lexicon_title }}{% endblock %} {% block title %}Character | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
<h1>Characters</h1> <h1>Characters</h1>
{% set players = memq.get_players_in_lexicon(db, g.lexicon.id)|list %} {% set players = memq.get_players_in_lexicon(db, g.lexicon.id)|list %}
{% set characters = charq.get_in_lexicon(db, g.lexicon.id)|list %} {% set characters = charq.get_in_lexicon(db, g.lexicon.id)|list %}
@ -30,5 +31,5 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -2,17 +2,15 @@
{% block title %}{{ article.title }} | {{ lexicon_title }}{% endblock %} {% block title %}{{ article.title }} | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
<h1>{{ article.title }}</h1> <h1>{{ article.title }}</h1>
{{ article.html }} {{ article.html }}
</section>
{% endblock %} <section>
{% block citations %}
<p> <p>
{% for citation in article.cites %} {% for citation in article.cites %}
<a href="{{ citation|articlelink }}">{{ citation }}</a>{% if not loop.last %} / {% endif %} <a href="{{ citation|articlelink }}">{{ citation }}</a>{% if not loop.last %} / {% endif %}
@ -23,6 +21,5 @@
<a href="{{ citation|articlelink }}">{{ citation }}</a>{% if not loop.last %} / {% endif %} <a href="{{ citation|articlelink }}">{{ citation }}</a>{% if not loop.last %} / {% endif %}
{% endfor %} {% endfor %}
</p> </p>
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main(), self.citations()] %}

View File

@ -3,7 +3,7 @@
{% block title %}Index | {{ lexicon_title }}{% endblock %} {% block title %}Index | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
@ -20,6 +20,5 @@
</ul> </ul>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -2,7 +2,7 @@
{% block title %}Join | {{ g.lexicon.full_title }}{% endblock %} {% block title %}Join | {{ g.lexicon.full_title }}{% endblock %}
{% block main %} {% block main %}
<section>
<form id="lexicon-join" action="" method="post" novalidate> <form id="lexicon-join" action="" method="post" novalidate>
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
{% if g.lexicon.join_password %} {% if g.lexicon.join_password %}
@ -16,6 +16,5 @@
{% for message in get_flashed_messages() %} {% for message in get_flashed_messages() %}
<span style="color:#ff0000">{{ message }}</span><br> <span style="color:#ff0000">{{ message }}</span><br>
{% endfor %} {% endfor %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -3,8 +3,7 @@
{% block title %}Rules | {{ lexicon_title }}{% endblock %} {% block title %}Rules | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
Placeholder text Placeholder text
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -3,8 +3,7 @@
{% block title %}Session | {{ lexicon_title }}{% endblock %} {% block title %}Session | {{ lexicon_title }}{% endblock %}
{% block main %} {% block main %}
<section>
Placeholder text Placeholder text
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -19,6 +19,7 @@
{% endmacro %} {% endmacro %}
{% block main %} {% block main %}
<section>
{% if current_membership.is_editor %} {% if current_membership.is_editor %}
<ul class="unordered-tabs"> <ul class="unordered-tabs">
<li>{{ settings_page_link("player", "Player Settings") }}</li> <li>{{ settings_page_link("player", "Player Settings") }}</li>
@ -172,6 +173,5 @@
{% if page_name == "article" %} {% if page_name == "article" %}
<h3>Article Requirements</h3> <h3>Article Requirements</h3>
{% endif %} {% endif %}
</section>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.main()] %}

View File

@ -27,11 +27,7 @@
</header> </header>
{% block sidebar %}{% endblock %} {% block sidebar %}{% endblock %}
<article class="{% block content_class %}{% endblock %}"> <article class="{% block content_class %}{% endblock %}">
{% if not template_content_blocks %}{% set template_content_blocks = [] %}{% endif %} {% block main %}{% endblock %}
{% if not content_blocks %}{% set content_blocks = [] %}{% endif %}
{% for content_block in template_content_blocks + content_blocks -%}
<section>{{ content_block|safe }}</div>
{% endfor %}
</article> </article>
</main> </main>
</body> </body>