/
germanubis
/
tera
Обзор
Документация
Войти
/
germanubis
/
tera
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
docs/playground/src/lib.rs
20 строк
634 B
Vincent Prouillet
Work on playground (#609)
07 мар 2021, 00:15
Не верифицирован
07 мар 2021, 00:15
668de49
Код
Авторство
О чём код?
mod utils; use tera::{Context, Tera}; use wasm_bindgen::prelude::*; // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator. #[cfg(feature = "wee_alloc")] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; #[wasm_bindgen] pub fn render(template: &str, context: String) -> Result<String, JsValue> { tera_render(template, &context).map_err(|e| e.to_string().into()) } fn tera_render(template: &str, context: &str) -> Result<String, tera::Error> { let context = Context::from_value(serde_json::from_str(context)?)?; Tera::one_off(template, &context, true) }