Got rid of most of the Clone traits on the parser types since some of the parser results now contain owned values rather than just references.

This commit is contained in:
Tom Alexander
2020-05-31 19:01:51 -04:00
parent 15c8e3bf28
commit f1ec0ffb9e
4 changed files with 48 additions and 52 deletions

View File

@@ -3,8 +3,9 @@ extern crate nom;
use crate::renderer::CompareContextElement;
use parser::Filter;
use parser::OwnedLiteral;
use parser::Template;
use renderer::compile_template;
use renderer::CompiledTemplate;
use renderer::CompileError;
use renderer::ContextElement;
use renderer::DustRenderer;
use renderer::IntoContextElement;
@@ -38,18 +39,18 @@ fn main() {
(p.to_string(), template_content)
})
.collect();
let compiled_templates: Vec<CompiledTemplate> = template_contents
.iter()
.map(|(p, contents)| template_from_file(p, contents))
.collect();
let mut dust_renderer = DustRenderer::new();
compiled_templates.iter().for_each(|template| {
dust_renderer.load_source(template);
});
let main_template_name = &compiled_templates
.first()
.expect("There should be more than 1 template")
.name;
// let compiled_templates: Vec<CompiledTemplate> = template_contents
// .iter()
// .map(|(p, contents)| template_from_file(p, contents))
// .collect();
// let mut dust_renderer = DustRenderer::new();
// compiled_templates.iter().for_each(|template| {
// dust_renderer.load_source(template);
// });
// let main_template_name = &compiled_templates
// .first()
// .expect("There should be more than 1 template")
// .name;
// let breadcrumbs = vec![&context as &dyn IntoContextElement];
// println!(
// "{}",
@@ -59,11 +60,18 @@ fn main() {
// );
}
fn template_from_file<'a>(file_path: &str, file_contents: &'a str) -> CompiledTemplate<'a> {
fn template_from_file<'a>(
file_path: &str,
file_contents: &'a str,
) -> Result<(String, Template<'a>), CompileError> {
let path: &Path = Path::new(file_path);
let name = path.file_stem().unwrap();
compile_template(file_contents, name.to_string_lossy().to_string())
.expect("Failed to compile template")
let name = path.file_stem().ok_or(CompileError {
message: format!("Failed to get file stem on {}", file_path),
})?;
Ok((
name.to_string_lossy().to_string(),
compile_template(file_contents)?,
))
}
fn read_context_from_stdin() -> serde_json::Value {