Last active
December 21, 2015 00:35
-
-
Save brianloveswords/affc96cebf859c2df3db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate handlebars; | |
extern crate rustc_serialize; | |
use std::collections::HashMap; | |
use handlebars::Handlebars; | |
type Data = HashMap<String, String>; | |
struct Templatizer { | |
handlebars: Handlebars, | |
} | |
impl Templatizer { | |
fn new(template: String) -> Templatizer { | |
let mut hb = Handlebars::new(); | |
hb.register_template_string("template", template); | |
Templatizer { handlebars: hb } | |
} | |
fn render(&self, data: &Data) -> String { | |
self.handlebars.render("template", data).unwrap() | |
} | |
} | |
pub fn main() { | |
let t = Templatizer::new(String::from("this is {{stuff}}")); | |
let mut data = Data::new(); | |
data.insert(String::from("stuff"), String::from("updog")); | |
println!("{}", t.render(&data)); // prints "this is updog" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment