2023-12-27 11:31:35 -05:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
use serde::Deserialize;
|
2023-12-24 01:35:21 -05:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
2023-12-27 18:01:56 -05:00
|
|
|
use super::additional_property::AdditionalProperties;
|
|
|
|
|
use super::additional_property::AdditionalPropertyValue;
|
2023-12-25 11:51:39 -05:00
|
|
|
use super::ast_node::WasmAstNode;
|
2023-12-24 13:18:06 -05:00
|
|
|
use super::macros::to_wasm;
|
2023-12-24 15:48:33 -05:00
|
|
|
use super::to_wasm::ToWasm;
|
2023-12-27 15:14:42 -05:00
|
|
|
use crate::compare::ElispFact;
|
2023-12-27 09:31:54 -05:00
|
|
|
use crate::types::Document;
|
2023-12-24 15:48:33 -05:00
|
|
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
2023-12-24 13:18:06 -05:00
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2023-12-29 12:49:43 -05:00
|
|
|
pub struct WasmDocument {
|
2023-12-29 10:04:59 -05:00
|
|
|
#[serde(flatten)]
|
2023-12-29 12:49:43 -05:00
|
|
|
pub(crate) additional_properties: AdditionalProperties,
|
2023-12-29 11:37:30 -05:00
|
|
|
#[serde(rename = "CATEGORY")]
|
2023-12-29 12:49:43 -05:00
|
|
|
pub(crate) category: Option<String>,
|
2023-12-27 15:58:31 -05:00
|
|
|
pub(crate) path: Option<PathBuf>,
|
2023-12-24 13:18:06 -05:00
|
|
|
}
|
2023-12-24 01:35:21 -05:00
|
|
|
|
2023-12-29 15:03:36 -05:00
|
|
|
to_wasm!(
|
2023-12-29 12:49:43 -05:00
|
|
|
WasmDocument,
|
2023-12-24 15:48:33 -05:00
|
|
|
Document<'s>,
|
2023-12-25 12:32:35 -05:00
|
|
|
original,
|
2023-12-24 15:48:33 -05:00
|
|
|
wasm_context,
|
2023-12-29 14:06:10 -05:00
|
|
|
{ WasmAstNode::Document(original) },
|
|
|
|
|
{ "org-data".into() },
|
2023-12-24 15:48:33 -05:00
|
|
|
{
|
2023-12-27 11:36:47 -05:00
|
|
|
let category = original.category.as_ref().map(String::as_str);
|
2023-12-27 11:31:35 -05:00
|
|
|
let path = original.path.clone();
|
|
|
|
|
|
2023-12-27 18:01:56 -05:00
|
|
|
let mut additional_properties = AdditionalProperties::default();
|
|
|
|
|
for (name, val) in original.get_additional_properties().map(|node_property| {
|
|
|
|
|
(
|
|
|
|
|
node_property.property_name.to_uppercase(),
|
2023-12-29 12:49:43 -05:00
|
|
|
AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("").to_owned()),
|
2023-12-27 18:01:56 -05:00
|
|
|
)
|
|
|
|
|
}) {
|
|
|
|
|
additional_properties.properties.insert(name, val);
|
|
|
|
|
}
|
2023-12-25 12:32:35 -05:00
|
|
|
|
2023-12-25 12:55:48 -05:00
|
|
|
let children = original
|
|
|
|
|
.zeroth_section
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|child| {
|
|
|
|
|
child
|
|
|
|
|
.to_wasm(wasm_context.clone())
|
2023-12-29 12:49:43 -05:00
|
|
|
.map(Into::<WasmAstNode>::into)
|
2023-12-25 12:55:48 -05:00
|
|
|
})
|
|
|
|
|
.chain(original.children.iter().map(|child| {
|
|
|
|
|
child
|
|
|
|
|
.to_wasm(wasm_context.clone())
|
2023-12-29 12:49:43 -05:00
|
|
|
.map(Into::<WasmAstNode>::into)
|
2023-12-25 12:55:48 -05:00
|
|
|
}))
|
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
2023-12-25 12:42:38 -05:00
|
|
|
|
2023-12-29 14:06:10 -05:00
|
|
|
Ok((
|
2023-12-25 12:55:48 -05:00
|
|
|
children,
|
2023-12-29 14:06:10 -05:00
|
|
|
WasmDocument {
|
|
|
|
|
additional_properties,
|
|
|
|
|
category: category.map(str::to_owned),
|
|
|
|
|
path,
|
|
|
|
|
},
|
|
|
|
|
))
|
2023-12-24 01:35:21 -05:00
|
|
|
}
|
2023-12-24 15:48:33 -05:00
|
|
|
);
|