templates: Fix improper plurals, create helpers.

Previously, the three instances of 'Report[s]' and one instance of
'Coin[s]' in the UI templates were always pluralized, even when they
referred to a singular instance. This has been corrected by creating
a `plural` helper macro.

Additionally, this was used as impetus to create `utils/helpers.html`
to eventually move more recurring template logic into macros.
remotes/1693045480750635534/spooky-22
Snakes 2022-06-07 05:26:22 -04:00
parent f966262b97
commit cb5f9d05c6
15 changed files with 21 additions and 4 deletions

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
{% if not ajax %}
{% if comment_info and not request.full_path.endswith('#context') %}
<script>
@ -184,7 +185,7 @@
{% if c.bannedfor %}
<a role="button"><i class="fas fa-hammer-crash text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="User was banned for this comment{% if c.author.banned_by %} by @{{c.author.banned_by.username}}{% endif %}"></i></a>
{% endif %}
{% if c.active_flags(v) %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px"role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags(v)}} Reports</a>{% endif %}
{% if c.active_flags(v) %}<a class="btn btn-primary" style="padding:1px 5px; font-size:10px"role="button" onclick="document.getElementById('flaggers-{{c.id}}').classList.toggle('d-none')">{{c.active_flags(v)}} Report{{ help.plural(c.active_flags(v)) }}</a>{% endif %}
{% if c.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if v and v.admin_level > 1 and c.author.shadowbanned %}<i class="fas fa-user-times text-admin" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Shadowbanned by @{{c.author.shadowbanned}}"></i>{% endif %}
{% if c.stickied %}

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -161,7 +161,7 @@
<div><img alt="your profile picture" loading="lazy" src="{{v.profile_url}}" class="profile-pic-35"></div>
<div class="text-left pl-2">
<div style="color: #{{v.namecolor}}" class="text-small font-weight-bold {% if v.patron %}patron{% endif %}"><span {% if v.patron %}class="patron" style="background-color:#{{v.namecolor}}"{% endif %}>{{v.username}}</span></div>
<div class="text-small-extra"><img alt="coins" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" src="/assets/images/{{SITE_NAME}}/coins.webp?v=2" title="coins" aria-label="coins"><span id="user-coins-amount">{{v.coins}}</span> Coins</div>
<div class="text-small-extra"><img alt="coins" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" src="/assets/images/{{SITE_NAME}}/coins.webp?v=2" title="coins" aria-label="coins"><span id="user-coins-amount">{{v.coins}}</span> Coin{{ help.plural(v.coins) }}</div>
{% if SITE_NAME not in ('Cringetopia', 'WPD') %}
<div class="text-small-extra"><img alt="marseybux" class="mr-1 ml-1" data-bs-toggle="tooltip" data-bs-placement="bottom" height="13" width="30" src="/assets/images/marseybux.webp?v=1008" title="Marseybux" aria-label="Marseybux"><span id="user-bux-amount">{{v.procoins}}</span> Marseybux</div>
{% endif %}

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">

View File

@ -695,7 +695,7 @@
{% if p.is_bot %} <i class="fas fa-robot text-info" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Bot"></i>{% endif %}
{% if p.over_18 %}<span class="badge badge-danger text-small-extra mr-1">+18</span>{% endif %}
{% if p.private %}<span class="badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers').classList.toggle('d-none')">{{p.active_flags(v)}} Reports</a>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers').classList.toggle('d-none')">{{p.active_flags(v)}} Report{{ help.plural(p.active_flags(v)) }}</a>{% endif %}
{% if not p.author %}
{{p.print()}}

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
{% if v %}
{% include "award_modal.html" %}
@ -173,7 +174,7 @@
{% if p.is_blocking %}<i class="fas fa-user-minus text-warning" data-bs-toggle="tooltip" data-bs-placement="bottom" title="You're blocking this user, but you can see this post because you're an admin."></i>{% endif %}
{% if p.is_blocked %}<i class="fas fa-user-minus text-danger" data-bs-toggle="tooltip" data-bs-placement="bottom" title="This user is blocking you."></i>{% endif %}
{% if p.private %}<span class="badge border-warning border-1 text-small-extra">Draft</span>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers-{{p.id}}').classList.toggle('d-none')">{{p.active_flags(v)}} Reports</a>{% endif %}
{% if p.active_flags(v) %}<a class="btn btn-primary" role="button" style="padding:1px 5px; font-size:10px"onclick="document.getElementById('flaggers-{{p.id}}').classList.toggle('d-none')">{{p.active_flags(v)}} Report{{ help.plural(p.active_flags(v)) }}</a>{% endif %}
{% if not p.author %}
{{p.print()}}

View File

@ -1,4 +1,5 @@
{%- from 'util/assetcache.html' import asset -%}
{%- import 'util/helpers.html' as help -%}
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -0,0 +1,5 @@
{%- macro plural(value, suffix='s') -%}
{%- if value > 1 or value < -1 -%}
{{ suffix }}
{%- endif -%}
{%- endmacro -%}