natter/src/context/element.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2023-10-27 15:32:24 -04:00
use std::path::Path;
2023-10-24 00:04:44 -04:00
use serde::Serialize;
2023-10-27 15:32:24 -04:00
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IElement;
2023-10-27 16:13:23 -04:00
use super::comment::RenderComment;
2023-10-27 16:09:44 -04:00
use super::keyword::RenderKeyword;
2023-10-27 15:46:16 -04:00
use super::paragraph::RenderParagraph;
2023-10-24 00:04:44 -04:00
#[derive(Debug, Serialize)]
#[serde(untagged)]
2023-10-27 15:46:16 -04:00
pub(crate) enum RenderElement {
Paragraph(RenderParagraph),
2023-10-27 16:09:44 -04:00
Keyword(RenderKeyword),
2023-10-27 16:13:23 -04:00
Comment(RenderComment),
2023-10-27 15:46:16 -04:00
}
2023-10-27 15:32:24 -04:00
impl RenderElement {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
element: &IElement,
) -> Result<RenderElement, CustomError> {
2023-10-27 15:46:16 -04:00
match element {
IElement::Paragraph(inner) => Ok(RenderElement::Paragraph(RenderParagraph::new(
config,
output_directory,
output_file,
inner,
)?)),
2023-10-27 16:09:44 -04:00
IElement::Keyword(inner) => Ok(RenderElement::Keyword(RenderKeyword::new(
config,
output_directory,
output_file,
inner,
)?)),
2023-10-27 16:13:23 -04:00
IElement::Comment(inner) => Ok(RenderElement::Comment(RenderComment::new(
config,
output_directory,
output_file,
inner,
)?)),
2023-10-27 15:46:16 -04:00
}
2023-10-27 15:32:24 -04:00
}
}