Skip to content

Make code generator re-usable for other projects#434

Merged
Kijewski merged 1 commit intoaskama-rs:masterfrom
Kijewski:pr-macros
May 17, 2025
Merged

Make code generator re-usable for other projects#434
Kijewski merged 1 commit intoaskama-rs:masterfrom
Kijewski:pr-macros

Conversation

@Kijewski
Copy link
Copy Markdown
Member

@Kijewski Kijewski commented May 15, 2025

This PR

  • removes the crate askama_derive_standalone,
  • makes askama_derive a normal library, and
  • adds the proc-macro crate askama_macros,

Before, it was not possible for another crate to re-export askama::Template in a useful way, because the generated code assumes that it has access to an extern crate askama.

askama_derive will export the function derive_template() like askama_derive_standalone did, but it has an additional argument to accept a TokenStream that should contain (an) statement(s) to define the identifier askama, e.g. quote! { extern crate askama; }.

The new proc-macro crate askama_macros now defines the derive-macro Template by calling askama_derive::derive_template().

Prior art: encaseencase_deriveencase_derive_impl; 2298a3e.

The PR is best viewed with ignored whitespace changes.

Resolves #377.

Comment thread testing/tests/reexported-askama.rs Dismissed
Comment thread askama/src/lib.rs
Comment on lines -86 to -87
#[doc(hidden)]
pub use crate as shared;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed since askama v0.10 IIRC.

@Kijewski Kijewski force-pushed the pr-macros branch 7 times, most recently from ea15d1f to 81b64c4 Compare May 16, 2025 14:09
This PR
* removes the crate `askama_derive_standalone`,
* makes `askama_derive` a normal library, and
* adds the proc-macro crate `askama_macros`,

Before, it was not possible for another crate to re-export
`askama::Template` in a useful way, because the generated code assumes
that it has access to an `extern crate askama`.

`askama_derive` will export the function `derive_template()` like
`askama_derive_standalone` did, but it has an additional argument to
accept a `TokenStream` that should contain (an) statement(s) to define
the identifier `askama`, e.g. `quote! { extern crate askama; }`.

The new proc-macro crate `askama_macros` now defines the derive-macro
`Template` by calling `askama_derive::derive_template()`.

Prior art: [`encase`] → [`encase_derive`] → [`encase_derive_impl`];
[2298a3e].

[`encase`]: <https://crates.io/crates/encase/0.11.0>
[`encase_derive`]: <https://crates.io/crates/encase_derive/0.11.0>
[`encase_derive_impl`]: <https://crates.io/crates/encase_derive_impl/0.11.0>
[2298a3e]: <teoxoy/encase@2298a3e>
@Kijewski Kijewski merged commit 6ce85f3 into askama-rs:master May 17, 2025
39 checks passed
@Kijewski Kijewski deleted the pr-macros branch May 17, 2025 11:20
@Kijewski Kijewski mentioned this pull request Jun 6, 2025
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

Successfully merging this pull request may close these issues.

Please make lib.rs/build_template public

3 participants