summaryrefslogtreecommitdiffstats
path: root/svgbob_cli/examples/memes2.rs
blob: b03fc85bd5a96fe1e8f86907c6fd961d30558eb5 (plain)
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
extern crate handlebars;
use std::fs::File;

use std::collections::BTreeMap;

use handlebars::Handlebars;
extern crate svg;
extern crate svgbob;

use handlebars::Context;

fn main() {
    let svg_file = "screenshots/memes2.svg";
    let html_file = "memes2.html";
    let bob_str = include_str!("memes2.bob");
    let svg = svgbob::to_svg(bob_str);
    svg::save(svg_file, &svg).unwrap();
    println!("Saved to {}", svg_file);

    let handlebars = Handlebars::new();
    let mut m: BTreeMap<String, String> = BTreeMap::new();
    m.insert("bob".to_string(), bob_str.to_owned());
    m.insert("svg_file".to_string(), svg_file.to_string());
    let context = Context::wraps(&m);

    let mut source_template = File::open(&"web/index.hbs").unwrap();
    let mut output_file = File::create(html_file).unwrap();
    if let Ok(_) = handlebars.template_renderw2(&mut source_template, &context, &mut output_file) {
        println!("Rendered to {}", html_file);
    } else {
        println!("Error");
    };
}