From e3b5f7f74f8c5b53ed369f46416067add6b70a6b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 27 Oct 2023 13:05:34 -0400 Subject: [PATCH] Rename blog_post module to intermediate. This module is mostly the intermediate representation of the AST, so the renaming is to make that more clear. The three forms are parsed => intermediate => render. Parsed comes from Organic and is a direct translation of the org-mode text. Intermediate converts the parsed data into owned values and does any calculations that are needed on the data (for example: assigning numbers to footnotes.) Render takes intermediate and translates it into the format expected by the dust templates. The processing in this step should be minimal since all the logic should be in the intermediate step. --- src/blog_post/document_element.rs | 8 -------- src/blog_post/element.rs | 2 -- src/command/build/render.rs | 4 ++-- src/command/build/runner.rs | 2 +- src/context/heading.rs | 4 ++-- src/context/object.rs | 6 +++--- src/context/plain_text.rs | 4 ++-- src/context/section.rs | 4 ++-- src/{blog_post => intermediate}/convert.rs | 6 +++--- src/{blog_post => intermediate}/definition.rs | 4 ++-- src/intermediate/document_element.rs | 8 ++++++++ src/intermediate/element.rs | 2 ++ src/{blog_post => intermediate}/heading.rs | 14 +++++++------- src/{blog_post => intermediate}/mod.rs | 12 ++++++------ src/{blog_post => intermediate}/object.rs | 12 ++++++------ src/{blog_post => intermediate}/page.rs | 12 ++++++------ src/{blog_post => intermediate}/plain_text.rs | 10 +++++----- src/{blog_post => intermediate}/section.rs | 8 ++++---- src/{blog_post => intermediate}/util.rs | 0 src/main.rs | 6 +++--- 20 files changed, 64 insertions(+), 64 deletions(-) delete mode 100644 src/blog_post/document_element.rs delete mode 100644 src/blog_post/element.rs rename src/{blog_post => intermediate}/convert.rs (97%) rename src/{blog_post => intermediate}/definition.rs (97%) create mode 100644 src/intermediate/document_element.rs create mode 100644 src/intermediate/element.rs rename src/{blog_post => intermediate}/heading.rs (65%) rename src/{blog_post => intermediate}/mod.rs (55%) rename src/{blog_post => intermediate}/object.rs (90%) rename src/{blog_post => intermediate}/page.rs (83%) rename src/{blog_post => intermediate}/plain_text.rs (58%) rename src/{blog_post => intermediate}/section.rs (54%) rename src/{blog_post => intermediate}/util.rs (100%) diff --git a/src/blog_post/document_element.rs b/src/blog_post/document_element.rs deleted file mode 100644 index ab0f28a..0000000 --- a/src/blog_post/document_element.rs +++ /dev/null @@ -1,8 +0,0 @@ -use super::Heading; -use super::Section; - -#[derive(Debug)] -pub(crate) enum DocumentElement { - Heading(Heading), - Section(Section), -} diff --git a/src/blog_post/element.rs b/src/blog_post/element.rs deleted file mode 100644 index bb64b91..0000000 --- a/src/blog_post/element.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[derive(Debug)] -pub(crate) enum Element {} diff --git a/src/command/build/render.rs b/src/command/build/render.rs index 04a73f6..853028a 100644 --- a/src/command/build/render.rs +++ b/src/command/build/render.rs @@ -4,10 +4,10 @@ use std::path::PathBuf; use include_dir::include_dir; use include_dir::Dir; -use crate::blog_post::convert_blog_post_page_to_render_context; -use crate::blog_post::BlogPost; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::convert_blog_post_page_to_render_context; +use crate::intermediate::BlogPost; use crate::render::DusterRenderer; use crate::render::RendererIntegration; diff --git a/src/command/build/runner.rs b/src/command/build/runner.rs index bb267f6..13dc846 100644 --- a/src/command/build/runner.rs +++ b/src/command/build/runner.rs @@ -1,10 +1,10 @@ use std::path::PathBuf; -use crate::blog_post::BlogPost; use crate::cli::parameters::BuildArgs; use crate::command::build::render::SiteRenderer; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::BlogPost; pub(crate) async fn build_site(args: BuildArgs) -> Result<(), CustomError> { let config = Config::load_from_file(args.config).await?; diff --git a/src/context/heading.rs b/src/context/heading.rs index 1192e78..c609c5a 100644 --- a/src/context/heading.rs +++ b/src/context/heading.rs @@ -2,9 +2,9 @@ use std::path::Path; use serde::Serialize; -use crate::blog_post::Heading; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::IHeading; use super::RenderObject; @@ -21,7 +21,7 @@ impl RenderHeading { config: &Config, output_directory: D, output_file: F, - heading: &Heading, + heading: &IHeading, ) -> Result { let title = heading .title diff --git a/src/context/object.rs b/src/context/object.rs index 558f1d2..8cccc88 100644 --- a/src/context/object.rs +++ b/src/context/object.rs @@ -2,9 +2,9 @@ use std::path::Path; use serde::Serialize; -use crate::blog_post::Object; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::IObject; use super::plain_text::RenderPlainText; @@ -19,10 +19,10 @@ impl RenderObject { config: &Config, output_directory: D, output_file: F, - object: &Object, + object: &IObject, ) -> Result { match object { - Object::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new( + IObject::PlainText(inner) => Ok(RenderObject::PlainText(RenderPlainText::new( config, output_directory, output_file, diff --git a/src/context/plain_text.rs b/src/context/plain_text.rs index aae8012..24bf142 100644 --- a/src/context/plain_text.rs +++ b/src/context/plain_text.rs @@ -2,9 +2,9 @@ use std::path::Path; use serde::Serialize; -use crate::blog_post::PlainText; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::IPlainText; #[derive(Debug, Serialize)] #[serde(tag = "type")] @@ -16,7 +16,7 @@ impl RenderPlainText { config: &Config, output_directory: D, output_file: F, - heading: &PlainText, + heading: &IPlainText, ) -> Result { Ok(RenderPlainText {}) } diff --git a/src/context/section.rs b/src/context/section.rs index ff11345..937422a 100644 --- a/src/context/section.rs +++ b/src/context/section.rs @@ -2,9 +2,9 @@ use std::path::Path; use serde::Serialize; -use crate::blog_post::Section; use crate::config::Config; use crate::error::CustomError; +use crate::intermediate::ISection; #[derive(Debug, Serialize)] #[serde(tag = "type")] @@ -16,7 +16,7 @@ impl RenderSection { config: &Config, output_directory: D, output_file: F, - section: &Section, + section: &ISection, ) -> Result { Ok(RenderSection {}) } diff --git a/src/blog_post/convert.rs b/src/intermediate/convert.rs similarity index 97% rename from src/blog_post/convert.rs rename to src/intermediate/convert.rs index cd321cd..f28ac59 100644 --- a/src/blog_post/convert.rs +++ b/src/intermediate/convert.rs @@ -12,7 +12,7 @@ use crate::error::CustomError; use super::BlogPost; use super::BlogPostPage; -use super::DocumentElement; +use super::IDocumentElement; pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef>( config: &Config, @@ -48,7 +48,7 @@ pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef< for child in page.children.iter() { match child { - DocumentElement::Heading(heading) => { + IDocumentElement::Heading(heading) => { children.push(RenderDocumentElement::Heading(RenderHeading::new( config, output_directory, @@ -56,7 +56,7 @@ pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef< heading, )?)); } - DocumentElement::Section(section) => { + IDocumentElement::Section(section) => { children.push(RenderDocumentElement::Section(RenderSection::new( config, output_directory, diff --git a/src/blog_post/definition.rs b/src/intermediate/definition.rs similarity index 97% rename from src/blog_post/definition.rs rename to src/intermediate/definition.rs index 019c422..c81053a 100644 --- a/src/blog_post/definition.rs +++ b/src/intermediate/definition.rs @@ -7,13 +7,13 @@ use walkdir::WalkDir; use crate::error::CustomError; use super::BlogPostPage; -use super::DocumentElement; +use super::IDocumentElement; #[derive(Debug)] pub(crate) struct BlogPost { pub(crate) id: String, pub(crate) pages: Vec, - pub(crate) children: Vec, + pub(crate) children: Vec, } impl BlogPost { diff --git a/src/intermediate/document_element.rs b/src/intermediate/document_element.rs new file mode 100644 index 0000000..3f35270 --- /dev/null +++ b/src/intermediate/document_element.rs @@ -0,0 +1,8 @@ +use super::IHeading; +use super::ISection; + +#[derive(Debug)] +pub(crate) enum IDocumentElement { + Heading(IHeading), + Section(ISection), +} diff --git a/src/intermediate/element.rs b/src/intermediate/element.rs new file mode 100644 index 0000000..3aeafe0 --- /dev/null +++ b/src/intermediate/element.rs @@ -0,0 +1,2 @@ +#[derive(Debug)] +pub(crate) enum IElement {} diff --git a/src/blog_post/heading.rs b/src/intermediate/heading.rs similarity index 65% rename from src/blog_post/heading.rs rename to src/intermediate/heading.rs index 57a5da8..c8bb925 100644 --- a/src/blog_post/heading.rs +++ b/src/intermediate/heading.rs @@ -1,21 +1,21 @@ use crate::error::CustomError; -use super::Object; +use super::IObject; #[derive(Debug)] -pub(crate) struct Heading { +pub(crate) struct IHeading { pub(crate) level: organic::types::HeadlineLevel, - pub(crate) title: Vec, + pub(crate) title: Vec, } -impl Heading { - pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result { +impl IHeading { + pub(crate) fn new(heading: &organic::types::Heading<'_>) -> Result { let title = heading .title .iter() - .map(Object::new) + .map(IObject::new) .collect::, _>>()?; - Ok(Heading { + Ok(IHeading { title, level: heading.level, }) diff --git a/src/blog_post/mod.rs b/src/intermediate/mod.rs similarity index 55% rename from src/blog_post/mod.rs rename to src/intermediate/mod.rs index fae23ec..b8760ff 100644 --- a/src/blog_post/mod.rs +++ b/src/intermediate/mod.rs @@ -10,10 +10,10 @@ mod section; mod util; pub(crate) use convert::convert_blog_post_page_to_render_context; pub(crate) use definition::BlogPost; -pub(crate) use document_element::DocumentElement; -pub(crate) use element::Element; -pub(crate) use heading::Heading; -pub(crate) use object::Object; +pub(crate) use document_element::IDocumentElement; +pub(crate) use element::IElement; +pub(crate) use heading::IHeading; +pub(crate) use object::IObject; pub(crate) use page::BlogPostPage; -pub(crate) use plain_text::PlainText; -pub(crate) use section::Section; +pub(crate) use plain_text::IPlainText; +pub(crate) use section::ISection; diff --git a/src/blog_post/object.rs b/src/intermediate/object.rs similarity index 90% rename from src/blog_post/object.rs rename to src/intermediate/object.rs index b758ac3..f15e90f 100644 --- a/src/blog_post/object.rs +++ b/src/intermediate/object.rs @@ -1,14 +1,14 @@ use crate::error::CustomError; -use super::plain_text::PlainText; +use super::plain_text::IPlainText; #[derive(Debug)] -pub(crate) enum Object { - PlainText(PlainText), +pub(crate) enum IObject { + PlainText(IPlainText), } -impl Object { - pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result { +impl IObject { + pub(crate) fn new(obj: &organic::types::Object<'_>) -> Result { match obj { organic::types::Object::Bold(_) => todo!(), organic::types::Object::Italic(_) => todo!(), @@ -17,7 +17,7 @@ impl Object { organic::types::Object::Code(_) => todo!(), organic::types::Object::Verbatim(_) => todo!(), organic::types::Object::PlainText(plain_text) => { - Ok(Object::PlainText(PlainText::new(plain_text)?)) + Ok(IObject::PlainText(IPlainText::new(plain_text)?)) } organic::types::Object::RegularLink(_) => todo!(), organic::types::Object::RadioLink(_) => todo!(), diff --git a/src/blog_post/page.rs b/src/intermediate/page.rs similarity index 83% rename from src/blog_post/page.rs rename to src/intermediate/page.rs index 7a7aab1..fde0ce8 100644 --- a/src/blog_post/page.rs +++ b/src/intermediate/page.rs @@ -2,9 +2,9 @@ use std::path::PathBuf; use crate::error::CustomError; -use super::DocumentElement; -use super::Heading; -use super::Section; +use super::IDocumentElement; +use super::IHeading; +use super::ISection; #[derive(Debug)] pub(crate) struct BlogPostPage { @@ -13,7 +13,7 @@ pub(crate) struct BlogPostPage { pub(crate) title: Option, - pub(crate) children: Vec, + pub(crate) children: Vec, } impl BlogPostPage { @@ -24,10 +24,10 @@ impl BlogPostPage { let path = path.into(); let mut children = Vec::new(); if let Some(section) = document.zeroth_section.as_ref() { - children.push(DocumentElement::Section(Section::new(section)?)); + children.push(IDocumentElement::Section(ISection::new(section)?)); } for heading in document.children.iter() { - children.push(DocumentElement::Heading(Heading::new(heading)?)); + children.push(IDocumentElement::Heading(IHeading::new(heading)?)); } Ok(BlogPostPage { diff --git a/src/blog_post/plain_text.rs b/src/intermediate/plain_text.rs similarity index 58% rename from src/blog_post/plain_text.rs rename to src/intermediate/plain_text.rs index e62191f..24cebb2 100644 --- a/src/blog_post/plain_text.rs +++ b/src/intermediate/plain_text.rs @@ -1,16 +1,16 @@ -use crate::blog_post::util::coalesce_whitespace; use crate::error::CustomError; +use crate::intermediate::util::coalesce_whitespace; #[derive(Debug)] -pub(crate) struct PlainText { +pub(crate) struct IPlainText { source: String, } -impl PlainText { +impl IPlainText { pub(crate) fn new( plain_text: &organic::types::PlainText<'_>, - ) -> Result { - Ok(PlainText { + ) -> Result { + Ok(IPlainText { source: coalesce_whitespace(plain_text.source).into_owned(), }) } diff --git a/src/blog_post/section.rs b/src/intermediate/section.rs similarity index 54% rename from src/blog_post/section.rs rename to src/intermediate/section.rs index b7b888d..d7b0069 100644 --- a/src/blog_post/section.rs +++ b/src/intermediate/section.rs @@ -1,10 +1,10 @@ use crate::error::CustomError; #[derive(Debug)] -pub(crate) struct Section {} +pub(crate) struct ISection {} -impl Section { - pub(crate) fn new(section: &organic::types::Section<'_>) -> Result { - Ok(Section {}) +impl ISection { + pub(crate) fn new(section: &organic::types::Section<'_>) -> Result { + Ok(ISection {}) } } diff --git a/src/blog_post/util.rs b/src/intermediate/util.rs similarity index 100% rename from src/blog_post/util.rs rename to src/intermediate/util.rs diff --git a/src/main.rs b/src/main.rs index e280cc7..d2d3edd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,13 +7,13 @@ use self::cli::parameters::Commands; use self::command::build::build_site; use self::command::init::init_writer_folder; use self::error::CustomError; -mod blog_post; mod cli; mod command; mod config; -mod error; -mod render; mod context; +mod error; +mod intermediate; +mod render; fn main() -> Result { let rt = tokio::runtime::Runtime::new()?;