natter/src/context/plain_list_item.rs
2023-10-29 18:46:13 -04:00

55 lines
1.3 KiB
Rust

use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IPlainListItem;
use super::RenderElement;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "plain_list_item")]
pub(crate) struct RenderPlainListItem {
tag: Vec<RenderObject>,
children: Vec<RenderElement>,
}
impl RenderPlainListItem {
pub(crate) fn new(
config: &Config,
output_directory: &Path,
output_file: &Path,
original: &IPlainListItem,
) -> Result<RenderPlainListItem, CustomError> {
let tag = {
let mut ret = Vec::new();
for obj in original.tag.iter() {
ret.push(RenderObject::new(
config,
output_directory,
output_file,
obj,
)?);
}
ret
};
let children = {
let mut ret = Vec::new();
for obj in original.children.iter() {
ret.push(RenderElement::new(
config,
output_directory,
output_file,
obj,
)?);
}
ret
};
Ok(RenderPlainListItem { tag, children })
}
}