Module rubble_templates::std_fun[][src]

This module contains standard functions for rubble-templates. Use std_functions to get a copy of map with those functions.

use std::collections::HashMap;
use rubble_templates::std_fun::std_functions;
use rubble_templates_evaluators::simple::template::Template;
use rubble_templates_evaluators::simple::evaluator::SimpleEvaluationEngine;
use rubble_templates_evaluators::simple::compiler::TemplateCompiler;
use rubble_templates_core::compiler::Compiler;
use rubble_templates_core::evaluator::Context;

let raw_input = "2 + 3 = {{ + 2 3 }}".to_string();

// prepare compilation evironment
let template = Template::from(raw_input);
let engine = SimpleEvaluationEngine::from(std_functions());
let compiler = TemplateCompiler::new(engine);

let result = compiler.compile(&template, Context::empty());

assert_eq!(result.unwrap(), "2 + 3 = 5".to_string());

See rubble_templates_core::functions for more info on how to implement custom Functions.

Example usages are in the test-assets. See the “stdlib-template” and “stdlib-template-output” to see standard functions in action.

Modules

math

Provides standard math functions.

strings

Provides standard string manipulation and utility functions.

Functions

std_functions

Provides a set of standard functions.