141 lines
4.9 KiB
Rust
141 lines
4.9 KiB
Rust
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
|
|
use super::ast_node::WasmAstNode;
|
|
use super::macros::to_wasm;
|
|
use super::to_wasm::ToWasm;
|
|
use super::AdditionalProperties;
|
|
use super::AdditionalPropertyValue;
|
|
use crate::util::elisp_fact::ElispFact;
|
|
use crate::types::Heading;
|
|
use crate::types::HeadlineLevel;
|
|
use crate::types::PriorityCookie;
|
|
use crate::types::TodoKeywordType;
|
|
use crate::wasm::to_wasm::ToWasmStandardProperties;
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct WasmHeadline {
|
|
#[serde(flatten)]
|
|
pub(crate) additional_properties: AdditionalProperties,
|
|
pub(crate) level: HeadlineLevel,
|
|
pub(crate) tags: Vec<String>,
|
|
#[serde(rename = "todo-keyword")]
|
|
pub(crate) todo_keyword: Option<String>,
|
|
#[serde(rename = "todo-type")]
|
|
pub(crate) todo_type: Option<String>,
|
|
pub(crate) title: Vec<WasmAstNode>,
|
|
pub(crate) priority: Option<PriorityCookie>,
|
|
#[serde(rename = "archivedp")]
|
|
pub(crate) is_archived: bool,
|
|
#[serde(rename = "commentedp")]
|
|
pub(crate) is_comment: bool,
|
|
#[serde(rename = "raw-value")]
|
|
pub(crate) raw_value: String,
|
|
#[serde(rename = "footnote-section-p")]
|
|
pub(crate) is_footnote_section: bool,
|
|
pub(crate) scheduled: Option<Box<WasmAstNode>>,
|
|
pub(crate) deadline: Option<Box<WasmAstNode>>,
|
|
pub(crate) closed: Option<Box<WasmAstNode>>,
|
|
#[serde(rename = "pre-blank")]
|
|
pub(crate) pre_blank: Noop,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
#[serde(tag = "noop")]
|
|
pub struct Noop {}
|
|
|
|
to_wasm!(
|
|
WasmHeadline,
|
|
Heading<'s>,
|
|
original,
|
|
wasm_context,
|
|
{ WasmAstNode::Headline(original) },
|
|
{ "headline".into() },
|
|
{
|
|
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
|
|
.children
|
|
.iter()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
Ok((
|
|
children,
|
|
WasmHeadline {
|
|
additional_properties,
|
|
level: original.level,
|
|
tags: original.tags.iter().map(|tag| (*tag).to_owned()).collect(),
|
|
todo_keyword: original
|
|
.todo_keyword
|
|
.as_ref()
|
|
.map(|(_, keyword)| (*keyword).to_owned()),
|
|
todo_type: original
|
|
.todo_keyword
|
|
.as_ref()
|
|
.map(|(keyword, _)| match keyword {
|
|
TodoKeywordType::Done => "done".to_owned(),
|
|
TodoKeywordType::Todo => "todo".to_owned(),
|
|
}),
|
|
title: original
|
|
.title
|
|
.iter()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.collect::<Result<Vec<_>, _>>()?,
|
|
priority: original.priority_cookie,
|
|
is_archived: original.is_archived,
|
|
is_comment: original.is_comment,
|
|
raw_value: original.get_raw_value(),
|
|
is_footnote_section: original.is_footnote_section,
|
|
scheduled: original
|
|
.scheduled
|
|
.as_ref()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.map_or(Ok(None), |r| r.map(Some))?
|
|
.map(|child| Box::new(child)),
|
|
deadline: original
|
|
.deadline
|
|
.as_ref()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.map_or(Ok(None), |r| r.map(Some))?
|
|
.map(|child| Box::new(child)),
|
|
closed: original
|
|
.closed
|
|
.as_ref()
|
|
.map(|child| {
|
|
child
|
|
.to_wasm(wasm_context.clone())
|
|
.map(Into::<WasmAstNode>::into)
|
|
})
|
|
.map_or(Ok(None), |r| r.map(Some))?
|
|
.map(|child| Box::new(child)),
|
|
pre_blank: Noop {},
|
|
},
|
|
))
|
|
}
|
|
);
|