Keats/tera

Allow only pulling in specific builtins

BD103 opened this issue · 4 comments

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! :)

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

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.

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

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

Have a good weekend