1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::collections::HashMap;

use serde_json::Value;

use crate::context::Context;
use crate::error::Result;

pub(crate) use self::datetime::{date, datetime, time};
pub(crate) use self::lower::lower;
pub(crate) use self::slugify::slugify;
pub(crate) use self::trim::trim;
pub(crate) use self::upper::upper;

mod datetime;
mod lower;
mod slugify;
mod trim;
mod upper;

/// Evaluation engine filter signature
///
/// You can register custom filter with the [`filter`] method.
///
/// # Arguments
///
/// * `input` - An input value
/// * `args` - A function arguments
/// * `context` - An evaluation context
///
/// # Examples
///
/// `"hallo" | upper`:
///
/// * `"hallo"` - filter `input`
/// * `upper` - filter name
/// * `args` - empty map
///
/// `"hallo" | upper(trim=true)`
///
/// * `"hallo"` - filter `input`
/// * `upper` - filter name
/// * `args` - map contains `trim` key with the `Value::Boolean(true)` value
///
/// Visit [`filter`] method documentation to see how to register custom function
/// and how it should look like.
///
/// [`Engine`]: struct.Engine.html
/// [`filter`]: struct.EngineBuilder.html#method.filter
pub type FilterFn = fn(input: &Value, args: &HashMap<String, Value>, context: &mut Context) -> Result<Value>;