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
50
51
52
53
54
/*!
Katalyst configuration is based around expressions. Expressions are a syntax for templating and
customization from within the configuration.
*/

mod bindings;
pub(crate) mod compiler;
mod traits;

use crate::prelude::*;
use bindings::*;
pub use compiler::Compiler;
use std::sync::Arc;
pub use traits::*;
use unstructured::Document;

/// Arguments passed to an expression
pub type ExpressionArgs = Vec<Arc<CompiledExpression>>;
/// The base expression
pub type Expression = Vec<Arc<CompiledExpression>>;

impl CompiledExpression for Expression {
    fn render(&self, guard: &RequestContext) -> RenderResult {
        let mut result = String::new();
        for part in self.iter() {
            result.push_str(&part.render(guard)?);
        }
        Ok(result)
    }

    fn result(&self, guard: &RequestContext) -> ExpressionResult {
        let mut res = vec![];
        for exp in self.iter() {
            res.push(exp.result(guard)?);
        }
        Ok(res.into())
    }

    fn result_type(&self) -> Document {
        Document::Seq(vec![])
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn compile_template() {
        let compiler = Compiler::default();
        compiler.compile_template(Some("/testing/the/parser/{{http.ip()}}/test")).unwrap();
    }

}