We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In tests/helper_macro.rs, within the function test_macro_helper, you can add the following assertion.
tests/helper_macro.rs
test_macro_helper
assert_eq!( hbs.render_template("{{tag 'html'}}", &()).unwrap(), "<html>" );
thread 'test_macro_helper' panicked at 'called `Result::unwrap()` on an `Err` value: RenderError { desc: "`tag` helper: Couldn't convert parameter t to type `str`. It's Null as JSON. Got these params: [PathAndJson { relative_path: Some(\"'html'\"), value: Missing }]", template_name: None, line_no: Some(1), column_no: Some(1), cause: None, unimplemented: false }', tests/helper_macro.rs:77:52
I believe the origin of this behavior is
handlebars-rust/src/template.rs
Lines 292 to 296 in 27a9a9a
The single-quoted literal matches the Rule::literal parser rule, but it is not valid JSON, so it becomes a Name object.
Rule::literal
As evidence of this, here is the data structure I get by parsing the template {{tag 'html'}}:
{{tag 'html'}}
Template { name: None, elements: [ Expression(HelperTemplate { name: Name("tag"), params: [Name("'html'")], hash: {}, block_param: None, template: None, inverse: None, block: false }) ], mapping: [TemplateMapping(1, 1)] }
I think the way forward is to somehow extract more information from the pest parse results.
Here is a rough sketch of how I think that logic might look. As you can see, I'm out of my depth here, but this passes all the tests!
Rule::literal => { let param = param.into_inner().next().unwrap(); match param.as_rule() { Rule::string_literal => { let string_inner = param.into_inner().next().unwrap(); // don't double-escape characters - see test_string_no_escape_422 let double_quoted = format!("\"{}\"", string_inner.as_str()); Parameter::Literal(Json::from_str(&double_quoted).unwrap()) } _ => { Parameter::Literal(Json::from_str(param_span.as_str()).unwrap()) } } }
(In the suggestion above I removed the Name code path, since I don't think any other JSON data type would make sense as a Name.)
Thank you very much, for reading this report and for all your work on this project.
The text was updated successfully, but these errors were encountered:
Thank you for reporting and the solution looks good to me. Could you please create a pull request for this?
Sorry, something went wrong.
No branches or pull requests
Reproduction
In
tests/helper_macro.rs
, within the functiontest_macro_helper
, you can add the following assertion.Cause
I believe the origin of this behavior is
handlebars-rust/src/template.rs
Lines 292 to 296 in 27a9a9a
The single-quoted literal matches the
Rule::literal
parser rule, but it is not valid JSON, so it becomes a Name object.As evidence of this, here is the data structure I get by parsing the template
{{tag 'html'}}
:Proposal
I think the way forward is to somehow extract more information from the pest parse results.
Here is a rough sketch of how I think that logic might look. As you can see, I'm out of my depth here, but this passes all the tests!
(In the suggestion above I removed the Name code path, since I don't think any other JSON data type would make sense as a Name.)
Thank you very much, for reading this report and for all your work on this project.
The text was updated successfully, but these errors were encountered: