Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow nesting sections in tags #59

Merged
merged 4 commits into from
Jun 7, 2022
Merged

Conversation

grego
Copy link
Contributor

@grego grego commented Dec 18, 2021

It often happens that only one field from a subsecion is to be rendered. For this, one currently has to write {{#section}}{{field}}{{/section}}, which is quite verbose. This PR adds the posibility to write this as {{section field}}, or to nest arbitrary many such subsecions, like {{section subsecion field}}.

Furthermore, it allows opening arbitrarily many sections as {{#section subsecion subsubsection}}, or closing them as {{/subsubsection subsecion section}} (in the order they are closed).

Apart from readability, this should also improve rendering performance a bit, since unnecessary closing blocks with no HTML data are not added ({{section field}} doesn't require a closing block, the span of the section is automatically calculated).

On my machine, surprisingly, the parsing benchmark also turns out a bit beter than before, probably because trimming of whitespace and hashing of fields where it is not necessary is eliminated.

It often happens that only one field from a subsecion is to be rendered.
For this, one currently has to write `{{#section}}{{field}}{{/section}}`,
which is quite verbose. This PR adds the posibility to write this as
`{{section field}}`, or to nest arbitrary many such subsecions, like
`{{section subsecion field}}`.

Furthermore, it allows opening arbitrarily many sections as
`{{#section subsecion subsubsection}}`, or closing them as
`{{/subsubsection subsecion section}}` (in the order they are closed).

Apart from readability, this should also improve rendering performance a bit,
since unnecessary closing blocks with no HTML data are not added
(`{{section field}}` doesn't require a closing block, the span of the section
is automatically calculated).

On my machine, surprisingly, the parsing benchmark also turns out a bit beter
than before, probably because trimming of whitespace and hashing of fields where
it is not necessary is eliminated.
This makes the hashes the same as in the `HashMap<&str, V, FnvBuildHasher>`,
making it possible to get the field directly by its hash.
Reduces the number of dependencies and allows more flexibility in
choosing the hasher.
@@ -212,7 +228,7 @@ mod test {
Block {
html: "",
name: "test",
hash: 0xf9e6e6ef197c2b25,
hash: 2271575940368597870,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So using the Hash trait instead of Hasher::write changes the hash for &str somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the Hash implementation appends 0xff after the string.

@maciejhirsz maciejhirsz merged commit ec36358 into maciejhirsz:master Jun 7, 2022
@maciejhirsz
Copy link
Owner

Published in 0.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants