From 76714c3731d171fe572e5dd2bca7aaa8b50e00fd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 6 Mar 2023 11:15:59 +0100 Subject: [PATCH 1/3] Update askama version to 0.12 --- Cargo.lock | 60 ++++++++++++++++++++++++--------------- src/librustdoc/Cargo.toml | 2 +- 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 74bb3c8e6c2..82530c019a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -132,47 +132,36 @@ checksum = "5a2f58b0bb10c380af2b26e57212856b8c9a59e0925b4c20f4a174a49734eaf7" [[package]] name = "askama" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d8f355701c672c2ba3d718acbd213f740beea577cc4eae66accdffe15be1882" +checksum = "47cbc3cf73fa8d9833727bbee4835ba5c421a0d65b72daf9a7b5d0e0f9cfb57e" dependencies = [ "askama_derive", "askama_escape", - "askama_shared", ] [[package]] name = "askama_derive" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84704cab5b7ae0fd3a9f78ee5eb7b27f3749df445f04623db6633459ae283267" -dependencies = [ - "askama_shared", - "proc-macro2", - "syn", -] - -[[package]] -name = "askama_escape" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1bb320f97e6edf9f756bf015900038e43c7700e059688e5724a928c8f3b8d5" - -[[package]] -name = "askama_shared" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dae03eebba55a2697a376e58b573a29fe36893157173ac8df312ad85f3c0e012" +checksum = "e80b5ad1afe82872b7aa3e9de9b206ecb85584aa324f0f60fa4c903ce935936b" dependencies = [ - "askama_escape", + "basic-toml", + "mime", + "mime_guess", "nom", "proc-macro2", "quote", "serde", "syn", - "toml 0.5.7", ] +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + [[package]] name = "atty" version = "0.2.14" @@ -223,6 +212,15 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" +[[package]] +name = "basic-toml" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c0de75129aa8d0cceaf750b89013f0e08804d6ec61416da787b35ad0d7cddf1" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -2614,6 +2612,22 @@ dependencies = [ "autocfg", ] +[[package]] +name = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "mime_guess" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" +dependencies = [ + "mime", + "unicase", +] + [[package]] name = "minifier" version = "0.2.2" diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index c48f7998c5a..6ca6edfd3c9 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -8,7 +8,7 @@ path = "lib.rs" [dependencies] arrayvec = { version = "0.7", default-features = false } -askama = { version = "0.11", default-features = false, features = ["config"] } +askama = { version = "0.12", default-features = false, features = ["config"] } itertools = "0.10.1" minifier = "0.2.2" once_cell = "1.10.0" From a776c1726334bcdf036fcb22e1258fe0268de939 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 6 Mar 2023 11:16:35 +0100 Subject: [PATCH 2/3] Remove unneeded minus sign in jinja tags --- src/librustdoc/askama.toml | 1 + src/librustdoc/html/templates/page.html | 294 +++++++++--------- src/librustdoc/html/templates/print_item.html | 52 ++-- 3 files changed, 174 insertions(+), 173 deletions(-) diff --git a/src/librustdoc/askama.toml b/src/librustdoc/askama.toml index 0c984f637ba..2732c4bc61e 100644 --- a/src/librustdoc/askama.toml +++ b/src/librustdoc/askama.toml @@ -1,2 +1,3 @@ [general] dirs = ["html/templates"] +whitespace = "suppress" diff --git a/src/librustdoc/html/templates/page.html b/src/librustdoc/html/templates/page.html index 7690d8f251f..e896850fab6 100644 --- a/src/librustdoc/html/templates/page.html +++ b/src/librustdoc/html/templates/page.html @@ -1,148 +1,148 @@ - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {{page.title}} {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {#- -#} - {%- for theme in themes -%} - {#- -#} - {%- endfor -%} - {%- if !layout.default_settings.is_empty() -%} - {#- -#} - {%- endif -%} - {#- -#} - {%- if page.css_class.contains("crate") -%} - {#- -#} - {%- else if page.css_class == "source" -%} - {#- -#} - {#- -#} - {%- else if !page.css_class.contains("mod") -%} - {#- -#} - {%- endif -%} - {#- -#} - {%- if layout.scrape_examples_extension -%} - {#- -#} - {%- endif -%} - {#- -#} - {%- if layout.css_file_extension.is_some() -%} - {#- -#} - {%- endif -%} - {%- if !layout.favicon.is_empty() -%} - {#- -#} - {%- else -%} - {#- -#} - {#- -#} - {#- -#} - {%- endif -%} - {{- layout.external_html.in_header|safe -}} - {#- -#} - {#- -#} - {#- -#} - {{- layout.external_html.before_content|safe -}} - {%- if page.css_class != "source" -%} - {#- -#} - {%- endif -%} - {#- -#} -
{#- -#} - {%- if page.css_class != "source" -%}
{%- endif -%} - {#- -#} -
{{- content|safe -}}
{#- -#} - {%- if page.css_class != "source" -%}
{%- endif -%} -
{#- -#} - {{- layout.external_html.after_content|safe -}} -
{#- -#} -
{#- -#} - {#- -#} - {#- -#} + {% endfor %} + > {# #} + {% endif %} + {# #} + {% if page.css_class.contains("crate") %} + {# #} + {% else if page.css_class == "source" %} + {# #} + {# #} + {% else if !page.css_class.contains("mod") %} + {# #} + {% endif %} + {# #} + {% if layout.scrape_examples_extension %} + {# #} + {% endif %} + {# #} + {% if layout.css_file_extension.is_some() %} + {# #} + {% endif %} + {% if !layout.favicon.is_empty() %} + {# #} + {% else %} + {# #} + {# #} + {# #} + {% endif %} + {{ layout.external_html.in_header|safe }} + {# #} + {# #} + {# #} + {{ layout.external_html.before_content|safe }} + {% if page.css_class != "source" %} + {# #} + {% endif %} + {# #} +
{# #} + {% if page.css_class != "source" %}
{% endif %} + {# #} +
{{ content|safe }}
{# #} + {% if page.css_class != "source" %}
{% endif %} +
{# #} + {{ layout.external_html.after_content|safe }} +
{# #} +
{# #} + {# #} + {# #} diff --git a/src/librustdoc/html/templates/print_item.html b/src/librustdoc/html/templates/print_item.html index 3a1867b7feb..edabac9a082 100644 --- a/src/librustdoc/html/templates/print_item.html +++ b/src/librustdoc/html/templates/print_item.html @@ -1,28 +1,28 @@ -
{#- -#} -

{#- -#} - {{-typ-}} - {#- The breadcrumbs of the item path, like std::string -#} - {%- for component in path_components -%} - {{component.name}}:: - {%- endfor -%} - {{name}} {#- -#} - {#- -#} -

{#- -#} - {#- -#} +
{# #} +

{# #} + {{typ}} + {# The breadcrumbs of the item path, like std::string #} + {% for component in path_components %} + {{component.name}}:: + {% endfor %} + {{name}} {# #} + {# #} +

{# #} + {# #} {% if !stability_since_raw.is_empty() %} - {{- stability_since_raw|safe }} · {# -#} + {{ stability_since_raw|safe +}} · {#+ #} {% endif %} - {%- match src_href -%} - {%- when Some with (href) -%} - source · {# -#} - {%- else -%} - {%- endmatch -%} - {#- -#} - {#- -#} -
{#- -#} + {% match src_href %} + {% when Some with (href) %} + source · {#+ #} + {% else %} + {% endmatch %} + {# #} +
{# #} +
{# #} From 511d2628c0c3a0920718029e815bb8df1834ee03 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 6 Mar 2023 11:17:02 +0100 Subject: [PATCH 3/3] Update documentation for HTML templates style --- src/librustdoc/html/templates/STYLE.md | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/html/templates/STYLE.md b/src/librustdoc/html/templates/STYLE.md index fff65e3b5ff..72c516c93eb 100644 --- a/src/librustdoc/html/templates/STYLE.md +++ b/src/librustdoc/html/templates/STYLE.md @@ -10,28 +10,29 @@ similar to [Jinja2](jinjadoc) and [Django](djangodoc) templates, and also to [As We want our rendered output to have as little unnecessary whitespace as possible, so that pages load quickly. To achieve that we use Tera's -[whitespace control] features. At the end of most lines, we put an empty comment -tag with the whitespace control characters: `{#- -#}`. This causes all -whitespace between the end of the line and the beginning of the next, including -indentation, to be omitted on render. Sometimes we want to preserve a single -space. In those cases we put the space at the end of the line, followed by -`{# -#}`, which is a directive to remove following whitespace but not preceding. -We also use the whitespace control characters in most instances of tags with -control flow, for example `{%- if foo -%}`. +[whitespace control] features. By default, whitespace characters are removed +around jinja tags (`{% %}` for example). At the end of most lines, we put an +empty comment tag: `{# #}`. This causes all whitespace between the end of the +line and the beginning of the next, including indentation, to be omitted on +render. Sometimes we want to preserve a single space. In those cases we put the +space at the end of the line, followed by `{#+ #}`, which is a directive to +remove following whitespace but not preceding. We also use the whitespace +control characters in most instances of tags with control flow, for example +`{% if foo %}`. [whitespace control]: https://tera.netlify.app/docs/#whitespace-control We want our templates to be readable, so we use indentation and newlines -liberally. We indent by four spaces after opening an HTML tag _or_ a Tera +liberally. We indent by four spaces after opening an HTML tag _or_ a Jinja tag. In most cases an HTML tag should be followed by a newline, but if the tag has simple contents and fits with its close tag on a single line, the contents don't necessarily need a new line. -Tera templates support quite sophisticated control flow. To keep our templates +Askama templates support quite sophisticated control flow. To keep our templates simple and understandable, we use only a subset: `if` and `for`. In particular -we avoid [assignments in the template logic](assignments) and [Tera +we avoid [assignments in the template logic](assignments) and [Askama macros](macros). This also may make things easier if we switch to a different Jinja-style template system, like Askama, in the future. -[assignments]: https://tera.netlify.app/docs/#assignments -[macros]: https://tera.netlify.app/docs/#macros +[assignments]: https://djc.github.io/askama/template_syntax.html#assignments +[macros]: https://djc.github.io/askama/template_syntax.html#macros