From 354d24cf696d4bc4904c1649d6a2166b9d044414 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 27 Oct 2023 16:13:23 -0400 Subject: [PATCH] Add comment as a no-op. --- src/context/comment.rs | 23 +++++++++++++++++++++++ src/context/element.rs | 8 ++++++++ src/context/mod.rs | 1 + src/intermediate/comment.rs | 16 ++++++++++++++++ src/intermediate/element.rs | 6 +++++- src/intermediate/keyword.rs | 1 - src/intermediate/mod.rs | 2 ++ 7 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 src/context/comment.rs create mode 100644 src/intermediate/comment.rs diff --git a/src/context/comment.rs b/src/context/comment.rs new file mode 100644 index 0000000..713c220 --- /dev/null +++ b/src/context/comment.rs @@ -0,0 +1,23 @@ +use std::path::Path; + +use serde::Serialize; + +use crate::config::Config; +use crate::error::CustomError; +use crate::intermediate::IComment; + +#[derive(Debug, Serialize)] +#[serde(tag = "type")] +#[serde(rename = "comment")] +pub(crate) struct RenderComment {} + +impl RenderComment { + pub(crate) fn new, F: AsRef>( + config: &Config, + output_directory: D, + output_file: F, + comment: &IComment, + ) -> Result { + Ok(RenderComment {}) + } +} diff --git a/src/context/element.rs b/src/context/element.rs index 8a3cf0b..5144938 100644 --- a/src/context/element.rs +++ b/src/context/element.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IElement; +use super::comment::RenderComment; use super::keyword::RenderKeyword; use super::paragraph::RenderParagraph; @@ -14,6 +15,7 @@ use super::paragraph::RenderParagraph; pub(crate) enum RenderElement { Paragraph(RenderParagraph), Keyword(RenderKeyword), + Comment(RenderComment), } impl RenderElement { @@ -36,6 +38,12 @@ impl RenderElement { output_file, inner, )?)), + IElement::Comment(inner) => Ok(RenderElement::Comment(RenderComment::new( + config, + output_directory, + output_file, + inner, + )?)), } } } diff --git a/src/context/mod.rs b/src/context/mod.rs index f9b5e75..96a8811 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -1,4 +1,5 @@ mod blog_post_page; +mod comment; mod document_element; mod element; mod global_settings; diff --git a/src/intermediate/comment.rs b/src/intermediate/comment.rs new file mode 100644 index 0000000..70649f2 --- /dev/null +++ b/src/intermediate/comment.rs @@ -0,0 +1,16 @@ +use crate::error::CustomError; + +use super::registry::Registry; + +/// Essentially a no-op since the comment is not rendered. +#[derive(Debug)] +pub(crate) struct IComment {} + +impl IComment { + pub(crate) async fn new<'parse>( + registry: &mut Registry<'parse>, + comment: &organic::types::Comment<'parse>, + ) -> Result { + Ok(IComment {}) + } +} diff --git a/src/intermediate/element.rs b/src/intermediate/element.rs index e9b3feb..fd2b4f1 100644 --- a/src/intermediate/element.rs +++ b/src/intermediate/element.rs @@ -1,5 +1,6 @@ use crate::error::CustomError; +use super::comment::IComment; use super::keyword::IKeyword; use super::registry::Registry; use super::IParagraph; @@ -8,6 +9,7 @@ use super::IParagraph; pub(crate) enum IElement { Paragraph(IParagraph), Keyword(IKeyword), + Comment(IComment), } impl IElement { @@ -25,7 +27,9 @@ impl IElement { organic::types::Element::SpecialBlock(_) => todo!(), organic::types::Element::DynamicBlock(_) => todo!(), organic::types::Element::FootnoteDefinition(_) => todo!(), - organic::types::Element::Comment(_) => todo!(), + organic::types::Element::Comment(inner) => { + Ok(IElement::Comment(IComment::new(registry, inner).await?)) + } organic::types::Element::Drawer(_) => todo!(), organic::types::Element::PropertyDrawer(_) => todo!(), organic::types::Element::Table(_) => todo!(), diff --git a/src/intermediate/keyword.rs b/src/intermediate/keyword.rs index 876eff1..bd26939 100644 --- a/src/intermediate/keyword.rs +++ b/src/intermediate/keyword.rs @@ -1,7 +1,6 @@ use crate::error::CustomError; use super::registry::Registry; -use super::IObject; /// Essentially a no-op since the keyword is not rendered and any relevant impact on other elements is pulled from the parsed form of keyword. #[derive(Debug)] diff --git a/src/intermediate/mod.rs b/src/intermediate/mod.rs index 293b609..b363853 100644 --- a/src/intermediate/mod.rs +++ b/src/intermediate/mod.rs @@ -1,3 +1,4 @@ +mod comment; mod convert; mod definition; mod document_element; @@ -12,6 +13,7 @@ mod registry; mod section; mod target; mod util; +pub(crate) use comment::IComment; pub(crate) use convert::convert_blog_post_page_to_render_context; pub(crate) use definition::BlogPost; pub(crate) use document_element::IDocumentElement;