Make the renderer a bit more generic.
This commit is contained in:
parent
aed88cf05a
commit
fc5342adce
@ -4,6 +4,7 @@ use crate::blog_post::convert_blog_post_to_render_context;
|
||||
use crate::blog_post::BlogPost;
|
||||
use crate::error::CustomError;
|
||||
use crate::render::DusterRenderer;
|
||||
use crate::render::RendererIntegration;
|
||||
|
||||
pub(crate) struct SiteRenderer {
|
||||
pub(crate) output_directory: PathBuf,
|
||||
@ -12,13 +13,12 @@ pub(crate) struct SiteRenderer {
|
||||
|
||||
impl SiteRenderer {
|
||||
pub(crate) async fn render_blog_posts(&self) -> Result<(), CustomError> {
|
||||
let mut renderer_integration = DusterRenderer {};
|
||||
for blog_post in &self.blog_posts {
|
||||
let render_context = convert_blog_post_to_render_context(blog_post);
|
||||
println!("{}", serde_json::to_string(&render_context)?);
|
||||
renderer_integration.render(render_context)?;
|
||||
}
|
||||
|
||||
let mut renderer_integration = DusterRenderer {};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
use super::renderer_integration::RendererIntegration;
|
||||
use duster::renderer::DustRenderer;
|
||||
use serde::Serialize;
|
||||
|
||||
pub(crate) struct DusterRenderer {}
|
||||
|
||||
@ -8,17 +10,18 @@ impl RendererIntegration for DusterRenderer {
|
||||
I: Iterator<Item = P>,
|
||||
P: Into<std::path::PathBuf>,
|
||||
{
|
||||
todo!()
|
||||
// TODO
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render<P>(
|
||||
&self,
|
||||
context: &str,
|
||||
build_directory: P,
|
||||
) -> Result<String, crate::error::CustomError>
|
||||
fn render<C>(&self, context: C) -> Result<String, crate::error::CustomError>
|
||||
where
|
||||
P: AsRef<std::path::Path>,
|
||||
C: Serialize,
|
||||
{
|
||||
todo!()
|
||||
let mut dust_renderer = DustRenderer::new();
|
||||
println!("{}", serde_json::to_string(&context)?);
|
||||
|
||||
// TODO
|
||||
Ok("".to_owned())
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
mod duster_renderer;
|
||||
mod renderer_integration;
|
||||
pub(crate) use duster_renderer::DusterRenderer;
|
||||
pub(crate) use renderer_integration::RendererIntegration;
|
||||
|
@ -1,15 +1,16 @@
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::error::CustomError;
|
||||
|
||||
pub trait RendererIntegration {
|
||||
pub(crate) trait RendererIntegration {
|
||||
fn load_templates<I, P>(&mut self, dust_templates: I) -> Result<(), CustomError>
|
||||
where
|
||||
I: Iterator<Item = P>,
|
||||
P: Into<PathBuf>;
|
||||
|
||||
fn render<P>(&self, context: &str, build_directory: P) -> Result<String, CustomError>
|
||||
fn render<C>(&self, context: C) -> Result<String, crate::error::CustomError>
|
||||
where
|
||||
P: AsRef<Path>;
|
||||
C: Serialize;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user