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

Rust's raw identifiers in variable access #540

Closed
kellytk opened this issue Oct 10, 2021 · 8 comments · Fixed by #548
Closed

Rust's raw identifiers in variable access #540

kellytk opened this issue Oct 10, 2021 · 8 comments · Fixed by #548

Comments

@kellytk
Copy link
Contributor

kellytk commented Oct 10, 2021

From the documentation:

You can use a dot (.) to access variable's attributes or methods.

{% match f.fieldtype() %} runs as expected, however {% match f.r#type() %} generates an error unable to parse template.

@vallentin
Copy link
Collaborator

vallentin commented Oct 10, 2021

Can you check using the main branch? This might have been fixed in #476

@kellytk
Copy link
Contributor Author

kellytk commented Oct 11, 2021

It generates an error problems parsing template source at row y, column x near: "#type() %}...".

@vallentin
Copy link
Collaborator

If you're using the main branch. Then try using just {% match f.type() %}. Askama does not support raw identifiers, but the previously mentioned PR implements, so the generator automatically maps e.g. type to r#type, when it generates Rust code for the template.

@kellytk
Copy link
Contributor Author

kellytk commented Oct 11, 2021

With that code the error is expected identifier, found keyword 'type'.

rustc --version 1.57 nightly 2021-9-12

@djc
Copy link
Collaborator

djc commented Oct 12, 2021

It looks like #476 didn't cover the method call scenario (it did not add a normalize_identifier() call in visit_method_call()). Would be great if someone can submit a PR (ideally including a test case).

@kellytk
Copy link
Contributor Author

kellytk commented Oct 12, 2021

@djc In the course of attempting to create a PR, I've cloned the askama repo locally and updated my project's Cargo.toml to resolve the dependency via path to the local repo.

Although I can build the local askama repo, building my project fails with an error failed to get 'askama' as a dependency of package ... and continues to mention virtual manifests. How please can I resolve that?

@Kijewski
Copy link
Collaborator

Kijewski commented Oct 12, 2021

The project consists of multiple crates, and you need to add the path to the crate itself, not the project root. E.g. { path = "/home/kellytk/git/askama/askama" } instead of { path = "/home/kellytk/git/askama" }.

@kellytk
Copy link
Contributor Author

kellytk commented Oct 12, 2021

Which existing test is most like what you'd envision here @djc? I'll attempt to adapt it.

@djc djc closed this as completed in #548 Oct 13, 2021
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 a pull request may close this issue.

4 participants