Skip to content

Commit

Permalink
Rollup merge of #108805 - GuillaumeGomez:update-askama, r=notriddle
Browse files Browse the repository at this point in the history
Update askama to 0.12 and improve whitespace control

`askama` 0.12 was just released, and it adds the possibility to have "whitespace suppression" enabled by default in the configuration so I switched to it.

r? ``@notriddle``
  • Loading branch information
JohnTitor authored Mar 7, 2023
2 parents 4dc48db + 511d262 commit 79fd51d
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 210 deletions.
60 changes: 37 additions & 23 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/askama.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[general]
dirs = ["html/templates"]
whitespace = "suppress"
27 changes: 14 additions & 13 deletions src/librustdoc/html/templates/STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 79fd51d

Please sign in to comment.