2023-10-24 00:36:08 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
use crate::error::CustomError;
|
2023-10-27 13:05:34 -04:00
|
|
|
use crate::intermediate::ISection;
|
2023-10-24 00:36:08 -04:00
|
|
|
|
2023-10-27 15:32:24 -04:00
|
|
|
use super::RenderElement;
|
|
|
|
|
2023-10-24 00:36:08 -04:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(tag = "type")]
|
|
|
|
#[serde(rename = "section")]
|
2023-10-27 15:32:24 -04:00
|
|
|
pub(crate) struct RenderSection {
|
|
|
|
children: Vec<RenderElement>,
|
|
|
|
}
|
2023-10-24 00:36:08 -04:00
|
|
|
|
|
|
|
impl RenderSection {
|
|
|
|
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
|
|
|
|
config: &Config,
|
|
|
|
output_directory: D,
|
|
|
|
output_file: F,
|
2023-10-27 13:05:34 -04:00
|
|
|
section: &ISection,
|
2023-10-24 00:36:08 -04:00
|
|
|
) -> Result<RenderSection, CustomError> {
|
2023-10-27 15:32:24 -04:00
|
|
|
let children = section
|
|
|
|
.children
|
|
|
|
.iter()
|
|
|
|
.map(|obj| RenderElement::new(config, &output_directory, &output_file, obj))
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
|
|
|
|
Ok(RenderSection { children })
|
2023-10-24 00:36:08 -04:00
|
|
|
}
|
|
|
|
}
|