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

Constant used in template is not parsed properly #129

Closed
wezm opened this issue Jul 6, 2023 · 2 comments · Fixed by #130
Closed

Constant used in template is not parsed properly #129

wezm opened this issue Jul 6, 2023 · 2 comments · Fixed by #130

Comments

@wezm
Copy link
Contributor

wezm commented Jul 6, 2023

I have a constant:

pub const TOKEN_VALIDITY_DURATION: Duration = Duration::minutes(10);

Which I import and use in a template like:

@use crate::web::password_reset::TOKEN_VALIDITY_DURATION;

@(username: &str, link: &str, new_reset_link: &str)
    ⋮
    <p>
        If you don't use this link within @TOKEN_VALIDITY_DURATION.whole_minutes()
    ⋮

This results in generated code:

TOKEN_.to_html(_ructe_out_)?;
_ructe_out_.write_all(b"VALIDITY_DURATION.whole_minutes()")?;

I think the issue might be the second part of rust_name does not include uppercase letters. I tried adding them and it fixed the problem. I can submit a PR with the changes if you like.

ructe/src/expression.rs

Lines 54 to 62 in 4065b75

pub fn rust_name(input: &[u8]) -> PResult<&str> {
map_res(
recognize(pair(
alt((tag("_"), alpha1)),
opt(is_a("_0123456789abcdefghijklmnopqrstuvwxyz")),
)),
input_to_str,
)(input)
}

@kaj
Copy link
Owner

kaj commented Jul 15, 2023

Thanks! Yes, your diagnosis seems correct to me, a PR would be great!

(Or I could fix it myself if you no longer have time, since my answer is a week late).

@wezm
Copy link
Contributor Author

wezm commented Jul 15, 2023

I can do it. I've been using a fixed version in my project. I just need to write some tests to open the PR.

@kaj kaj closed this as completed in #130 Jul 16, 2023
kaj added a commit that referenced this issue Jul 16, 2023
kaj added a commit that referenced this issue Jul 22, 2023
* Added a check that no more than one of the http-types, mime02, or
  mime03 features are enabled (PR #124).  Thanks @rustafarian-dev.
* Changed the writer type from `W: &mut Write` to just `W: Write` (PR #125).
  Thanks @kornelski!
* Fixed handling of `MULTI_WORD_CONSTANTS` in templates (Issue #129, PR #130).
  Thanks @wezm!
* More ways to create a working rust symbol name from a "strange"
  static file name.  Illegal characters are replaced by `_`, and if
  the file name starts with a number it is prefixed with `n` (Issue
  #82, PR #132).  Thanks @Aedius for reporting!
* Fixed more clippy lints (PR #123, #127).  Thanks @vbrandl!
* Updated `rsass` to 0.28.0 and `itertools` to 0.11.0.
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.

2 participants