compiling templates in the same manner as the shim
This commit is contained in:
31
src/bin.rs
31
src/bin.rs
@@ -1,13 +1,42 @@
|
||||
extern crate nom;
|
||||
|
||||
use parser::template;
|
||||
use renderer::compile_template;
|
||||
use renderer::CompiledTemplate;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, Read};
|
||||
use std::path::Path;
|
||||
|
||||
mod parser;
|
||||
mod renderer;
|
||||
|
||||
fn main() {
|
||||
let context = read_context_from_stdin();
|
||||
println!("{:?}", context);
|
||||
|
||||
let argv: Vec<String> = env::args().collect();
|
||||
if argv.len() < 2 {
|
||||
panic!("Need to pass templates");
|
||||
}
|
||||
let template_paths = &argv[1..];
|
||||
let template_contents: Vec<(String, String)> = template_paths
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let template_content = fs::read_to_string(&p).unwrap();
|
||||
(p.to_string(), template_content)
|
||||
})
|
||||
.collect();
|
||||
let compiled_templates: Vec<CompiledTemplate> = template_contents
|
||||
.iter()
|
||||
.map(|(p, contents)| template_from_file(p, contents))
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn template_from_file<'a>(file_path: &str, file_contents: &'a str) -> CompiledTemplate<'a> {
|
||||
let path: &Path = Path::new(file_path);
|
||||
let name = path.file_stem().unwrap();
|
||||
println!("{:?}", name);
|
||||
compile_template(file_contents, name.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
fn read_context_from_stdin() -> serde_json::map::Map<String, serde_json::Value> {
|
||||
|
||||
Reference in New Issue
Block a user