From 67e5829fd96458663fdaa5142cd58f1ee4b721db Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 25 Dec 2023 12:55:48 -0500 Subject: [PATCH] Populating document's children. --- src/wasm/ast_node.rs | 3 ++- src/wasm/document.rs | 22 ++++++++++++++++++++-- src/wasm/headline.rs | 10 ++++++++-- src/wasm/macros.rs | 3 ++- src/wasm/section.rs | 10 ++++++++-- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/wasm/ast_node.rs b/src/wasm/ast_node.rs index bc425bb..c6571ec 100644 --- a/src/wasm/ast_node.rs +++ b/src/wasm/ast_node.rs @@ -60,10 +60,11 @@ use super::verbatim::WasmVerbatim; use super::verse_block::WasmVerseBlock; #[derive(Debug, Serialize)] +#[serde(untagged)] pub enum WasmAstNode<'s> { // Document Nodes Document(WasmDocument<'s>), - Heading(WasmHeadline<'s>), + Headline(WasmHeadline<'s>), Section(WasmSection<'s>), // Elements Paragraph(WasmParagraph<'s>), diff --git a/src/wasm/document.rs b/src/wasm/document.rs index 0a36b17..cf0a838 100644 --- a/src/wasm/document.rs +++ b/src/wasm/document.rs @@ -33,16 +33,34 @@ to_wasm!( }) .collect(); + let children = original + .zeroth_section + .iter() + .map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::>::into) + }) + .chain(original.children.iter().map(|child| { + child + .to_wasm(wasm_context.clone()) + .map(Into::>::into) + })) + .collect::, _>>()?; // let children = original // .children // .iter() - // .map(|child| child.to_wasm(wasm_context.clone())) + // .map(|child| { + // child + // .to_wasm(wasm_context.clone()) + // .map(Into::>::into) + // }) // .collect::, _>>()?; Ok(WasmDocument { standard_properties, additional_properties, - children: Vec::new(), + children, }) } ); diff --git a/src/wasm/headline.rs b/src/wasm/headline.rs index 2025854..490a423 100644 --- a/src/wasm/headline.rs +++ b/src/wasm/headline.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; use organic::types::Heading; -use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; @@ -11,7 +11,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize)] #[serde(tag = "ast_node")] -#[serde(rename = "org-data")] +#[serde(rename = "headline")] pub(crate) struct WasmHeadline<'s> { standard_properties: WasmStandardProperties, children: Vec<()>, @@ -32,3 +32,9 @@ to_wasm!( }) } ); + +impl<'s> Into> for WasmHeadline<'s> { + fn into(self) -> WasmAstNode<'s> { + WasmAstNode::Headline(self) + } +} diff --git a/src/wasm/macros.rs b/src/wasm/macros.rs index 333086f..82e4de1 100644 --- a/src/wasm/macros.rs +++ b/src/wasm/macros.rs @@ -11,7 +11,8 @@ macro_rules! to_wasm { $wasm_context: crate::wasm::to_wasm::ToWasmContext<'_>, ) -> Result { let $original = self; - let $standard_properties = self.to_wasm_standard_properties($wasm_context)?; + let $standard_properties = + self.to_wasm_standard_properties($wasm_context.clone())?; $fnbody } } diff --git a/src/wasm/section.rs b/src/wasm/section.rs index 615b8fd..e534e35 100644 --- a/src/wasm/section.rs +++ b/src/wasm/section.rs @@ -1,9 +1,9 @@ use std::marker::PhantomData; use organic::types::Section; -use serde::Deserialize; use serde::Serialize; +use super::ast_node::WasmAstNode; use super::macros::to_wasm; use super::standard_properties::WasmStandardProperties; use super::to_wasm::ToWasm; @@ -11,7 +11,7 @@ use crate::wasm::to_wasm::ToWasmStandardProperties; #[derive(Debug, Serialize)] #[serde(tag = "ast_node")] -#[serde(rename = "org-data")] +#[serde(rename = "section")] pub(crate) struct WasmSection<'s> { standard_properties: WasmStandardProperties, children: Vec<()>, @@ -32,3 +32,9 @@ to_wasm!( }) } ); + +impl<'s> Into> for WasmSection<'s> { + fn into(self) -> WasmAstNode<'s> { + WasmAstNode::Section(self) + } +}