Skip to content

Commit

Permalink
Enable more minijinja-contrib features in the CLI (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko authored Jul 31, 2024
1 parent 06a1aed commit a66801f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to MiniJinja are documented here.
`minijinja-contrib`. #547
- Added the ability to use `&T` and `Arc<T>` as parameters
to filters and functions if `T` is an `Object`. #548
- `minijinja-cli` now also enables the datetime, timezone and rand features. #549

## 2.1.0

Expand Down
5 changes: 3 additions & 2 deletions minijinja-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
rust-version = "1.65"

[features]
default = ["toml", "yaml", "querystring", "cbor", "datetime", "json5", "repl", "unicode"]
default = ["toml", "yaml", "querystring", "cbor", "datetime", "json5", "repl", "unicode", "contrib"]
yaml = ["serde_yml"]
querystring = ["serde_qs"]
cbor = ["ciborium"]
Expand All @@ -22,6 +22,7 @@ repl = ["rustyline"]
completions = ["clap_complete", "clap_complete_nushell", "clap_complete_fig"]
unicode = ["minijinja/unicode"]
ini = ["configparser"]
contrib = ["minijinja-contrib"]

[dependencies]
anyhow = "1.0.74"
Expand All @@ -42,7 +43,7 @@ minijinja = { version = "=2.1.0", path = "../minijinja", features = [
"unstable_machinery",
"custom_syntax",
] }
minijinja-contrib = { version = "=2.1.0", path = "../minijinja-contrib", features = ["pycompat"] }
minijinja-contrib = { version = "=2.1.0", optional = true, path = "../minijinja-contrib", features = ["pycompat", "datetime", "timezone", "rand"] }
rustyline = { version = "12.0.0", optional = true }
serde = "1.0.183"
serde_json = "1.0.105"
Expand Down
1 change: 1 addition & 0 deletions minijinja-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ selected when the defaults are turned off:
* `datetime`: enables the date and time filters and `now()` function
* `completions`: enables the generation of completions
* `unicode`: enables the unicode identifier support
* `contrib`: enables the `minijinja_contrib` based functionality including the `--py-compat` flag

Additionally if the `ASSET_OUT_DIR` environment variable is set during
compilation manpage (and optionally completions) are generated into that
Expand Down
1 change: 1 addition & 0 deletions minijinja-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub(super) fn make_command() -> Command {
arg!(--"no-newline" "Do not output a trailing newline"),
arg!(--"trim-blocks" "Enable the trim_blocks flag"),
arg!(--"lstrip-blocks" "Enable the lstrip_blocks flag"),
#[cfg(feature = "contrib")]
arg!(--"py-compat" "Enables improved Python compatibility. Enabling \
this adds methods such as dict.keys and some others."),
arg!(-s --syntax <PAIR>... "Changes a syntax feature (feature=value) \
Expand Down
9 changes: 6 additions & 3 deletions minijinja-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ fn create_env(
}
}

minijinja_contrib::add_to_environment(&mut env);
if matches.get_flag("py-compat") {
env.set_unknown_method_callback(minijinja_contrib::pycompat::unknown_method_callback);
#[cfg(feature = "contrib")]
{
minijinja_contrib::add_to_environment(&mut env);
if matches.get_flag("py-compat") {
env.set_unknown_method_callback(minijinja_contrib::pycompat::unknown_method_callback);
}
}

if matches.get_flag("env") {
Expand Down
4 changes: 2 additions & 2 deletions minijinja-contrib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub fn add_to_environment(env: &mut Environment) {
#[cfg(feature = "rand")]
{
env.add_filter("random", filters::random);
env.add_filter("randrange", globals::randrange);
env.add_filter("lipsum", globals::lipsum);
env.add_function("lipsum", globals::lipsum);
env.add_function("randrange", globals::randrange);
}
env.add_function("cycler", globals::cycler);
env.add_function("joiner", globals::joiner);
Expand Down

0 comments on commit a66801f

Please sign in to comment.