|
1 |
| -{% if render_title %} |
2 |
| -{% if versiondata.name %} |
3 |
| -{{header_prefix}} {{ versiondata.name }} {{ versiondata.version }} ({{ versiondata.date }}) |
4 |
| -{% else %} |
5 |
| -{{header_prefix}} {{ versiondata.version }} ({{ versiondata.date }}) |
6 |
| -{% endif %} |
7 |
| -{% endif %} |
8 |
| -{% for section, _ in sections.items() %} |
9 |
| -{% if section %} |
10 |
| - |
11 |
| -{{header_prefix}}# {{section}} |
12 |
| -{% endif %} |
13 |
| - |
14 |
| -{% if sections[section] %} |
15 |
| -{% for category, val in definitions.items() if category in sections[section] %} |
16 |
| -{{header_prefix}}#{% if section %}#{% endif %} {{ definitions[category]['name'] }} |
17 |
| - |
18 |
| -{% for text, values in sections[section][category].items() %} |
19 |
| -- {{ text }} |
20 |
| -{%- if values %} |
21 |
| -{% if "\n - " in text or '\n * ' in text %} |
22 |
| - |
23 |
| - |
24 |
| - ( |
25 |
| -{%- else %} |
26 |
| -{% if text %} ({% endif %} |
27 |
| -{%- endif -%} |
28 |
| -{%- for issue in values %} |
29 |
| -{{ issue.split(": ", 1)[0] }}{% if not loop.last %}, {% endif %} |
30 |
| -{%- endfor %} |
31 |
| -{% if text %}){% endif %} |
| 1 | +{#- |
| 2 | +══════════════════════════════════════════════════════════════════════════════ |
| 3 | +TOWNCRIER MARKDOWN TEMPLATE |
| 4 | +══════════════════════════════════════════════════════════════════════════════ |
| 5 | + |
| 6 | +─── Macro: heading ───────────────────────────────────────────────────────── |
| 7 | +Purpose: |
| 8 | + Generates Markdown headings with the appropriate number of # characters. |
| 9 | + Based on header_prefix (default: "#") and the level argument. |
| 10 | + |
| 11 | +Arguments: |
| 12 | + level The relative heading level (1=#, 2=##, 3=###, etc.) |
| 13 | +-#} |
| 14 | +{%- macro heading(level) -%} |
| 15 | + {{- "#" * ( header_prefix | length + level -1 ) }} |
| 16 | +{%- endmacro -%} |
| 17 | + |
| 18 | +{#- |
| 19 | +─── Variable: newline ────────────────────────────────────────────────────── |
| 20 | +Purpose: |
| 21 | + Consistent newline handling. -#} |
| 22 | +{%- set newline = "\n" -%} |
| 23 | + |
| 24 | +{#- ════════════════════════ TEMPLATE GENERATION ════════════════════════ -#} |
| 25 | +{#- ─── TITLE HEADING ─── #} |
| 26 | +{#- render_title is false when title_format is specified in the config #} |
| 27 | +{%- if render_title %} |
| 28 | + {%- if versiondata.name %} |
| 29 | + {{- heading(1) ~ " " ~ versiondata.name ~ " " ~ versiondata.version ~ " (" ~ versiondata.date ~ ")" ~ newline }} |
| 30 | + {%- else %} |
| 31 | + {{- heading(1) ~ " " ~ versiondata.version ~ " (" ~ versiondata.date ~ ")" ~ newline }} |
| 32 | + {%- endif %} |
| 33 | +{%- endif %} |
| 34 | +{#- If title_format is specified, we start with a new line #} |
| 35 | +{{- newline }} |
| 36 | + |
| 37 | +{%- for section, _ in sections.items() %} |
| 38 | + {#- ─── SECTION HEADING ─── #} |
| 39 | + {%- if section %} |
| 40 | + {{- newline }} |
| 41 | + {{- heading(2) ~ " " ~ section ~ newline }} |
| 42 | + {{- newline }} |
| 43 | + {%- endif %} |
32 | 44 |
|
33 |
| -{% else %} |
| 45 | + {%- if sections[section] %} |
34 | 46 |
|
35 |
| -{% endif %} |
36 |
| -{% endfor %} |
| 47 | + {%- for category, val in definitions.items() if category in sections[section] %} |
| 48 | + {%- set issue_pks = [] %} |
| 49 | + {#- ─── CATEGORY HEADING ─── #} |
| 50 | + {#- Increase heading level if section is not present #} |
| 51 | + {{- heading(3 if section else 2) ~" " ~ definitions[category]['name'] ~ newline }} |
| 52 | + {{- newline }} |
37 | 53 |
|
38 |
| -{% if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %} |
39 |
| -{% for issue in issues_by_category[section][category] %} |
40 |
| -{{ issue }} |
41 |
| -{% endfor %} |
| 54 | + {#- ─── RENDER ENTRIES ─── #} |
| 55 | + {%- for text, values in sections[section][category].items() %} |
| 56 | + {#- Prepare the string of issue numbers (e.g., "#1, #9, #142") #} |
| 57 | + {%- set issue_pks = [] %} |
| 58 | + {%- for v_issue in values %} |
| 59 | + {%- set _= issue_pks.append(v_issue.split(": ", 1)[0]) %} |
| 60 | + {%- endfor %} |
| 61 | + {%- set issues_list = issue_pks | join(", ") %} |
42 | 62 |
|
43 |
| -{% endif %} |
44 |
| -{% if sections[section][category]|length == 0 %} |
45 |
| -No significant changes. |
| 63 | + {#- Check if text contains a sublist #} |
| 64 | + {%- set text_has_sublist = (("\n - " in text) or ("\n * " in text)) %} |
46 | 65 |
|
47 |
| -{% else %} |
48 |
| -{% endif %} |
49 |
| -{% endfor %} |
50 |
| -{% else %} |
51 |
| -No significant changes. |
| 66 | + {#- CASE 1: No text, only issues #} |
| 67 | + {#- Output: - #1, #9, #142 #} |
| 68 | + {%- if not text and issues_list %} |
| 69 | + {{- "- " ~ issues_list ~ newline }} |
52 | 70 |
|
53 |
| -{% endif %} |
54 |
| -{% endfor +%} |
55 |
| -{# |
56 |
| -This comment adds one more newline at the end of the rendered newsfile content. |
| 71 | + {#- Cases where both text and issues exist #} |
| 72 | + {%- elif text and issues_list %} |
| 73 | + {%- if text_has_sublist %} |
| 74 | + {#- CASE 3: Text with sublist #} |
| 75 | + {#- Output: - TEXT\n\n (#1, #9, #142) #} |
| 76 | + {{- "- " ~ text ~ newline ~ newline ~ " (" ~ issues_list ~ ")" ~ newline }} |
| 77 | + {%- else %} |
| 78 | + {#- CASE 2: Text, no sublist #} |
| 79 | + {#- Output: - TEXT (#1, #9, #142) #} |
| 80 | + {{- "- " ~ text ~ " (" ~ issues_list ~ ")" ~ newline }} |
| 81 | + {%- endif %} |
| 82 | + |
| 83 | + {%- elif text %} |
| 84 | + {#- Implicit Case: Text, but no issues #} |
| 85 | + {#- Output: - TEXT #} |
| 86 | + {{- "- " ~ text ~ newline }} |
| 87 | + {%- endif %} |
| 88 | + {%- endfor %} |
| 89 | + |
| 90 | + {#- New line between list and link references #} |
| 91 | + {{- newline }} |
| 92 | + |
| 93 | + {#- Link references #} |
| 94 | + {%- if issues_by_category[section][category] and "]: " in issues_by_category[section][category][0] %} |
| 95 | + {%- for issue in issues_by_category[section][category] %} |
| 96 | + {{- issue ~ newline }} |
| 97 | + {%- endfor %} |
| 98 | + {{- newline }} |
| 99 | + {%- endif %} |
| 100 | + |
| 101 | + {#- No changes in this category #} |
| 102 | + {%- if sections[section][category]|length == 0 %} |
| 103 | + {{- newline }} |
| 104 | + {{- "No significant changes." ~ newline * 2 }} |
| 105 | + {%- endif %} |
| 106 | + {%- endfor %} |
| 107 | + {%- else %} |
| 108 | + {#- No changes in this section #} |
| 109 | + {{- "No significant changes." ~ newline * 2 }} |
| 110 | + {%- endif %} |
| 111 | +{%- endfor %} |
| 112 | +{#- |
| 113 | +Newline at the end of the rendered newsfile content. |
57 | 114 | In this way the there are 2 newlines between the latest release and the previous release content.
|
58 |
| -#} |
| 115 | +-#} |
| 116 | +{{- newline -}} |
0 commit comments