-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
templates: Refine and simplify emoji count overview
- Loading branch information
Showing
5 changed files
with
66 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,45 @@ | ||
{# Overview template macros #} | ||
|
||
{% macro partial_emoji_overview(ns) %} | ||
|
||
# get the overview string for "❌", "✅", "❓". | ||
{%- for emoji in ["❌", "✅", "❓"] -%} | ||
{%- if emoji in varargs[0] %} | ||
{%- if emoji in varargs[1] %} | ||
# if "emoji" exists in each of the emoji count dictionaries, | ||
# generate a formatting string from the length of the longest | ||
# count between them. | ||
|
||
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%} | ||
{% if varargs[0][emoji] | length > varargs[1][emoji] | length %} | ||
{% set index = 0 %} | ||
{% else %} | ||
{% set index = 1 %} | ||
{% endif %} | ||
{% set ns.format_string = ns.format_string + "%s " + "%" + | ||
varargs[index][emoji] | length | string + "s " %} | ||
{% else %} | ||
# if "emoji" exists in the first but not latter of the | ||
# emoji count dictionaries, generate formatting string | ||
# from the length of first count. | ||
|
||
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) -%} | ||
{% set ns.format_string = ns.format_string + "%s " + "%" + | ||
varargs[0][emoji] | length | string + "s " %} | ||
{% endif %} | ||
|
||
{% else %} | ||
{%- if emoji in varargs[1] %} | ||
# if "emoji" exist in the latter but not first of the | ||
# emoji count dictionaries, insert "➖" instead. | ||
|
||
{% set _ = ns.elements.extend(["➖", ""]) %} | ||
{% set ns.format_string = ns.format_string + "%s " + "%" + | ||
varargs[1][emoji] | length | string + "s " %} | ||
{% endif %} | ||
|
||
{% endif -%} | ||
{% import "test.j2" as test_macros %} | ||
|
||
{%- macro emoji_counts() -%} | ||
{%- set ns = namespace( | ||
max_emojis={}, | ||
pieces=[], | ||
first=test_macros.WAIVED_STATUS_EMOJIS | length, | ||
last=-1 | ||
) -%} | ||
|
||
{# Find maximum emoji counts accross all arguments #} | ||
{%- for emoji in test_macros.WAIVED_STATUS_EMOJIS.values() -%} | ||
{%- set _ = ns.max_emojis.__setitem__( | ||
emoji, varargs | map(attribute=emoji) | max | ||
) -%} | ||
{%- endfor -%} | ||
{% endmacro %} | ||
|
||
{% macro emoji_overview() -%} | ||
{% set ns = namespace(elements=[], format_string='') %} | ||
{%- set _ = partial_emoji_overview(ns, varargs[0], varargs[1]) -%} | ||
|
||
{# generate formatting string for other emoji(s) in TESTS. #} | ||
{% for emoji in varargs[0] -%} | ||
{% if emoji not in ["❌", "✅", '❓'] %} | ||
{% set _ = ns.elements.extend([emoji, varargs[0][emoji]]) %} | ||
{% set ns.format_string = ns.format_string + "%" + | ||
emoji | length | string + "s %" + | ||
varargs[0][emoji] | length | string + "s " %} | ||
{% endif %} | ||
{# Build a list of "<emoji> <count>" pieces for all emojis #} | ||
{%- for emoji, count in varargs[0].items() -%} | ||
{%- if ns.max_emojis[emoji] > 0 -%} | ||
{# Remember the first non-zero emoji across all arguments #} | ||
{%- set ns.first = [ ns.first, loop.index0 ] | min -%} | ||
{# Add an "<emoji> <count>" piece #} | ||
{%- set _ = ns.pieces.extend([ | ||
( | ||
"%s %" + | ||
(ns.max_emojis[emoji] | string | length | string) + | ||
"s" | ||
) | | ||
format( | ||
"➖" if count == 0 else emoji, | ||
"" if count == 0 else (count | string) | ||
) | ||
]) -%} | ||
{# Remember the last non-zero emoji in this argument #} | ||
{%- if count > 0 -%} | ||
{%- set ns.last = loop.index0 -%} | ||
{%- endif -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
|
||
{{- ns.format_string | format(*ns.elements) -}} | ||
{# Output the pieces of interest #} | ||
{{- ns.pieces[ns.first:ns.last + 1] | join(" ") -}} | ||
{%- endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters