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

Configure template paths for debug and release. #1103

Open
RylanYancey opened this issue Oct 13, 2024 · 5 comments
Open

Configure template paths for debug and release. #1103

RylanYancey opened this issue Oct 13, 2024 · 5 comments

Comments

@RylanYancey
Copy link

I'm using Vite for my application, which is used to build the app, but does not run during development. While in debug mode, I want askama to load templates from /static, but load from /dist during dev. it would be nice if I could configure a debug mode in the Askama.toml without having to do a bunch of ugly #[cfg_attr on each of my templates.

@djc
Copy link
Owner

djc commented Oct 14, 2024

Hmm, I don't think there is a clean way to do this, but feel free to propose a design.

@RylanYancey
Copy link
Author

Hmm, I don't think there is a clean way to do this, but feel free to propose a design.

Option 1: Set alternative debug path in the macro.

#[derive(Template)]
#[template(
     path = "./static/pages/settings.html",
     debug = "./dist/pages/settings.html"
)]
pub struct SettingsPage {
    pub profile: UserProfile,
}

Askama would use the HTML file in dist when building for release, and static when building in debug mode.

Option 2: Add a 'debug-dirs' key to the config file

[general]
dirs = ["./static/pages", "./static/templates"]
debug-dirs = ["./dist/pages", "./static/templates"]

@djc
Copy link
Owner

djc commented Oct 20, 2024

How would Askama detect whether the calling code is compiled in debug mode? As I understand it, each crate may be compiled with a separate profile, and as a procedural macro crate, the profile with which Askama is compiled doesn't necessarily match the profile the calling code is compiled with.

@RylanYancey
Copy link
Author

How would Askama detect whether the calling code is compiled in debug mode? As I understand it, each crate may be compiled with a separate profile, and as a procedural macro crate, the profile with which Askama is compiled doesn't necessarily match the profile the calling code is compiled with.

I was under the impression that #[cfg(debug_assertions)] worked for dependencies as well. In the case of option 2, this could be implemented by conditionally using debug-dirs instead of dirs when compiling for debug mode.

If that is not the case, perhaps this could work:

Option 3: 'debug' feature in dev-dependencies

[dependencies]
askama = { version = "0.12.1", features = ["with-axum"] }

[dev-dependencies]
askama = { version = "0.12.1", features = ["with-axum", "debug"]  }

Specifying the debug feature in the dev dependencies would cause Askama to use a debug profile, such as:

[general]
dirs = ["./dist"]

[debug]
dirs = ["./static"]

@djc
Copy link
Owner

djc commented Oct 21, 2024

Yeah, I don't think any of this really makes sense. I suggest you write a custom procedural macro to abstract over the bunch of ugly #[cfg_attr on your templates.

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

No branches or pull requests

2 participants