Create a struct that will combine all the context for converting intermediate objects into the dust render context.

This commit is contained in:
Tom Alexander 2023-12-19 14:54:12 -05:00
parent 94d9a95967
commit cb3278aba5
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
4 changed files with 31 additions and 2 deletions

View File

@ -8,6 +8,7 @@ use crate::error::CustomError;
use super::raw::RawConfig;
/// This is the config struct used by most of the code, which is an interpreted version of the RawConfig struct which is the raw disk-representation of the config.
#[derive(Debug)]
pub(crate) struct Config {
raw: RawConfig,
config_path: PathBuf,

View File

@ -2,7 +2,7 @@ use serde::Deserialize;
use serde::Serialize;
/// This is the struct for the writer.toml config file that ends up in each site's root directory.
#[derive(Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct RawConfig {
pub(super) site_title: Option<String>,
author: Option<String>,
@ -25,7 +25,7 @@ impl Default for RawConfig {
}
}
#[derive(Deserialize, Serialize)]
#[derive(Debug, Deserialize, Serialize)]
pub(crate) struct RawConfigStream {
pub(super) entries_per_page: Option<usize>,
}

View File

@ -48,6 +48,7 @@ mod quote_block;
mod radio_link;
mod radio_target;
mod regular_link;
mod render_context;
mod section;
mod special_block;
mod src_block;

View File

@ -0,0 +1,27 @@
use std::path::Path;
use crate::config::Config;
use crate::error::CustomError;
/// The supporting information used for converting the intermediate representation into the dust context for rendering.
#[derive(Debug, Clone)]
pub(crate) struct RenderContext<'intermediate> {
pub(crate) config: &'intermediate Config,
// TODO: Perhaps rename to output_root_directory.
pub(crate) output_directory: &'intermediate Path,
pub(crate) output_file: &'intermediate Path,
}
impl<'intermediate> RenderContext<'intermediate> {
pub(crate) fn new(
config: &'intermediate Config,
output_directory: &'intermediate Path,
output_file: &'intermediate Path,
) -> Result<RenderContext<'intermediate>, CustomError> {
Ok(RenderContext {
config,
output_directory,
output_file,
})
}
}