Compare commits

...

5 Commits

Author SHA1 Message Date
Tom Alexander
354d24cf69
Add comment as a no-op. 2023-10-27 16:14:37 -04:00
Tom Alexander
5891ac7fb7
Add keyword and as no-op. 2023-10-27 16:09:44 -04:00
Tom Alexander
f9377d7609
Make converstion to intermediate state async.
We are going to need to do things like call external tools for syntax highlighting so we are going to need async in there eventually.
2023-10-27 15:55:19 -04:00
Tom Alexander
4a6948cde7
Add paragraph. 2023-10-27 15:46:56 -04:00
Tom Alexander
5b34942b64
Add element. 2023-10-27 15:46:56 -04:00
19 changed files with 303 additions and 33 deletions

23
src/context/comment.rs Normal file
View File

@ -0,0 +1,23 @@
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IComment;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "comment")]
pub(crate) struct RenderComment {}
impl RenderComment {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
comment: &IComment,
) -> Result<RenderComment, CustomError> {
Ok(RenderComment {})
}
}

View File

@ -1,5 +1,49 @@
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IElement;
use super::comment::RenderComment;
use super::keyword::RenderKeyword;
use super::paragraph::RenderParagraph;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderElement {}
pub(crate) enum RenderElement {
Paragraph(RenderParagraph),
Keyword(RenderKeyword),
Comment(RenderComment),
}
impl RenderElement {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
element: &IElement,
) -> Result<RenderElement, CustomError> {
match element {
IElement::Paragraph(inner) => Ok(RenderElement::Paragraph(RenderParagraph::new(
config,
output_directory,
output_file,
inner,
)?)),
IElement::Keyword(inner) => Ok(RenderElement::Keyword(RenderKeyword::new(
config,
output_directory,
output_file,
inner,
)?)),
IElement::Comment(inner) => Ok(RenderElement::Comment(RenderComment::new(
config,
output_directory,
output_file,
inner,
)?)),
}
}
}

23
src/context/keyword.rs Normal file
View File

@ -0,0 +1,23 @@
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IKeyword;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "keyword")]
pub(crate) struct RenderKeyword {}
impl RenderKeyword {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
keyword: &IKeyword,
) -> Result<RenderKeyword, CustomError> {
Ok(RenderKeyword {})
}
}

View File

@ -1,9 +1,12 @@
mod blog_post_page;
mod comment;
mod document_element;
mod element;
mod global_settings;
mod heading;
mod keyword;
mod object;
mod paragraph;
mod plain_text;
mod section;
mod target;

32
src/context/paragraph.rs Normal file
View File

@ -0,0 +1,32 @@
use std::path::Path;
use serde::Serialize;
use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::IParagraph;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "paragraph")]
pub(crate) struct RenderParagraph {
children: Vec<RenderObject>,
}
impl RenderParagraph {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
config: &Config,
output_directory: D,
output_file: F,
paragraph: &IParagraph,
) -> Result<RenderParagraph, CustomError> {
let children = paragraph
.children
.iter()
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
.collect::<Result<Vec<_>, _>>()?;
Ok(RenderParagraph { children })
}
}

View File

@ -8,7 +8,7 @@ use crate::intermediate::IPlainText;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "heading")]
#[serde(rename = "plain_text")]
pub(crate) struct RenderPlainText {}
impl RenderPlainText {

View File

@ -6,10 +6,14 @@ use crate::config::Config;
use crate::error::CustomError;
use crate::intermediate::ISection;
use super::RenderElement;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "section")]
pub(crate) struct RenderSection {}
pub(crate) struct RenderSection {
children: Vec<RenderElement>,
}
impl RenderSection {
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
@ -18,6 +22,12 @@ impl RenderSection {
output_file: F,
section: &ISection,
) -> Result<RenderSection, CustomError> {
Ok(RenderSection {})
let children = section
.children
.iter()
.map(|obj| RenderElement::new(config, &output_directory, &output_file, obj))
.collect::<Result<Vec<_>, _>>()?;
Ok(RenderSection { children })
}
}

View File

@ -0,0 +1,16 @@
use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the comment is not rendered.
#[derive(Debug)]
pub(crate) struct IComment {}
impl IComment {
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
comment: &organic::types::Comment<'parse>,
) -> Result<IComment, CustomError> {
Ok(IComment {})
}
}

View File

