From 8876b673b95c47773164e0ad17d9d8682968f20b Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Mon, 29 Mar 2021 17:19:40 -0600 Subject: parse and compare versions --- templates/badge.svg.jinja | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'templates') diff --git a/templates/badge.svg.jinja b/templates/badge.svg.jinja index 64117b8..fe2da3f 100644 --- a/templates/badge.svg.jinja +++ b/templates/badge.svg.jinja @@ -1,12 +1,39 @@ +{%- set ROW_HEIGHT = 24 -%} +{%- set ROW_MARGIN = 2 -%} +{%- set FONT_SIZE_PERCENT = 75 -%} +{%- set FONT_SIZE = (ROW_HEIGHT - ROW_MARGIN) * FONT_SIZE_PERCENT / 100 -%} +{%- set ROWS = 1 + versions|length + (versions.items()|map('length')|sum) -%} +{%- set OUTER_MARGIN = 5 -%} +{%- set REPO_LEFT_MARGIN = 15 -%} +{%- set FONT_WIDENESS = 0.5 -%} +{# ugh. just ugh. #} +{%- set ns = namespace(longest_repo = 0, longest_version = 0) -%} +{%- for family_contents in versions.values() -%} + {%- set this_longest_repo = family_contents.keys()|map('length')|max -%} + {%- set this_longest_version = family_contents.values()|map('string')|map('length')|max -%} + {%- set ns.longest_repo = [ns.longest_repo, this_longest_repo]|max -%} + {%- set ns.longest_version = [ns.longest_version, this_longest_version]|max -%} +{%- endfor -%} +{%- set VERSION_X = OUTER_MARGIN + REPO_LEFT_MARGIN + ns.longest_repo * FONT_WIDENESS * FONT_SIZE -%} +{%- set VERSION_WIDTH = OUTER_MARGIN + ns.longest_version * FONT_WIDENESS * FONT_SIZE -%} +{%- set WIDTH = VERSION_X + VERSION_WIDTH -%} +{%- set ns = namespace(y = 0) -%} +{%- macro y(offset=0) -%}{{ ns.y + offset }}{%- endmacro -%} +{%- macro texty() -%}{{ y(FONT_SIZE) }}{%- endmacro -%} +{%- macro end_row() -%}{%- set ns.y = ns.y + ROW_HEIGHT %}{%- endmacro -%} - - {% set ns = namespace(y = 20) %} - Packaging Status + + + Packaging Status + {{ end_row() }} {% for family, family_contents in versions.items() %} - {{ family }} + {{ family }}{{ end_row() }} {% for repo, version in family_contents.items() %} - {{ repo }} - {{ version }} + {{ repo }} + + {{ version }}{{ end_row() }} {% endfor %} {% endfor %} -- cgit v1.2.3