-
-
Notifications
You must be signed in to change notification settings - Fork 223
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
Load templates from relative paths #1112
base: main
Are you sure you want to change the base?
Conversation
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>
381cb2c
to
b6106c5
Compare
## Enables the ability to put templates in a directory relative to the source file that uses them. | ||
## Requires a nightly compiler and adding: | ||
## RUSTFLAGS='--cfg proc_macro_span --cfg procmacro2_semver_exempt' | ||
## to your cargo build command. |
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.
Consider adding the document-features
crate so this info can automatically populate the lib.rs doc comment without having to duplicate it.
@@ -26,7 +26,22 @@ impl<'a> Config<'a> { | |||
template_whitespace: Option<&str>, | |||
) -> std::result::Result<Config<'a>, CompileError> { | |||
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | |||
let default_dirs = vec![root.join("templates")]; | |||
let root_path = root.join("templates"); | |||
let default_dirs; |
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.
It's probable that the logic of which dirs end up in the list when config is taken into account might have to be a little more complex than this current logic. The crux of the problem is solved however, leaving the choice of how it should be behave remaining. I.e. if the user has a config file and it has dirs specified should we still resolve relative paths, should there be a config for this, ...
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:
RUSTFLAGS='--cfg proc_macro_span --cfg procmacro2_semver_exempt' \ cargo +nightly build
Fixes: https://github.com/djc/askama/issues/877
TODO:
relative-paths
for this)