2023-10-27 12:47:12 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-10-24 00:04:44 -04:00
|
|
|
use serde::Serialize;
|
|
|
|
|
2023-10-27 12:47:12 -04:00
|
|
|
use crate::config::Config;
|
|
|
|
use crate::error::CustomError;
|
2023-10-27 13:05:34 -04:00
|
|
|
use crate::intermediate::IObject;
|
2023-10-27 12:47:12 -04:00
|
|
|
|
2023-10-27 13:01:45 -04:00
|
|
|
use super::plain_text::RenderPlainText;
|
|
|
|
|
2023-10-24 00:04:44 -04:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(untagged)]
|
2023-10-27 13:01:45 -04:00
|
|
|
pub(crate) enum RenderObject {
|
|
|
|
PlainText(RenderPlainText),
|
|
|
|
}
|
2023-10-27 12:47:12 -04:00
|
|
|
|
|
|
|
impl RenderObject {
|
|
|
|
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
|
|
|
object: &IObject,
|
2023-10-27 12:47:12 -04:00
|
|
|
) -> Result<RenderObject, CustomError> {
|
2023-10-27 13:01:45 -04:00
|
|
|
match object {
|
2023-10-27 13:05:34 -04:00
|
|
|
IObject::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new(
|
2023-10-27 13:01:45 -04:00
|
|
|
config,
|
|
|
|
output_directory,
|
|
|
|
output_file,
|
|
|
|
inner,
|
|
|
|
)?)),
|
|
|
|
}
|
2023-10-27 12:47:12 -04:00
|
|
|
}
|
|
|
|
}
|