-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
relative template paths and include_str support #877
Comments
I think I'm open to either of these (assuming the implemention doesn't add too much complexity), if you want take a whack at implementing this. Have a look at https://github.com/djc/askama/blob/main/askama_derive/src/generator.rs#L81 and https://github.com/djc/askama/blob/main/askama_derive/src/input.rs#L11. |
The first option is impossible to implement. The proc macro will only see the token But I like the second option! |
Yes please! I REALLY wish to co-locate the html file with the rust file. I've actively looked for alternatives to askama that does this, but I haven't found any, and I don't want to use anything else because I really like how askama does things. |
I'm currently using this: Create an empty
Downside is that you have to hard code the entire path |
Is there any progress? |
No, I guess there isn't. Do you want to submit a PR? |
I will try.... |
I think ATM the second option is also impossible to implement: rust-lang/rust#54725 (going on 6 years)
i.e. I don't think there's a way to do this at the moment. |
Templates can now be placed directly next to the source file that they are defined in as a default. This relies on an unstable rust compiler feature, which exposes the source file to proc macros. See <rust-lang/rust#54725> for more info. This requires the nightly compiler to run, and enabling the proc_macro_span and procmacro2_semver_exempt cfg flags. To build / test: ```shell RUSTFLAGS='--cfg proc_macro_span --cfg procmacro2_semver_exempt' \ cargo +nightly build ``` Fixes: <https://github.com/djc/askama/issues/877>
Templates can now be placed directly next to the source file that they are defined in as a default. This relies on an unstable rust compiler feature, which exposes the source file to proc macros. See <rust-lang/rust#54725> for more info. This requires the nightly compiler to run, and enabling the proc_macro_span and procmacro2_semver_exempt cfg flags. To build / test: ```shell RUSTFLAGS='--cfg proc_macro_span --cfg procmacro2_semver_exempt' \ cargo +nightly build ``` Fixes: <https://github.com/djc/askama/issues/877>
Use a nightly compiler, add cfg flags to your RUST_FLAGs and this PR does the trick: Needs a bikeshed discussion on the feature flag name (as From an implementation perspective, it made sense to me to just make the current source folder the first folder that gets searched for the template, rather than having to use any change in configuration. This allows some things to be put in the configured template folders and some things to be put in the relevant src folders. So the syntax to make this work is just One thing that is an open question is what to do when paths are specified in the config. I currently did not make this allow the relative paths, but it would be easy enough to extend the PR to do that. Requires a decision on this. (I haven't used config files generally so I don't really have a position on what is right there). Additionally, it might be worth considering looking at files up the directory tree in order to have the ability to define templates that are generic / reused / default, and which can be overridden. This might be useful for situations where you have a standard list format and then have a template defined that will just pick that up from the parent folder, but sometimes want to override the list view. Likely outside of the scope of the PR, but worth considering |
I would want to have the feature.html template be in the same folder as feature.rs.
It would be cool if you could do either one of:
A)
B)
The text was updated successfully, but these errors were encountered: