diff --git a/Cargo.lock b/Cargo.lock index 44e485f..2d338e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,6 +71,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "backtrace" version = "0.3.69" @@ -192,6 +198,95 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" +[[package]] +name = "futures" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" + +[[package]] +name = "futures-executor" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" + +[[package]] +name = "futures-macro" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" + +[[package]] +name = "futures-task" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" + +[[package]] +name = "futures-util" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "gimli" version = "0.28.0" @@ -347,6 +442,12 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "proc-macro2" version = "1.0.69" @@ -432,6 +533,15 @@ dependencies = [ "serde", ] +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -641,6 +751,7 @@ version = "0.0.1" dependencies = [ "clap", "duster", + "futures", "include_dir", "organic", "serde", diff --git a/Cargo.toml b/Cargo.toml index 4026897..d79bda7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] clap = { version = "4.4.6", default-features = false, features = ["std", "color", "help", "derive"] } duster = { git = "https://code.fizz.buzz/talexander/duster.git", branch = "master" } +futures = "0.3.29" include_dir = "0.7.3" # TODO: This is temporary to work on the latest organic code. Eventually switch back to using the published crate. organic = { path = "../organic" } diff --git a/default_environment/templates/html/heading.dust b/default_environment/templates/html/heading.dust index 2a76948..856846d 100644 --- a/default_environment/templates/html/heading.dust +++ b/default_environment/templates/html/heading.dust @@ -1 +1,11 @@ -heading +{@lte key=.level value=4} + {#.title}{>object/}{/.title} +{:else} +
    +
  1. {#.title}{>object/}{/.title}
  2. +
+{/lte} + +{#.children} + {>document_element/} +{/.children} diff --git a/src/context/angle_link.rs b/src/context/angle_link.rs index 1d97bcf..72e6df0 100644 --- a/src/context/angle_link.rs +++ b/src/context/angle_link.rs @@ -12,10 +12,10 @@ use crate::intermediate::IAngleLink; pub(crate) struct RenderAngleLink {} impl RenderAngleLink { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IAngleLink, ) -> Result { Ok(RenderAngleLink {}) diff --git a/src/context/babel_call.rs b/src/context/babel_call.rs index cee5641..f8ca4fe 100644 --- a/src/context/babel_call.rs +++ b/src/context/babel_call.rs @@ -12,10 +12,10 @@ use crate::intermediate::IBabelCall; pub(crate) struct RenderBabelCall {} impl RenderBabelCall { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IBabelCall, ) -> Result { Ok(RenderBabelCall {}) diff --git a/src/context/bold.rs b/src/context/bold.rs index 1d4edd7..a6158f3 100644 --- a/src/context/bold.rs +++ b/src/context/bold.rs @@ -12,10 +12,10 @@ use crate::intermediate::IBold; pub(crate) struct RenderBold {} impl RenderBold { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IBold, ) -> Result { Ok(RenderBold {}) diff --git a/src/context/center_block.rs b/src/context/center_block.rs index c5e024f..c1c26d4 100644 --- a/src/context/center_block.rs +++ b/src/context/center_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::ICenterBlock; pub(crate) struct RenderCenterBlock {} impl RenderCenterBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ICenterBlock, ) -> Result { Ok(RenderCenterBlock {}) diff --git a/src/context/citation.rs b/src/context/citation.rs index 8e6ab3e..cea9028 100644 --- a/src/context/citation.rs +++ b/src/context/citation.rs @@ -12,10 +12,10 @@ use crate::intermediate::ICitation; pub(crate) struct RenderCitation {} impl RenderCitation { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ICitation, ) -> Result { Ok(RenderCitation {}) diff --git a/src/context/citation_reference.rs b/src/context/citation_reference.rs index e99800f..61d3d8c 100644 --- a/src/context/citation_reference.rs +++ b/src/context/citation_reference.rs @@ -12,10 +12,10 @@ use crate::intermediate::ICitationReference; pub(crate) struct RenderCitationReference {} impl RenderCitationReference { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ICitationReference, ) -> Result { Ok(RenderCitationReference {}) diff --git a/src/context/clock.rs b/src/context/clock.rs index dc32032..814db1d 100644 --- a/src/context/clock.rs +++ b/src/context/clock.rs @@ -12,10 +12,10 @@ use crate::intermediate::IClock; pub(crate) struct RenderClock {} impl RenderClock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IClock, ) -> Result { Ok(RenderClock {}) diff --git a/src/context/code.rs b/src/context/code.rs index cf90a0d..af4defe 100644 --- a/src/context/code.rs +++ b/src/context/code.rs @@ -12,10 +12,10 @@ use crate::intermediate::ICode; pub(crate) struct RenderCode {} impl RenderCode { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ICode, ) -> Result { Ok(RenderCode {}) diff --git a/src/context/comment.rs b/src/context/comment.rs index 713c220..73d94b0 100644 --- a/src/context/comment.rs +++ b/src/context/comment.rs @@ -12,10 +12,10 @@ use crate::intermediate::IComment; pub(crate) struct RenderComment {} impl RenderComment { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IComment, ) -> Result { Ok(RenderComment {}) diff --git a/src/context/comment_block.rs b/src/context/comment_block.rs index d4cf314..dbe6fd4 100644 --- a/src/context/comment_block.rs +++ b/src/context/comment_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::ICommentBlock; pub(crate) struct RenderCommentBlock {} impl RenderCommentBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ICommentBlock, ) -> Result { Ok(RenderCommentBlock {}) diff --git a/src/context/diary_sexp.rs b/src/context/diary_sexp.rs index 8a3e5f4..0513fb6 100644 --- a/src/context/diary_sexp.rs +++ b/src/context/diary_sexp.rs @@ -12,10 +12,10 @@ use crate::intermediate::IDiarySexp; pub(crate) struct RenderDiarySexp {} impl RenderDiarySexp { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IDiarySexp, ) -> Result { Ok(RenderDiarySexp {}) diff --git a/src/context/document_element.rs b/src/context/document_element.rs index 6b11e0b..f4f3283 100644 --- a/src/context/document_element.rs +++ b/src/context/document_element.rs @@ -1,5 +1,11 @@ +use std::path::Path; + use serde::Serialize; +use crate::config::Config; +use crate::error::CustomError; +use crate::intermediate::IDocumentElement; + use super::RenderHeading; use super::RenderSection; @@ -9,3 +15,21 @@ pub(crate) enum RenderDocumentElement { Heading(RenderHeading), Section(RenderSection), } + +impl RenderDocumentElement { + pub(crate) fn new( + config: &Config, + output_directory: &Path, + output_file: &Path, + original: &IDocumentElement, + ) -> Result { + match original { + IDocumentElement::Heading(inner) => Ok(RenderDocumentElement::Heading( + RenderHeading::new(config, output_directory, output_file, inner)?, + )), + IDocumentElement::Section(inner) => Ok(RenderDocumentElement::Section( + RenderSection::new(config, output_directory, output_file, inner)?, + )), + } + } +} diff --git a/src/context/drawer.rs b/src/context/drawer.rs index 1872b26..fca6c58 100644 --- a/src/context/drawer.rs +++ b/src/context/drawer.rs @@ -12,10 +12,10 @@ use crate::intermediate::IDrawer; pub(crate) struct RenderDrawer {} impl RenderDrawer { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IDrawer, ) -> Result { Ok(RenderDrawer {}) diff --git a/src/context/dynamic_block.rs b/src/context/dynamic_block.rs index 4535bf2..893d7c5 100644 --- a/src/context/dynamic_block.rs +++ b/src/context/dynamic_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IDynamicBlock; pub(crate) struct RenderDynamicBlock {} impl RenderDynamicBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IDynamicBlock, ) -> Result { Ok(RenderDynamicBlock {}) diff --git a/src/context/element.rs b/src/context/element.rs index 7d27ab6..026b812 100644 --- a/src/context/element.rs +++ b/src/context/element.rs @@ -61,10 +61,10 @@ pub(crate) enum RenderElement { } impl RenderElement { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, element: &IElement, ) -> Result { match element { diff --git a/src/context/entity.rs b/src/context/entity.rs index a395ed9..f888dc5 100644 --- a/src/context/entity.rs +++ b/src/context/entity.rs @@ -12,10 +12,10 @@ use crate::intermediate::IEntity; pub(crate) struct RenderEntity {} impl RenderEntity { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IEntity, ) -> Result { Ok(RenderEntity {}) diff --git a/src/context/example_block.rs b/src/context/example_block.rs index dec90ab..1d37711 100644 --- a/src/context/example_block.rs +++ b/src/context/example_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IExampleBlock; pub(crate) struct RenderExampleBlock {} impl RenderExampleBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IExampleBlock, ) -> Result { Ok(RenderExampleBlock {}) diff --git a/src/context/export_block.rs b/src/context/export_block.rs index bd035eb..347bffd 100644 --- a/src/context/export_block.rs +++ b/src/context/export_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IExportBlock; pub(crate) struct RenderExportBlock {} impl RenderExportBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IExportBlock, ) -> Result { Ok(RenderExportBlock {}) diff --git a/src/context/export_snippet.rs b/src/context/export_snippet.rs index a6fe6cc..903f7e5 100644 --- a/src/context/export_snippet.rs +++ b/src/context/export_snippet.rs @@ -12,10 +12,10 @@ use crate::intermediate::IExportSnippet; pub(crate) struct RenderExportSnippet {} impl RenderExportSnippet { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IExportSnippet, ) -> Result { Ok(RenderExportSnippet {}) diff --git a/src/context/fixed_width_area.rs b/src/context/fixed_width_area.rs index e079ded..2220967 100644 --- a/src/context/fixed_width_area.rs +++ b/src/context/fixed_width_area.rs @@ -12,10 +12,10 @@ use crate::intermediate::IFixedWidthArea; pub(crate) struct RenderFixedWidthArea {} impl RenderFixedWidthArea { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IFixedWidthArea, ) -> Result { Ok(RenderFixedWidthArea {}) diff --git a/src/context/footnote_definition.rs b/src/context/footnote_definition.rs index e062c28..589658e 100644 --- a/src/context/footnote_definition.rs +++ b/src/context/footnote_definition.rs @@ -12,10 +12,10 @@ use crate::intermediate::IFootnoteDefinition; pub(crate) struct RenderFootnoteDefinition {} impl RenderFootnoteDefinition { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IFootnoteDefinition, ) -> Result { Ok(RenderFootnoteDefinition {}) diff --git a/src/context/footnote_reference.rs b/src/context/footnote_reference.rs index 6fbe88c..300517e 100644 --- a/src/context/footnote_reference.rs +++ b/src/context/footnote_reference.rs @@ -12,10 +12,10 @@ use crate::intermediate::IFootnoteReference; pub(crate) struct RenderFootnoteReference {} impl RenderFootnoteReference { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IFootnoteReference, ) -> Result { Ok(RenderFootnoteReference {}) diff --git a/src/context/heading.rs b/src/context/heading.rs index c609c5a..ec6399f 100644 --- a/src/context/heading.rs +++ b/src/context/heading.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IHeading; +use super::RenderDocumentElement; use super::RenderObject; #[derive(Debug, Serialize)] @@ -14,23 +15,46 @@ use super::RenderObject; pub(crate) struct RenderHeading { level: organic::types::HeadlineLevel, title: Vec, + children: Vec, } impl RenderHeading { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, heading: &IHeading, ) -> Result { - let title = heading - .title - .iter() - .map(|obj| RenderObject::new(config, &output_directory, &output_file, obj)) - .collect::, _>>()?; + let title = { + let mut ret = Vec::new(); + for obj in heading.title.iter() { + ret.push(RenderObject::new( + config, + &output_directory, + &output_file, + obj, + )?); + } + ret + }; + + let children = { + let mut ret = Vec::new(); + for obj in heading.children.iter() { + ret.push(RenderDocumentElement::new( + config, + &output_directory, + &output_file, + obj, + )?); + } + ret + }; + Ok(RenderHeading { - level: heading.level, + level: heading.level + 1, // Adding 1 because the page title is going to be h1. title, + children, }) } } diff --git a/src/context/horizontal_rule.rs b/src/context/horizontal_rule.rs index 781635e..d22316b 100644 --- a/src/context/horizontal_rule.rs +++ b/src/context/horizontal_rule.rs @@ -12,10 +12,10 @@ use crate::intermediate::IHorizontalRule; pub(crate) struct RenderHorizontalRule {} impl RenderHorizontalRule { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IHorizontalRule, ) -> Result { Ok(RenderHorizontalRule {}) diff --git a/src/context/inline_babel_call.rs b/src/context/inline_babel_call.rs index cab345c..bfa5d87 100644 --- a/src/context/inline_babel_call.rs +++ b/src/context/inline_babel_call.rs @@ -12,10 +12,10 @@ use crate::intermediate::IInlineBabelCall; pub(crate) struct RenderInlineBabelCall {} impl RenderInlineBabelCall { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IInlineBabelCall, ) -> Result { Ok(RenderInlineBabelCall {}) diff --git a/src/context/inline_source_block.rs b/src/context/inline_source_block.rs index 7303a8f..9972c95 100644 --- a/src/context/inline_source_block.rs +++ b/src/context/inline_source_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IInlineSourceBlock; pub(crate) struct RenderInlineSourceBlock {} impl RenderInlineSourceBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IInlineSourceBlock, ) -> Result { Ok(RenderInlineSourceBlock {}) diff --git a/src/context/italic.rs b/src/context/italic.rs index 7f3bf4c..7aa1557 100644 --- a/src/context/italic.rs +++ b/src/context/italic.rs @@ -12,10 +12,10 @@ use crate::intermediate::IItalic; pub(crate) struct RenderItalic {} impl RenderItalic { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IItalic, ) -> Result { Ok(RenderItalic {}) diff --git a/src/context/keyword.rs b/src/context/keyword.rs index c9e7a10..99dc1c7 100644 --- a/src/context/keyword.rs +++ b/src/context/keyword.rs @@ -12,10 +12,10 @@ use crate::intermediate::IKeyword; pub(crate) struct RenderKeyword {} impl RenderKeyword { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, keyword: &IKeyword, ) -> Result { Ok(RenderKeyword {}) diff --git a/src/context/latex_environment.rs b/src/context/latex_environment.rs index b7b75ae..74fe81d 100644 --- a/src/context/latex_environment.rs +++ b/src/context/latex_environment.rs @@ -12,10 +12,10 @@ use crate::intermediate::ILatexEnvironment; pub(crate) struct RenderLatexEnvironment {} impl RenderLatexEnvironment { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ILatexEnvironment, ) -> Result { Ok(RenderLatexEnvironment {}) diff --git a/src/context/latex_fragment.rs b/src/context/latex_fragment.rs index 69fdb94..58ddddf 100644 --- a/src/context/latex_fragment.rs +++ b/src/context/latex_fragment.rs @@ -12,10 +12,10 @@ use crate::intermediate::ILatexFragment; pub(crate) struct RenderLatexFragment {} impl RenderLatexFragment { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ILatexFragment, ) -> Result { Ok(RenderLatexFragment {}) diff --git a/src/context/line_break.rs b/src/context/line_break.rs index 68394da..d804926 100644 --- a/src/context/line_break.rs +++ b/src/context/line_break.rs @@ -12,10 +12,10 @@ use crate::intermediate::ILineBreak; pub(crate) struct RenderLineBreak {} impl RenderLineBreak { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ILineBreak, ) -> Result { Ok(RenderLineBreak {}) diff --git a/src/context/object.rs b/src/context/object.rs index 63e65d1..931b25e 100644 --- a/src/context/object.rs +++ b/src/context/object.rs @@ -67,10 +67,10 @@ pub(crate) enum RenderObject { } impl RenderObject { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, object: &IObject, ) -> Result { match object { diff --git a/src/context/org_macro.rs b/src/context/org_macro.rs index 87c144b..abcdb83 100644 --- a/src/context/org_macro.rs +++ b/src/context/org_macro.rs @@ -12,10 +12,10 @@ use crate::intermediate::IOrgMacro; pub(crate) struct RenderOrgMacro {} impl RenderOrgMacro { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IOrgMacro, ) -> Result { Ok(RenderOrgMacro {}) diff --git a/src/context/paragraph.rs b/src/context/paragraph.rs index 2570f93..2e0e1c3 100644 --- a/src/context/paragraph.rs +++ b/src/context/paragraph.rs @@ -16,17 +16,25 @@ pub(crate) struct RenderParagraph { } impl RenderParagraph { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, paragraph: &IParagraph, ) -> Result { - let children = paragraph - .children - .iter() - .map(|obj| RenderObject::new(config, &output_directory, &output_file, obj)) - .collect::, _>>()?; + let children = { + let mut ret = Vec::new(); + for obj in paragraph.children.iter() { + ret.push(RenderObject::new( + config, + &output_directory, + &output_file, + obj, + )?); + } + ret + }; + Ok(RenderParagraph { children }) } } diff --git a/src/context/plain_link.rs b/src/context/plain_link.rs index 9951f5a..a0c6606 100644 --- a/src/context/plain_link.rs +++ b/src/context/plain_link.rs @@ -12,10 +12,10 @@ use crate::intermediate::IPlainLink; pub(crate) struct RenderPlainLink {} impl RenderPlainLink { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IPlainLink, ) -> Result { Ok(RenderPlainLink {}) diff --git a/src/context/plain_list.rs b/src/context/plain_list.rs index 746d222..8c239f4 100644 --- a/src/context/plain_list.rs +++ b/src/context/plain_list.rs @@ -12,10 +12,10 @@ use crate::intermediate::IPlainList; pub(crate) struct RenderPlainList {} impl RenderPlainList { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IPlainList, ) -> Result { Ok(RenderPlainList {}) diff --git a/src/context/plain_text.rs b/src/context/plain_text.rs index 76f3d78..12b9e79 100644 --- a/src/context/plain_text.rs +++ b/src/context/plain_text.rs @@ -12,10 +12,10 @@ use crate::intermediate::IPlainText; pub(crate) struct RenderPlainText {} impl RenderPlainText { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, heading: &IPlainText, ) -> Result { Ok(RenderPlainText {}) diff --git a/src/context/planning.rs b/src/context/planning.rs index 1086dc2..7be554c 100644 --- a/src/context/planning.rs +++ b/src/context/planning.rs @@ -12,10 +12,10 @@ use crate::intermediate::IPlanning; pub(crate) struct RenderPlanning {} impl RenderPlanning { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IPlanning, ) -> Result { Ok(RenderPlanning {}) diff --git a/src/context/property_drawer.rs b/src/context/property_drawer.rs index d85c72b..8e1bc6f 100644 --- a/src/context/property_drawer.rs +++ b/src/context/property_drawer.rs @@ -12,10 +12,10 @@ use crate::intermediate::IPropertyDrawer; pub(crate) struct RenderPropertyDrawer {} impl RenderPropertyDrawer { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IPropertyDrawer, ) -> Result { Ok(RenderPropertyDrawer {}) diff --git a/src/context/quote_block.rs b/src/context/quote_block.rs index 6de04e0..9603f44 100644 --- a/src/context/quote_block.rs +++ b/src/context/quote_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IQuoteBlock; pub(crate) struct RenderQuoteBlock {} impl RenderQuoteBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IQuoteBlock, ) -> Result { Ok(RenderQuoteBlock {}) diff --git a/src/context/radio_link.rs b/src/context/radio_link.rs index 6001f51..2c41bfd 100644 --- a/src/context/radio_link.rs +++ b/src/context/radio_link.rs @@ -12,10 +12,10 @@ use crate::intermediate::IRadioLink; pub(crate) struct RenderRadioLink {} impl RenderRadioLink { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IRadioLink, ) -> Result { Ok(RenderRadioLink {}) diff --git a/src/context/radio_target.rs b/src/context/radio_target.rs index b56a020..7be7452 100644 --- a/src/context/radio_target.rs +++ b/src/context/radio_target.rs @@ -12,10 +12,10 @@ use crate::intermediate::IRadioTarget; pub(crate) struct RenderRadioTarget {} impl RenderRadioTarget { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IRadioTarget, ) -> Result { Ok(RenderRadioTarget {}) diff --git a/src/context/regular_link.rs b/src/context/regular_link.rs index 6727714..38bae6b 100644 --- a/src/context/regular_link.rs +++ b/src/context/regular_link.rs @@ -12,10 +12,10 @@ use crate::intermediate::IRegularLink; pub(crate) struct RenderRegularLink {} impl RenderRegularLink { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IRegularLink, ) -> Result { Ok(RenderRegularLink {}) diff --git a/src/context/section.rs b/src/context/section.rs index d614638..45d66bf 100644 --- a/src/context/section.rs +++ b/src/context/section.rs @@ -16,17 +16,24 @@ pub(crate) struct RenderSection { } impl RenderSection { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, section: &ISection, ) -> Result { - let children = section - .children - .iter() - .map(|obj| RenderElement::new(config, &output_directory, &output_file, obj)) - .collect::, _>>()?; + let children = { + let mut ret = Vec::new(); + for obj in section.children.iter() { + ret.push(RenderElement::new( + config, + &output_directory, + &output_file, + obj, + )?); + } + ret + }; Ok(RenderSection { children }) } diff --git a/src/context/special_block.rs b/src/context/special_block.rs index b8906ff..085be8b 100644 --- a/src/context/special_block.rs +++ b/src/context/special_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::ISpecialBlock; pub(crate) struct RenderSpecialBlock {} impl RenderSpecialBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ISpecialBlock, ) -> Result { Ok(RenderSpecialBlock {}) diff --git a/src/context/src_block.rs b/src/context/src_block.rs index cdbf0ec..0c19570 100644 --- a/src/context/src_block.rs +++ b/src/context/src_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::ISrcBlock; pub(crate) struct RenderSrcBlock {} impl RenderSrcBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ISrcBlock, ) -> Result { Ok(RenderSrcBlock {}) diff --git a/src/context/statistics_cookie.rs b/src/context/statistics_cookie.rs index 774f1f3..33ff1fa 100644 --- a/src/context/statistics_cookie.rs +++ b/src/context/statistics_cookie.rs @@ -12,10 +12,10 @@ use crate::intermediate::IStatisticsCookie; pub(crate) struct RenderStatisticsCookie {} impl RenderStatisticsCookie { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IStatisticsCookie, ) -> Result { Ok(RenderStatisticsCookie {}) diff --git a/src/context/strike_through.rs b/src/context/strike_through.rs index 2f0249f..22b4269 100644 --- a/src/context/strike_through.rs +++ b/src/context/strike_through.rs @@ -12,10 +12,10 @@ use crate::intermediate::IStrikeThrough; pub(crate) struct RenderStrikeThrough {} impl RenderStrikeThrough { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IStrikeThrough, ) -> Result { Ok(RenderStrikeThrough {}) diff --git a/src/context/subscript.rs b/src/context/subscript.rs index dd31b29..78596ad 100644 --- a/src/context/subscript.rs +++ b/src/context/subscript.rs @@ -12,10 +12,10 @@ use crate::intermediate::ISubscript; pub(crate) struct RenderSubscript {} impl RenderSubscript { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ISubscript, ) -> Result { Ok(RenderSubscript {}) diff --git a/src/context/superscript.rs b/src/context/superscript.rs index f47fac7..99b07bb 100644 --- a/src/context/superscript.rs +++ b/src/context/superscript.rs @@ -12,10 +12,10 @@ use crate::intermediate::ISuperscript; pub(crate) struct RenderSuperscript {} impl RenderSuperscript { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ISuperscript, ) -> Result { Ok(RenderSuperscript {}) diff --git a/src/context/table.rs b/src/context/table.rs index b80c216..9d067bd 100644 --- a/src/context/table.rs +++ b/src/context/table.rs @@ -12,10 +12,10 @@ use crate::intermediate::ITable; pub(crate) struct RenderTable {} impl RenderTable { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &ITable, ) -> Result { Ok(RenderTable {}) diff --git a/src/context/target.rs b/src/context/target.rs index ebdb69c..22f8aec 100644 --- a/src/context/target.rs +++ b/src/context/target.rs @@ -14,10 +14,10 @@ pub(crate) struct RenderTarget { } impl RenderTarget { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, target: &ITarget, ) -> Result { Ok(RenderTarget { diff --git a/src/context/timestamp.rs b/src/context/timestamp.rs index fa1daa3..bc28ef5 100644 --- a/src/context/timestamp.rs +++ b/src/context/timestamp.rs @@ -12,10 +12,10 @@ use crate::intermediate::ITimestamp; pub(crate) struct RenderTimestamp {} impl RenderTimestamp { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &ITimestamp, ) -> Result { Ok(RenderTimestamp {}) diff --git a/src/context/underline.rs b/src/context/underline.rs index 4575881..05ed24e 100644 --- a/src/context/underline.rs +++ b/src/context/underline.rs @@ -12,10 +12,10 @@ use crate::intermediate::IUnderline; pub(crate) struct RenderUnderline {} impl RenderUnderline { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IUnderline, ) -> Result { Ok(RenderUnderline {}) diff --git a/src/context/verbatim.rs b/src/context/verbatim.rs index 2523c83..a0f6262 100644 --- a/src/context/verbatim.rs +++ b/src/context/verbatim.rs @@ -12,10 +12,10 @@ use crate::intermediate::IVerbatim; pub(crate) struct RenderVerbatim {} impl RenderVerbatim { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, comment: &IVerbatim, ) -> Result { Ok(RenderVerbatim {}) diff --git a/src/context/verse_block.rs b/src/context/verse_block.rs index bc14724..a667cab 100644 --- a/src/context/verse_block.rs +++ b/src/context/verse_block.rs @@ -12,10 +12,10 @@ use crate::intermediate::IVerseBlock; pub(crate) struct RenderVerseBlock {} impl RenderVerseBlock { - pub(crate) fn new, F: AsRef>( + pub(crate) fn new( config: &Config, - output_directory: D, - output_file: F, + output_directory: &Path, + output_file: &Path, original: &IVerseBlock, ) -> Result { Ok(RenderVerseBlock {}) diff --git a/src/intermediate/convert.rs b/src/intermediate/convert.rs index f28ac59..ee9bdfa 100644 --- a/src/intermediate/convert.rs +++ b/src/intermediate/convert.rs @@ -6,13 +6,10 @@ use crate::config::Config; use crate::context::GlobalSettings; use crate::context::RenderBlogPostPage; use crate::context::RenderDocumentElement; -use crate::context::RenderHeading; -use crate::context::RenderSection; use crate::error::CustomError; use super::BlogPost; use super::BlogPostPage; -use super::IDocumentElement; pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef>( config: &Config, @@ -47,24 +44,12 @@ pub(crate) fn convert_blog_post_page_to_render_context, F: AsRef< let mut children = Vec::new(); for child in page.children.iter() { - match child { - IDocumentElement::Heading(heading) => { - children.push(RenderDocumentElement::Heading(RenderHeading::new( - config, - output_directory, - output_file, - heading, - )?)); - } - IDocumentElement::Section(section) => { - children.push(RenderDocumentElement::Section(RenderSection::new( - config, - output_directory, - output_file, - section, - )?)); - } - } + children.push(RenderDocumentElement::new( + config, + output_directory, + output_file, + child, + )?); } children diff --git a/src/intermediate/document_element.rs b/src/intermediate/document_element.rs index 3f35270..d348269 100644 --- a/src/intermediate/document_element.rs +++ b/src/intermediate/document_element.rs @@ -1,8 +1,31 @@ +use crate::error::CustomError; + +use super::registry::Registry; use super::IHeading; use super::ISection; +use futures::future::{BoxFuture, FutureExt}; #[derive(Debug)] pub(crate) enum IDocumentElement { Heading(IHeading), Section(ISection), } + +impl IDocumentElement { + pub(crate) fn new<'parse, 'b>( + registry: &'b mut Registry<'parse>, + original: &'b organic::types::DocumentElement<'parse>, + ) -> BoxFuture<'b, Result> { + async move { + match original { + organic::types::DocumentElement::Heading(inner) => Ok(IDocumentElement::Heading( + IHeading::new(registry, inner).await?, + )), + organic::types::DocumentElement::Section(inner) => Ok(IDocumentElement::Section( + ISection::new(registry, inner).await?, + )), + } + } + .boxed() + } +} diff --git a/src/intermediate/heading.rs b/src/intermediate/heading.rs index 17cc680..4ed510e 100644 --- a/src/intermediate/heading.rs +++ b/src/intermediate/heading.rs @@ -1,12 +1,14 @@ use crate::error::CustomError; use super::registry::Registry; +use super::IDocumentElement; use super::IObject; #[derive(Debug)] pub(crate) struct IHeading { pub(crate) level: organic::types::HeadlineLevel, pub(crate) title: Vec, + pub(crate) children: Vec, } impl IHeading { @@ -21,9 +23,17 @@ impl IHeading { } ret }; + let children = { + let mut ret = Vec::new(); + for obj in heading.children.iter() { + ret.push(IDocumentElement::new(registry, obj).await?); + } + ret + }; Ok(IHeading { title, level: heading.level, + children, }) } }