@ -61,11 +61,14 @@ impl BlogPost {
let mut ret = Vec::new();
for (real_path, _contents, parsed_document) in parsed_org_files.iter() {
let relative_to_post_dir_path = real_path.strip_prefix(post_dir)?;
ret.push(BlogPostPage::new(
relative_to_post_dir_path,
&mut registry,
parsed_document,
)?);
ret.push(
BlogPostPage::new(
relative_to_post_dir_path,
&mut registry,
parsed_document,
)
.await?,
);
}
ret
};

View File

@ -1,2 +1,53 @@
use crate::error::CustomError;
use super::comment::IComment;
use super::keyword::IKeyword;
use super::registry::Registry;
use super::IParagraph;
#[derive(Debug)]
pub(crate) enum IElement {}
pub(crate) enum IElement {
Paragraph(IParagraph),
Keyword(IKeyword),
Comment(IComment),
}
impl IElement {
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
elem: &organic::types::Element<'parse>,
) -> Result<IElement, CustomError> {
match elem {
organic::types::Element::Paragraph(inner) => {
Ok(IElement::Paragraph(IParagraph::new(registry, inner).await?))
}
organic::types::Element::PlainList(_) => todo!(),
organic::types::Element::CenterBlock(_) => todo!(),
organic::types::Element::QuoteBlock(_) => todo!(),
organic::types::Element::SpecialBlock(_) => todo!(),
organic::types::Element::DynamicBlock(_) => todo!(),
organic::types::Element::FootnoteDefinition(_) => todo!(),
organic::types::Element::Comment(inner) => {
Ok(IElement::Comment(IComment::new(registry, inner).await?))
}
organic::types::Element::Drawer(_) => todo!(),
organic::types::Element::PropertyDrawer(_) => todo!(),
organic::types::Element::Table(_) => todo!(),
organic::types::Element::VerseBlock(_) => todo!(),
organic::types::Element::CommentBlock(_) => todo!(),
organic::types::Element::ExampleBlock(_) => todo!(),
organic::types::Element::ExportBlock(_) => todo!(),
organic::types::Element::SrcBlock(_) => todo!(),
organic::types::Element::Clock(_) => todo!(),
organic::types::Element::DiarySexp(_) => todo!(),
organic::types::Element::Planning(_) => todo!(),
organic::types::Element::FixedWidthArea(_) => todo!(),
organic::types::Element::HorizontalRule(_) => todo!(),
organic::types::Element::Keyword(inner) => {
Ok(IElement::Keyword(IKeyword::new(registry, inner).await?))
}
organic::types::Element::BabelCall(_) => todo!(),
organic::types::Element::LatexEnvironment(_) => todo!(),
}
}
}

View File

