From 5b34942b64830450cacc7f019d83d8c83a36b3f6 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 27 Oct 2023 15:32:24 -0400 Subject: [PATCH] Add element. --- src/context/element.rs | 17 +++++++++++++++++ src/context/section.rs | 14 ++++++++++++-- src/intermediate/element.rs | 38 +++++++++++++++++++++++++++++++++++++ src/intermediate/section.rs | 19 ++++++++++++++----- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/src/context/element.rs b/src/context/element.rs index 37c605a..3825439 100644 --- a/src/context/element.rs +++ b/src/context/element.rs @@ -1,5 +1,22 @@ +use std::path::Path; + use serde::Serialize; +use crate::config::Config; +use crate::error::CustomError; +use crate::intermediate::IElement; + #[derive(Debug, Serialize)] #[serde(untagged)] pub(crate) enum RenderElement {} + +impl RenderElement { + pub(crate) fn new, F: AsRef>( + config: &Config, + output_directory: D, + output_file: F, + element: &IElement, + ) -> Result { + todo!() + } +} diff --git a/src/context/section.rs b/src/context/section.rs index 937422a..d614638 100644 --- a/src/context/section.rs +++ b/src/context/section.rs @@ -6,10 +6,14 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISection; +use super::RenderElement; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "section")] -pub(crate) struct RenderSection {} +pub(crate) struct RenderSection { + children: Vec, +} impl RenderSection { pub(crate) fn new, F: AsRef>( @@ -18,6 +22,12 @@ impl RenderSection { output_file: F, section: &ISection, ) -> Result { - Ok(RenderSection {}) + let children = section + .children + .iter() + .map(|obj| RenderElement::new(config, &output_directory, &output_file, obj)) + .collect::, _>>()?; + + Ok(RenderSection { children }) } } diff --git a/src/intermediate/element.rs b/src/intermediate/element.rs index 3aeafe0..36bc9b6 100644 --- a/src/intermediate/element.rs +++ b/src/intermediate/element.rs @@ -1,2 +1,40 @@ +use crate::error::CustomError; + +use super::registry::Registry; + #[derive(Debug)] pub(crate) enum IElement {} + +impl IElement { + pub(crate) fn new<'parse>( + registry: &mut Registry<'parse>, + elem: &organic::types::Element<'parse>, + ) -> Result { + match elem { + organic::types::Element::Paragraph(_) => todo!(), + organic::types::Element::PlainList(_) => todo!(), + organic::types::Element::CenterBlock(_) => todo!(), + organic::types::Element::QuoteBlock(_) => todo!(), + organic::types::Element::SpecialBlock(_) => todo!(), + organic::types::Element::DynamicBlock(_) => todo!(), + organic::types::Element::FootnoteDefinition(_) => todo!(), + organic::types::Element::Comment(_) => todo!(), + organic::types::Element::Drawer(_) => todo!(), + organic::types::Element::PropertyDrawer(_) => todo!(), + organic::types::Element::Table(_) => todo!(), + organic::types::Element::VerseBlock(_) => todo!(), + organic::types::Element::CommentBlock(_) => todo!(), + organic::types::Element::ExampleBlock(_) => todo!(), + organic::types::Element::ExportBlock(_) => todo!(), + organic::types::Element::SrcBlock(_) => todo!(), + organic::types::Element::Clock(_) => todo!(), + organic::types::Element::DiarySexp(_) => todo!(), + organic::types::Element::Planning(_) => todo!(), + organic::types::Element::FixedWidthArea(_) => todo!(), + organic::types::Element::HorizontalRule(_) => todo!(), + organic::types::Element::Keyword(_) => todo!(), + organic::types::Element::BabelCall(_) => todo!(), + organic::types::Element::LatexEnvironment(_) => todo!(), + } + } +} diff --git a/src/intermediate/section.rs b/src/intermediate/section.rs index 2afd831..5e129e9 100644 --- a/src/intermediate/section.rs +++ b/src/intermediate/section.rs @@ -1,15 +1,24 @@ use crate::error::CustomError; use super::registry::Registry; +use super::IElement; #[derive(Debug)] -pub(crate) struct ISection {} +pub(crate) struct ISection { + pub(crate) children: Vec, +} impl ISection { - pub(crate) fn new( - registry: &mut Registry<'_>, - section: &organic::types::Section<'_>, + pub(crate) fn new<'parse>( + registry: &mut Registry<'parse>, + section: &organic::types::Section<'parse>, ) -> Result { - Ok(ISection {}) + let children = section + .children + .iter() + .map(|obj| IElement::new(registry, obj)) + .collect::, _>>()?; + + Ok(ISection { children }) } }