-
Notifications
You must be signed in to change notification settings - Fork 51
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
Use Askama in cpp2 #338
Use Askama in cpp2 #338
Conversation
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.
this seems promising
might want to consider moving template def code outside of ty.rs . Unsure if it will be better, worth considering
tool/templates/cpp2/base.txt
Outdated
@@ -0,0 +1,35 @@ | |||
#ifndef {{ header_guard }} |
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.
nit: probably should use .hpp or .hpp.tmpl
(and set gitattributes to highlight tmpl as Jinja or something)
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'll use .h.jinja
since that extension is picked up by the plugins for VSCode and Sublime Text
https://marketplace.visualstudio.com/items?itemName=samuelcolvin.jinjahtml
tool/templates/cpp2/base.txt
Outdated
#define {{ header_guard }} | ||
|
||
{%~ match decl_include %} | ||
{% when Some with (include) ~%} |
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.
not quite happy with needing a full match here but i guess it's fine. Does seem to be the idiomatic way to do things (djc/askama#257)
I finished migrating everything that made sense to migrate in Cpp2. |
The only commit that affects the output is f935c12. I tried to keep the Askama output identical to the pre-existing outupt. |
@@ -0,0 +1,29 @@ | |||
inline {##} | |||
{{- m.return_ty }} {##} |
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.
Note: when the open or close tag has a -
it means to strip whitespace before or after it. The {##}
is a comment that protects whitespace.
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.
this looks great!
return_ty: Cow<'a, str>, | ||
type_name: Cow<'a, str>, | ||
method_name: Cow<'a, str>, | ||
pre_qualifiers: Vec<Cow<'a, str>>, |
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.
nit: docs for the non-obvious ones, please
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.
Done
If you like the general direction this is taking, I'll finish it up for Cpp2.