Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ features = [
# Templates
[workspace.dependencies.minijinja]
version = "2.4.0"
features = ["loader", "json", "speedups", "unstable_machinery"]

# Additional filters for minijinja
[workspace.dependencies.minijinja-contrib]
version = "2.3.1"
features = ["pycompat"]

# Utilities to deal with non-zero values
[workspace.dependencies.nonzero_ext]
Expand Down
1 change: 1 addition & 0 deletions crates/handlers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ time = "0.3.36"
url.workspace = true
mime = "0.3.17"
minijinja.workspace = true
minijinja-contrib.workspace = true
nonzero_ext.workspace = true
rand.workspace = true
rand_chacha = "0.3.1"
Expand Down
12 changes: 4 additions & 8 deletions crates/handlers/src/upstream_oauth2/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ use std::{collections::HashMap, sync::Arc};
use base64ct::{Base64, Base64Unpadded, Base64Url, Base64UrlUnpadded, Encoding};
use minijinja::{Environment, Error, ErrorKind, Value};

fn split(value: &str, separator: Option<&str>) -> Vec<String> {
value
.split(separator.unwrap_or(" "))
.map(ToOwned::to_owned)
.collect::<Vec<_>>()
}

fn b64decode(value: &str) -> Result<Value, Error> {
// We're not too concerned about the performance of this filter, so we'll just
// try all the base64 variants when decoding
Expand Down Expand Up @@ -78,12 +71,15 @@ fn string(value: &Value) -> String {
pub fn environment() -> Environment<'static> {
let mut env = Environment::new();

env.add_filter("split", split);
minijinja_contrib::add_to_environment(&mut env);

env.add_filter("b64decode", b64decode);
env.add_filter("b64encode", b64encode);
env.add_filter("tlvdecode", tlvdecode);
env.add_filter("string", string);

env.set_unknown_method_callback(minijinja_contrib::pycompat::unknown_method_callback);

env
}

Expand Down
2 changes: 1 addition & 1 deletion crates/i18n-scan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ workspace = true
[dependencies]
camino.workspace = true
clap.workspace = true
minijinja = { workspace = true, features = ["unstable_machinery"] }
minijinja.workspace = true
serde_json.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ walkdir = "2.5.0"
anyhow.workspace = true
thiserror.workspace = true

minijinja = { workspace = true, features = ["loader", "json", "speedups", "unstable_machinery"] }
minijinja.workspace = true
minijinja-contrib.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_urlencoded = "0.7.1"
Expand Down
16 changes: 3 additions & 13 deletions crates/templates/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ pub fn register(
vite_manifest: ViteManifest,
translator: Arc<Translator>,
) {
env.set_unknown_method_callback(minijinja_contrib::pycompat::unknown_method_callback);

minijinja_contrib::add_to_environment(env);
env.add_test("empty", self::tester_empty);
env.add_test("starting_with", tester_starting_with);
env.add_filter("to_params", filter_to_params);
env.add_filter("simplify_url", filter_simplify_url);
env.add_filter("add_slashes", filter_add_slashes);
env.add_filter("split", filter_split);
env.add_function("add_params_to_url", function_add_params_to_url);
env.add_function("counter", || Ok(Value::from_object(Counter::default())));
env.add_global(
Expand Down Expand Up @@ -72,17 +73,6 @@ fn tester_empty(seq: Value) -> bool {
seq.len() == Some(0)
}

fn tester_starting_with(value: &str, prefix: &str) -> bool {
value.starts_with(prefix)
}

fn filter_split(value: &str, separator: &str) -> Vec<String> {
value
.split(separator)
.map(std::borrow::ToOwned::to_owned)
.collect()
}

fn filter_add_slashes(value: &str) -> String {
value
.replace('\\', "\\\\")
Expand Down
2 changes: 1 addition & 1 deletion templates/components/scope.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<li>{{ icon.error() }}<p>{{ _("mas.scope.synapse_admin") }}</p></li>
{% elif scope == "urn:mas:admin" %}
<li>{{ icon.error() }}<p>{{ _("mas.scope.mas_admin") }}</p></li>
{% elif scope is starting_with("urn:matrix:org.matrix.msc2967.client:device:") %}
{% elif scope is startingwith("urn:matrix:org.matrix.msc2967.client:device:") %}
{# We hide this scope #}
{% else %}
<li>{{ icon.info() }}<p>{{ scope }}</p></li>
Expand Down
Loading