natter/src/context/section.rs

41 lines
912 B
Rust
Raw Normal View History

use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::ISection;
2023-10-27 15:32:24 -04:00
use super::RenderElement;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "section")]
2023-10-27 15:32:24 -04:00
pub(crate) struct RenderSection {
children: Vec<RenderElement>,
}
impl RenderSection {
2023-10-27 18:59:40 -04:00
pub(crate) fn new(
config: &Config,
2023-10-27 18:59:40 -04:00
output_directory: &Path,
output_file: &Path,
section: &ISection,
) -> Result<RenderSection, CustomError> {
2023-10-27 18:59:40 -04:00
let children = {
let mut ret = Vec::new();
for obj in section.children.iter() {
ret.push(RenderElement::new(
config,
2023-10-29 15:36:15 -04:00
output_directory,
output_file,
2023-10-27 18:59:40 -04:00
obj,
)?);
}
ret
};
2023-10-27 15:32:24 -04:00
Ok(RenderSection { children })
}
}