70 lines
2.0 KiB
Rust
70 lines
2.0 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
use super::additional_property::AdditionalProperties;
|
|
use super::additional_property::AdditionalPropertyValue;
|
|
use super::ast_node::WasmAstNode;
|
|
use super::macros::to_wasm;
|
|
use super::to_wasm::ToWasm;
|
|
use crate::compare::ElispFact;
|
|
use crate::types::Document;
|
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct WasmDocument {
|
|
#[serde(flatten)]
|
|
pub(crate) additional_properties: AdditionalProperties,
|
|
#[serde(rename = "CATEGORY")]
|
|
pub(crate) category: Option<String>,
|
|
pub(crate) path: Option<PathBuf>,
|
|
}
|
|
|
|
to_wasm!(
|
|
WasmDocument,
|
|
Document<'s>,
|
|
original,
|
|
wasm_context,
|
|
{ WasmAstNode::Document(original) },
|
|
{ "org-data".into() },
|
|
{
|
|
let category = original.category.as_ref().map(String::as_str);
|
|
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(),
|
|
AdditionalPropertyValue::SingleString(node_property.value.unwrap_or("").to_owned()),
|
|
)
|
|
}) {
|
|
additional_properties.properties.insert(name, val);
|
|
}
|
|
|
|
let children = original
|
|
.zeroth_section
|
|
.iter()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.chain(original.children.iter().map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
}))
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
Ok((
|
|
children,
|
|
WasmDocument {
|
|
additional_properties,
|
|
category: category.map(str::to_owned),
|
|
path,
|
|
},
|
|
))
|
|
}
|
|
);
|