@ -10,15 +10,17 @@ pub(crate) struct IHeading {
}
impl IHeading {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
heading: &organic::types::Heading<'parse>,
) -> Result<IHeading, CustomError> {
let title = heading
.title
.iter()
.map(|obj| IObject::new(registry, obj))
.collect::<Result<Vec<_>, _>>()?;
let title = {
let mut ret = Vec::new();
for obj in heading.title.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IHeading {
title,
level: heading.level,

View File

@ -0,0 +1,16 @@
use crate::error::CustomError;
use super::registry::Registry;
/// Essentially a no-op since the keyword is not rendered and any relevant impact on other elements is pulled from the parsed form of keyword.
#[derive(Debug)]
pub(crate) struct IKeyword {}
impl IKeyword {
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
keyword: &organic::types::Keyword<'parse>,
) -> Result<IKeyword, CustomError> {
Ok(IKeyword {})
}
}

View File

@ -1,22 +1,28 @@
mod comment;
mod convert;
mod definition;
mod document_element;
mod element;
mod heading;
mod keyword;
mod object;
mod page;
mod paragraph;
mod plain_text;
mod registry;
mod section;
mod target;
mod util;
pub(crate) use comment::IComment;
pub(crate) use convert::convert_blog_post_page_to_render_context;
pub(crate) use definition::BlogPost;
pub(crate) use document_element::IDocumentElement;
pub(crate) use element::IElement;
pub(crate) use heading::IHeading;
pub(crate) use keyword::IKeyword;
pub(crate) use object::IObject;
pub(crate) use page::BlogPostPage;
pub(crate) use paragraph::IParagraph;
pub(crate) use plain_text::IPlainText;
pub(crate) use section::ISection;
pub(crate) use target::ITarget;

View File

@ -11,7 +11,7 @@ pub(crate) enum IObject {
}
impl IObject {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
obj: &organic::types::Object<'parse>,
) -> Result<IObject, CustomError> {
@ -22,8 +22,8 @@ impl IObject {
organic::types::Object::StrikeThrough(_) => todo!(),
organic::types::Object::Code(_) => todo!(),
organic::types::Object::Verbatim(_) => todo!(),
organic::types::Object::PlainText(plain_text) => {
Ok(IObject::PlainText(IPlainText::new(registry, plain_text)?))
organic::types::Object::PlainText(inner) => {
Ok(IObject::PlainText(IPlainText::new(registry, inner).await?))
}
organic::types::Object::RegularLink(_) => todo!(),
organic::types::Object::RadioLink(_) => todo!(),
@ -40,8 +40,8 @@ impl IObject {
organic::types::Object::InlineBabelCall(_) => todo!(),
organic::types::Object::InlineSourceBlock(_) => todo!(),
organic::types::Object::LineBreak(_) => todo!(),
organic::types::Object::Target(target) => {
Ok(IObject::Target(ITarget::new(registry, target)?))
organic::types::Object::Target(inner) => {
Ok(IObject::Target(ITarget::new(registry, inner).await?))
}
organic::types::Object::StatisticsCookie(_) => todo!(),
organic::types::Object::Subscript(_) => todo!(),

View File

@ -18,7 +18,7 @@ pub(crate) struct BlogPostPage {
}
impl BlogPostPage {
pub(crate) fn new<'parse, P: Into<PathBuf>>(
pub(crate) async fn new<'parse, P: Into<PathBuf>>(
path: P,
registry: &mut Registry<'parse>,
document: &organic::types::Document<'parse>,
@ -26,10 +26,14 @@ impl BlogPostPage {
let path = path.into();
let mut children = Vec::new();
if let Some(section) = document.zeroth_section.as_ref() {
children.push(IDocumentElement::Section(ISection::new(registry, section)?));
children.push(IDocumentElement::Section(
ISection::new(registry, section).await?,
));
}
for heading in document.children.iter() {
children.push(IDocumentElement::Heading(IHeading::new(registry, heading)?));
children.push(IDocumentElement::Heading(
IHeading::new(registry, heading).await?,
));
}
Ok(BlogPostPage {

View File

@ -0,0 +1,26 @@
use crate::error::CustomError;
use super::registry::Registry;
use super::IObject;
#[derive(Debug)]
pub(crate) struct IParagraph {
pub(crate) children: Vec<IObject>,
}
impl IParagraph {
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
paragraph: &organic::types::Paragraph<'parse>,
) -> Result<IParagraph, CustomError> {
let children = {
let mut ret = Vec::new();
for obj in paragraph.children.iter() {
ret.push(IObject::new(registry, obj).await?);
}
ret
};
Ok(IParagraph { children })
}
}

View File

@ -9,9 +9,9 @@ pub(crate) struct IPlainText {
}
impl IPlainText {
pub(crate) fn new(
registry: &mut Registry<'_>,
plain_text: &organic::types::PlainText<'_>,
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
plain_text: &organic::types::PlainText<'parse>,
) -> Result<IPlainText, CustomError> {
Ok(IPlainText {
source: coalesce_whitespace(plain_text.source).into_owned(),

View File

@ -1,15 +1,26 @@
use crate::error::CustomError;
use super::registry::Registry;
use super::IElement;
#[derive(Debug)]
pub(crate) struct ISection {}
pub(crate) struct ISection {
pub(crate) children: Vec<IElement>,
}
impl ISection {
pub(crate) fn new(
registry: &mut Registry<'_>,
section: &organic::types::Section<'_>,
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
section: &organic::types::Section<'parse>,
) -> Result<ISection, CustomError> {
Ok(ISection {})
let children = {
let mut ret = Vec::new();
for elem in section.children.iter() {
ret.push(IElement::new(registry, elem).await?);
}
ret
};
Ok(ISection { children })
}
}

View File

@ -10,7 +10,7 @@ pub(crate) struct ITarget {
}
impl ITarget {
pub(crate) fn new<'parse>(
pub(crate) async fn new<'parse>(
registry: &mut Registry<'parse>,
target: &organic::types::Target<'parse>,
) -> Result<ITarget, CustomError> {