Skip to content

Commit ec38e30

Browse files
committed
Ensured compatibility with minijinja (Rust)
1 parent e66107e commit ec38e30

16 files changed

+211
-181
lines changed

material/templates/base.html

+25-29
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
{% endblock %}
5959
{% block fonts %}
6060
{% if config.theme.font != false %}
61-
{% set text = config.theme.font.get("text", "Roboto") %}
62-
{% set code = config.theme.font.get("code", "Roboto Mono") %}
61+
{% set text = config.theme.font.text | d("Roboto", true) %}
62+
{% set code = config.theme.font.code | d("Roboto Mono", true) %}
6363
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
6464
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family={{
6565
text | replace(' ', '+') + ':300,300i,400,400i,700,700i%7C' +
@@ -214,38 +214,34 @@
214214
{% include "partials/javascripts/consent.html" %}
215215
{% endif %}
216216
{% block config %}
217-
{%- set app = {
218-
"base": base_url,
219-
"features": features,
220-
"translations": {},
221-
"search": "assets/javascripts/workers/search.f8cc74c7.min.js" | url
222-
} -%}
217+
{% set _ = namespace() %}
218+
{% set _.tags = config.extra.tags %}
223219
{%- if config.extra.version -%}
224-
{%- set mike = config.plugins.get("mike") -%}
220+
{%- set mike = config.plugins.mike -%}
225221
{%- if not mike or mike.config.version_selector -%}
226-
{%- set _ = app.update({ "version": config.extra.version }) -%}
222+
{%- set _.version = config.extra.version -%}
227223
{%- endif -%}
228224
{%- endif -%}
229-
{%- if config.extra.tags -%}
230-
{%- set _ = app.update({ "tags": config.extra.tags }) -%}
231-
{%- endif -%}
232-
{%- set translations = app.translations -%}
233-
{%- for key in [
234-
"clipboard.copy",
235-
"clipboard.copied",
236-
"search.result.placeholder",
237-
"search.result.none",
238-
"search.result.one",
239-
"search.result.other",
240-
"search.result.more.one",
241-
"search.result.more.other",
242-
"search.result.term.missing",
243-
"select.version"
244-
] -%}
245-
{%- set _ = translations.update({ key: lang.t(key) }) -%}
246-
{%- endfor -%}
247225
<script id="__config" type="application/json">
248-
{{- app | tojson -}}
226+
{{- {
227+
"base": base_url,
228+
"features": features,
229+
"translations": {
230+
"clipboard.copy": lang.t("clipboard.copy"),
231+
"clipboard.copied": lang.t("clipboard.copied"),
232+
"search.result.placeholder": lang.t("search.result.placeholder"),
233+
"search.result.none": lang.t("search.result.none"),
234+
"search.result.one": lang.t("search.result.one"),
235+
"search.result.other": lang.t("search.result.other"),
236+
"search.result.more.one": lang.t("search.result.more.one"),
237+
"search.result.more.other": lang.t("search.result.more.other"),
238+
"search.result.term.missing": lang.t("search.result.term.missing"),
239+
"select.version": lang.t("select.version")
240+
},
241+
"search": "assets/javascripts/workers/search.f8cc74c7.min.js" | url,
242+
"tags": _.tags or none,
243+
"version": _.version or none
244+
} | tojson -}}
249245
</script>
250246
{% endblock %}
251247
{% block scripts %}

material/templates/partials/consent.html

+31-26
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
{#-
22
This file was automatically generated - do not edit
33
-#}
4-
{% set cookies = config.extra.consent.cookies | d({}) %}
5-
{% if config.extra.analytics %}
6-
{% if "analytics" not in cookies %}
7-
{% set _ = cookies.update({ "analytics": "Google Analytics" }) %}
8-
{% endif %}
9-
{% endif %}
10-
{% if config.repo_url and "github.com" in config.repo_url %}
11-
{% if "github" not in cookies %}
12-
{% set _ = cookies.update({ "github": "GitHub" }) %}
4+
{% macro render_cookie(cookie, type) %}
5+
{% set checked = "" %}
6+
{% if cookie is string %}
7+
{% set name = cookie %}
8+
{% set checked = "checked" %}
9+
{% else %}
10+
{% set name = cookie.name %}
11+
{% if cookie.checked %}
12+
{% set checked = "checked" %}
13+
{% endif %}
1314
{% endif %}
14-
{% endif %}
15+
<li class="task-list-item">
16+
<label class="task-list-control">
17+
<input type="checkbox" name="{{ type }}" {{ checked }}>
18+
<span class="task-list-indicator"></span>
19+
{{ name }}
20+
</label>
21+
</li>
22+
{% endmacro %}
1523
{% set actions = config.extra.consent.actions %}
1624
{% if not actions %}
1725
{% set actions = ["accept", "manage"] %}
@@ -24,24 +32,21 @@ <h4>{{ config.extra.consent.title }}</h4>
2432
<input class="md-toggle" type="checkbox" id="__settings" {{ checked }}>
2533
<div class="md-consent__settings">
2634
<ul class="task-list">
35+
{% set cookies = config.extra.consent.cookies %}
36+
{% if "analytics" not in cookies %}
37+
{% if config.extra.analytics %}
38+
{{ render_cookie("Google Analytics", "analytics") }}
39+
{% endif %}
40+
{% endif %}
41+
{% if "github" not in cookies %}
42+
{% if config.repo_url and "github.com" in config.repo_url %}
43+
{{ render_cookie("GitHub", "github") }}
44+
{% endif %}
45+
{% endif %}
2746
{% for type in cookies %}
28-
{% set checked = "" %}
29-
{% if cookies[type] is string %}
30-
{% set name = cookies[type] %}
31-
{% set checked = "checked" %}
32-
{% else %}
33-
{% set name = cookies[type].name %}
34-
{% if cookies[type].checked %}
35-
{% set checked = "checked" %}
36-
{% endif %}
47+
{% if cookies[type] %}
48+
{{ render_cookie(cookies[type], type) }}
3749
{% endif %}
38-
<li class="task-list-item">
39-
<label class="task-list-control">
40-
<input type="checkbox" name="{{ type }}" {{ checked }}>
41-
<span class="task-list-indicator"></span>
42-
{{ name }}
43-
</label>
44-
</li>
4550
{% endfor %}
4651
</ul>
4752
</div>

material/templates/partials/feedback.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@
3232
{% else %}
3333
{% set title = page.title | urlencode %}
3434
{% endif %}
35-
{{ rating.note.format(url = url, title = title) }}
35+
{% set note = rating.note %}
36+
{% if note %}
37+
{% set note = note | replace("{url}", url) %}
38+
{% set note = note | replace("{title}", title) %}
39+
{% endif %}
40+
{{ note }}
3641
</div>
3742
{% endfor %}
3843
</div>

material/templates/partials/icons.html

+17-17
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@
22
This file was automatically generated - do not edit
33
-#}
44
{% if config.theme.icon.admonition %}
5-
{% set style = ["\x3cstyle\x3e:root{"] %}
6-
{% for type, icon in config.theme.icon.admonition.items() %}
5+
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
6+
{% for type, icon in config.theme.icon.admonition | items %}
77
{% import ".icons/" ~ icon ~ ".svg" as icon %}
8-
{% set _ = style.append(
8+
{% set _.style = _.style ~
99
"--md-admonition-icon--" ~ type ~ ":" ~
1010
"url('data:image/svg+xml;charset=utf-8," ~
1111
icon | replace("\n", "") | urlencode ~
1212
"');"
13-
) %}
13+
%}
1414
{% endfor %}
15-
{% set _ = style.append("}\x3c/style\x3e") %}
16-
{{ style | join }}
15+
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
16+
{{ _.style }}
1717
{% endif %}
1818
{% if config.theme.icon.annotation %}
19-
{% set style = ["\x3cstyle\x3e:root{"] %}
19+
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
2020
{% import ".icons/" ~ config.theme.icon.annotation ~ ".svg" as icon %}
21-
{% set _ = style.append(
21+
{% set _.style = _.style ~
2222
"--md-annotation-icon:" ~
2323
"url('data:image/svg+xml;charset=utf-8," ~
2424
icon | replace("\n", "") | urlencode ~
2525
"');"
26-
) %}
27-
{% set _ = style.append("}\x3c/style\x3e") %}
28-
{{ style | join }}
26+
%}
27+
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
28+
{{ _.style }}
2929
{% endif %}
3030
{% if config.theme.icon.tag %}
31-
{% set style = ["\x3cstyle\x3e"] %}
32-
{% for type, icon in config.theme.icon.tag.items() %}
31+
{% set _ = namespace(style = "\x3cstyle\x3e:root{") %}
32+
{% for type, icon in config.theme.icon.tag | items %}
3333
{% import ".icons/" ~ icon ~ ".svg" as icon %}
3434
{% if type != "default" %}
3535
{% set modifier = ".md-tag--" ~ type %}
3636
{% endif %}
37-
{% set _ = style.append(
37+
{% set _.style = _.style ~
3838
".md-tag" ~ modifier ~ "{" ~
3939
"--md-tag-icon:" ~
4040
"url('data:image/svg+xml;charset=utf-8," ~
4141
icon | replace("\n", "") | urlencode ~
4242
"');" ~
4343
"}"
44-
) %}
44+
%}
4545
{% endfor %}
46-
{% set _ = style.append("\x3c/style\x3e") %}
47-
{{ style | join }}
46+
{% set _.style = _.style ~ "}\x3c/style\x3e" %}
47+
{{ _.style }}
4848
{% endif %}

material/templates/partials/nav-item.html

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
<span class="{{ class }}"></span>
1111
{% endif %}
1212
{% endmacro %}
13-
{% macro render_content(nav_item, ref = nav_item) %}
13+
{% macro render_content(nav_item, ref) %}
14+
{% set ref = ref or nav_item %}
1415
{% if nav_item.meta and nav_item.meta.icon %}
1516
{% include ".icons/" ~ nav_item.meta.icon ~ ".svg" %}
1617
{% endif %}
@@ -25,7 +26,8 @@
2526
{{ render_status(nav_item, nav_item.meta.status) }}
2627
{% endif %}
2728
{% endmacro %}
28-
{% macro render_pruned(nav_item, ref = nav_item) %}
29+
{% macro render_pruned(nav_item, ref) %}
30+
{% set ref = ref or nav_item %}
2931
{% set first = nav_item.children | first %}
3032
{% if first and first.children %}
3133
{{ render_pruned(first, ref) }}
@@ -49,14 +51,15 @@
4951
{% endif %}
5052
{% endif %}
5153
{% if nav_item.children %}
52-
{% set indexes = [] %}
54+
{% set _ = namespace(index = none) %}
5355
{% if "navigation.indexes" in features %}
54-
{% for nav_item in nav_item.children %}
55-
{% if nav_item.is_index and not index is defined %}
56-
{% set _ = indexes.append(nav_item) %}
56+
{% for item in nav_item.children %}
57+
{% if item.is_index and _.index is none %}
58+
{% set _.index = item %}
5759
{% endif %}
5860
{% endfor %}
5961
{% endif %}
62+
{% set index = _.index %}
6063
{% if "navigation.tabs" in features %}
6164
{% if level == 1 and nav_item.active %}
6265
{% set class = class ~ " md-nav__item--section" %}
@@ -87,14 +90,13 @@
8790
{% set indeterminate = "md-toggle--indeterminate" %}
8891
{% endif %}
8992
<input class="md-nav__toggle md-toggle {{ indeterminate }}" type="checkbox" id="{{ path }}" {{ checked }}>
90-
{% if not indexes %}
93+
{% if not index %}
9194
{% set tabindex = "0" if not is_section %}
9295
<label class="md-nav__link" for="{{ path }}" id="{{ path }}_label" tabindex="{{ tabindex }}">
9396
{{ render_content(nav_item) }}
9497
<span class="md-nav__icon md-icon"></span>
9598
</label>
9699
{% else %}
97-
{% set index = indexes | first %}
98100
{% set class = "md-nav__link--active" if index == page %}
99101
<div class="md-nav__link md-nav__container">
100102
<a href="{{ index.url | url }}" class="md-nav__link {{ class }}">
@@ -115,7 +117,7 @@
115117
</label>
116118
<ul class="md-nav__list" data-md-scrollfix>
117119
{% for nav_item in nav_item.children %}
118-
{% if not indexes or nav_item != indexes | first %}
120+
{% if not index or nav_item != index %}
119121
{{ render(nav_item, path ~ "_" ~ loop.index, level + 1) }}
120122
{% endif %}
121123
{% endfor %}

material/templates/partials/social.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
{% endif %}
1010
{% set title = social.name %}
1111
{% if not title and "//" in social.link %}
12-
{% set _, url = social.link.split("//") %}
13-
{% set title = url.split("/")[0] %}
12+
{% set (_, url) = social.link.split("//") %}
13+
{% set title = url.split("/") | first %}
1414
{% endif %}
1515
<a href="{{ social.link }}" target="_blank" rel="{{ rel }}" title="{{ title | e }}" class="md-social__link">
1616
{% include ".icons/" ~ social.icon ~ ".svg" %}

material/templates/partials/source-file.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</span>
1919
{% endmacro %}
2020
{% macro render_authors(authors) %}
21-
{% set git_authors = config.plugins.get("git-authors") %}
21+
{% set git_authors = config.plugins["git-authors"] %}
2222
<span class="md-source-file__fact">
2323
<span class="md-icon" title="{{ lang.t('source.file.contributors') }}">
2424
{% if authors | length == 1 %}
@@ -101,7 +101,7 @@
101101
{{ render_created(created) }}
102102
{% endif %}
103103
{% if git_info %}
104-
{{ render_authors(git_info.get("page_authors")) }}
104+
{{ render_authors(git_info["page_authors"]) }}
105105
{% endif %}
106106
{% if committers %}
107107
{{ render_committers(committers) }}

material/templates/partials/tabs-item.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{#-
22
This file was automatically generated - do not edit
33
-#}
4-
{% macro render_content(nav_item, ref = nav_item) %}
4+
{% macro render_content(nav_item, ref) %}
5+
{% set ref = ref or nav_item %}
56
{% if nav_item == ref or "navigation.indexes" in features %}
67
{% if nav_item.is_index and nav_item.meta.icon %}
78
{% include ".icons/" ~ nav_item.meta.icon ~ ".svg" %}
89
{% endif %}
910
{% endif %}
1011
{{ ref.title }}
1112
{% endmacro %}
12-
{% macro render(nav_item, ref = nav_item) %}
13+
{% macro render(nav_item, ref) %}
14+
{% set ref = ref or nav_item %}
1315
{% set class = "md-tabs__item" %}
1416
{% if ref.active %}
1517
{% set class = class ~ " md-tabs__item--active" %}

0 commit comments

Comments
 (0)