-
Notifications
You must be signed in to change notification settings - Fork 12
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
Remove rinja_escape
and make |escape
a "normal" filter
#53
Conversation
|
Looks all good to me, just one thing: could you add a test an invalid escaper please? I didn't see one. Would be also nice to improve the error message from |
Same for |
Sure! I updated the error message to contain the unknown escaper, and added a UI test. |
CI needs to be updated too. |
| | ||
= note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: no escaper defined for extension 'tex' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking more about this error message, I don't think it makes much sense, especially for users who just did a typo. What do you think about unknown extension 'tex'. The available extensions are 'x', 'y', 'z'
. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Added.
It is, but I failed to |
rinja_derive/src/lib.rs
Outdated
f.write_str("The available extensions are:")?; | ||
for (i, mut e) in exts.iter().copied().enumerate() { | ||
if e.is_empty() { | ||
e = r#""" <empty string>"#; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it was a debug display before checking. XD
I think using parens would be better here:
e = r#""" <empty string>"#; | |
e = r#""" (empty string)"#; |
One extra thought: wouldn't it be better to rely on join
instead? So your first iterator could become:
let exts: String = self
.0
.iter()
.flat_map(|(exts, _)| exts)
.map(|x| if x.is_empty() { r#""" (empty string)"# else { x.as_ref() })
.collect::<BTreeSet<&str>>()
.into_iter()
.join(", ");
No need for the loop below like this. And I think perf is not really a big issue here since we're errorring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. :) I use slice::join
and the debug display of the extension, now.
b009d48
to
5454d53
Compare
.iter() | ||
.flat_map(|(exts, _)| exts) | ||
.map(|x| format!("{x:?}")) | ||
.collect::<Vec<_>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better. 👍
Once merge conflict is fixed, please merge. |
5454d53
to
9beca5e
Compare
rinja_escaped
was a somewhat odd beast: Some functions and types were unused, some implementation details were open for the world to see, and it was checked at runtime if a value was safe when it could be deduced at compile type. Now|escape
and|safe
are proper filters with nothing unusual about them, and the additional crate is gone.This PR is a first step towards #51.