Files
organic/src/wasm/document.rs

71 lines
2.0 KiB
Rust
Raw Normal View History

2023-12-27 11:31:35 -05:00
use std::path::PathBuf;
2023-12-24 01:35:21 -05:00
use serde::Serialize;
use super::additional_property::AdditionalProperties;
use super::additional_property::AdditionalPropertyValue;
2023-12-25 11:51:39 -05:00
use super::ast_node::WasmAstNode;
use super::macros::new_to_wasm;
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 16:00:16 -05:00
#[cfg(feature = "wasm_test")]
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-25 12:42:38 -05:00
#[derive(Debug, Serialize)]
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,
#[serde(rename = "CATEGORY")]
2023-12-29 12:49:43 -05:00
pub(crate) category: Option<String>,
pub(crate) path: Option<PathBuf>,
2023-12-24 13:18:06 -05:00
}
2023-12-24 01:35:21 -05:00
new_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,
{ WasmAstNode::Document(original) },
{ "org-data".into() },
2023-12-24 15:48:33 -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();
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()),
)
}) {
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
Ok((
2023-12-25 12:55:48 -05:00
children,
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
);