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

Allow only pulling in specific builtins #890

Closed
BD103 opened this issue Jan 13, 2024 · 4 comments
Closed

Allow only pulling in specific builtins #890

BD103 opened this issue Jan 13, 2024 · 4 comments

Comments

@BD103
Copy link

BD103 commented Jan 13, 2024

In order to use builtin filters and functions, you have to enable the builtin feature:

builtins = ["urlencode", "slug", "humansize", "chrono", "chrono-tz", "rand"]

This feature requires 6 different dependencies, some of which you may not need (like rand). Instead of requiring an "all or nothing" approach, what if instead specific builtins are enabled only if the dependency they require is also enabled?

For instance, slugify would only require the slug feature to be enabled:

/// Transform a string into a slug
- #[cfg(feature = "builtins")]
+ #[cfg(feature = "slug")]
pub fn slugify(value: &Value, _: &HashMap<String, Value>) -> Result<Value> {
    let s = try_get_value!("slugify", "value", String, value);
    Ok(to_value(slug::slugify(s)).unwrap())
}

Source

I would love to work on this if the idea gets approved! :)

BD103 added a commit to BD103/bevy that referenced this issue Jan 13, 2024
This reverts commit 995bfe3.

Tera does not support only pulling in specific builtins (we just need the slugify one). See Keats/tera#890
@Keats
Copy link
Owner

Keats commented Jan 13, 2024

The way it's going to work for v2 is that you will have some built-in filters/fn/tests that don't require deps directly in Tera. Anything else will be a in a tera-contrib package with individual features for each element

@BD103
Copy link
Author

BD103 commented Jan 13, 2024

Would I be able to make a PR for v1 while v2 is still a work in progress? Or do you think v2 is stable enough to make the switch already?

My plan is to decrease the amount of dependencies Bevy uses in its CI, with Tera being the first on the list. The only filter it needs is slugify. The templates are relatively simple.

@Keats
Copy link
Owner

Keats commented Jan 13, 2024

v2 is not coming that soon. For your usecase you can just disable the built-in feature and copy paste the slugify filter?

@BD103
Copy link
Author

BD103 commented Jan 13, 2024

To be honest I didn't realize you can register your own filters. Thanks for the idea!

Have a good weekend

@BD103 BD103 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2024
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