2023-10-27 17:08:58 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
use crate::error::CustomError;
|
|
|
|
use crate::intermediate::IPlainList;
|
|
|
|
|
2023-10-27 20:12:56 -04:00
|
|
|
use super::plain_list_item::RenderPlainListItem;
|
|
|
|
|
2023-10-27 17:08:58 -04:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(tag = "type")]
|
|
|
|
#[serde(rename = "plain_list")]
|
2023-10-27 20:12:56 -04:00
|
|
|
pub(crate) struct RenderPlainList {
|
|
|
|
list_type: String,
|
|
|
|
children: Vec<RenderPlainListItem>,
|
|
|
|
}
|
2023-10-27 17:08:58 -04:00
|
|
|
|
|
|
|
impl RenderPlainList {
|
2023-10-27 18:59:40 -04:00
|
|
|
pub(crate) fn new(
|
2023-10-27 17:08:58 -04:00
|
|
|
config: &Config,
|
2023-10-27 18:59:40 -04:00
|
|
|
output_directory: &Path,
|
|
|
|
output_file: &Path,
|
2023-10-27 17:08:58 -04:00
|
|
|
original: &IPlainList,
|
|
|
|
) -> Result<RenderPlainList, CustomError> {
|
2023-10-27 20:12:56 -04:00
|
|
|
let list_type = match original.list_type {
|
|
|
|
organic::types::PlainListType::Unordered => "unordered".to_owned(),
|
|
|
|
organic::types::PlainListType::Ordered => "ordered".to_owned(),
|
|
|
|
organic::types::PlainListType::Descriptive => "descriptive".to_owned(),
|
|
|
|
};
|
|
|
|
let children = {
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
for obj in original.children.iter() {
|
|
|
|
ret.push(RenderPlainListItem::new(
|
|
|
|
config,
|
2023-10-29 15:36:15 -04:00
|
|
|
output_directory,
|
|
|
|
output_file,
|
2023-10-27 20:12:56 -04:00
|
|
|
obj,
|
|
|
|
)?);
|
|
|
|
}
|
|
|
|
ret
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(RenderPlainList {
|
|
|
|
list_type,
|
|
|
|
children,
|
|
|
|
})
|
2023-10-27 17:08:58 -04:00
|
|
|
}
|
|
|
|
}
|