Getting rendered output from duster.
This commit is contained in:
		
							parent
							
								
									043cc5eda4
								
							
						
					
					
						commit
						586fd8a066
					
				| @ -56,7 +56,8 @@ impl SiteRenderer { | ||||
| 
 | ||||
|         for blog_post in &self.blog_posts { | ||||
|             let render_context = convert_blog_post_to_render_context(blog_post); | ||||
|             renderer_integration.render(render_context)?; | ||||
|             let rendered_output = renderer_integration.render(render_context)?; | ||||
|             println!("Rendered: {}", rendered_output); | ||||
|         } | ||||
| 
 | ||||
|         Ok(()) | ||||
|  | ||||
| @ -13,6 +13,7 @@ pub(crate) enum CustomError { | ||||
|     Utf8(Utf8Error), | ||||
|     FromUtf8(FromUtf8Error), | ||||
|     DusterCompile(duster::renderer::CompileError), | ||||
|     DusterRender(duster::renderer::RenderError), | ||||
| } | ||||
| 
 | ||||
| impl From<std::io::Error> for CustomError { | ||||
| @ -74,3 +75,9 @@ impl From<duster::renderer::CompileError> for CustomError { | ||||
|         CustomError::DusterCompile(value) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl From<duster::renderer::RenderError> for CustomError { | ||||
|     fn from(value: duster::renderer::RenderError) -> Self { | ||||
|         CustomError::DusterRender(value) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -3,7 +3,6 @@ use std::collections::HashMap; | ||||
| use crate::error::CustomError; | ||||
| 
 | ||||
| use super::renderer_integration::RendererIntegration; | ||||
| use duster::renderer::DustRenderer; | ||||
| use serde::Serialize; | ||||
| 
 | ||||
| pub(crate) struct DusterRenderer<'a> { | ||||
| @ -29,10 +28,15 @@ impl<'a> RendererIntegration<'a> for DusterRenderer<'a> { | ||||
|     where | ||||
|         C: Serialize, | ||||
|     { | ||||
|         let mut dust_renderer = DustRenderer::new(); | ||||
|         println!("{}", serde_json::to_string(&context)?); | ||||
| 
 | ||||
|         // TODO
 | ||||
|         Ok("".to_owned()) | ||||
|         let mut dust_renderer = duster::renderer::DustRenderer::new(); | ||||
|         for (name, compiled_template) in self.templates.iter() { | ||||
|             dust_renderer.load_source(compiled_template, (*name).to_owned()); | ||||
|         } | ||||
|         // TODO: This is horribly inefficient. I am converting from a serialize type to json and back again so I can use the existing implementation of IntoContextElement. Honestly, I probably need to rework a lot of duster now that I've improved in rust over the years.
 | ||||
|         let json_context = serde_json::to_string(&context)?; | ||||
|         println!("Context: {}", json_context); | ||||
|         let parsed_context: serde_json::Value = serde_json::from_str(json_context.as_str())?; | ||||
|         let rendered_output = dust_renderer.render("main", Some(&parsed_context))?; | ||||
|         Ok(rendered_output) | ||||
|     } | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander