diff --git a/src/context/angle_link.rs b/src/context/angle_link.rs index 330d4e1..bb7fcb2 100644 --- a/src/context/angle_link.rs +++ b/src/context/angle_link.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IAngleLink; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "angle_link")] pub(crate) struct RenderAngleLink {} -impl RenderAngleLink { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IAngleLink, - ) -> Result { - Ok(RenderAngleLink {}) - } -} +rnoop!(RenderAngleLink, IAngleLink); diff --git a/src/context/babel_call.rs b/src/context/babel_call.rs index 272157e..f376b36 100644 --- a/src/context/babel_call.rs +++ b/src/context/babel_call.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IBabelCall; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "babel_call")] pub(crate) struct RenderBabelCall {} -impl RenderBabelCall { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IBabelCall, - ) -> Result { - Ok(RenderBabelCall {}) - } -} +rnoop!(RenderBabelCall, IBabelCall); diff --git a/src/context/blog_post_page.rs b/src/context/blog_post_page.rs index a8720f7..d7dd043 100644 --- a/src/context/blog_post_page.rs +++ b/src/context/blog_post_page.rs @@ -21,6 +21,7 @@ pub(crate) struct RenderBlogPostPage { } impl RenderBlogPostPage { + // TODO: Maybe these settings should be moved into a common struct so this can have the same type signature as the others. pub(crate) fn new( global_settings: GlobalSettings, title: Option, diff --git a/src/context/bold.rs b/src/context/bold.rs index d531027..4fdb56e 100644 --- a/src/context/bold.rs +++ b/src/context/bold.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IBold; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "bold")] pub(crate) struct RenderBold {} -impl RenderBold { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IBold, - ) -> Result { - Ok(RenderBold {}) - } -} +rnoop!(RenderBold, IBold); diff --git a/src/context/center_block.rs b/src/context/center_block.rs index e3a0b38..e0da129 100644 --- a/src/context/center_block.rs +++ b/src/context/center_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICenterBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "center_block")] pub(crate) struct RenderCenterBlock {} -impl RenderCenterBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &ICenterBlock, - ) -> Result { - Ok(RenderCenterBlock {}) - } -} +rnoop!(RenderCenterBlock, ICenterBlock); diff --git a/src/context/citation.rs b/src/context/citation.rs index 9705365..0ca5fbb 100644 --- a/src/context/citation.rs +++ b/src/context/citation.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICitation; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "citation")] pub(crate) struct RenderCitation {} -impl RenderCitation { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ICitation, - ) -> Result { - Ok(RenderCitation {}) - } -} +rnoop!(RenderCitation, ICitation); diff --git a/src/context/citation_reference.rs b/src/context/citation_reference.rs index c10d8b6..7d1143f 100644 --- a/src/context/citation_reference.rs +++ b/src/context/citation_reference.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICitationReference; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "citation_reference")] pub(crate) struct RenderCitationReference {} -impl RenderCitationReference { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ICitationReference, - ) -> Result { - Ok(RenderCitationReference {}) - } -} +rnoop!(RenderCitationReference, ICitationReference); diff --git a/src/context/clock.rs b/src/context/clock.rs index 0eb7049..8165502 100644 --- a/src/context/clock.rs +++ b/src/context/clock.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IClock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "clock")] pub(crate) struct RenderClock {} -impl RenderClock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IClock, - ) -> Result { - Ok(RenderClock {}) - } -} +rnoop!(RenderClock, IClock); diff --git a/src/context/code.rs b/src/context/code.rs index ba59d98..bdad7e2 100644 --- a/src/context/code.rs +++ b/src/context/code.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICode; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "code")] pub(crate) struct RenderCode {} -impl RenderCode { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ICode, - ) -> Result { - Ok(RenderCode {}) - } -} +rnoop!(RenderCode, ICode); diff --git a/src/context/comment_block.rs b/src/context/comment_block.rs index 0c1d194..c2801f6 100644 --- a/src/context/comment_block.rs +++ b/src/context/comment_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ICommentBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "comment_block")] pub(crate) struct RenderCommentBlock {} -impl RenderCommentBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &ICommentBlock, - ) -> Result { - Ok(RenderCommentBlock {}) - } -} +rnoop!(RenderCommentBlock, ICommentBlock); diff --git a/src/context/diary_sexp.rs b/src/context/diary_sexp.rs index c45cdff..889fc9f 100644 --- a/src/context/diary_sexp.rs +++ b/src/context/diary_sexp.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IDiarySexp; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "diary_sexp")] pub(crate) struct RenderDiarySexp {} -impl RenderDiarySexp { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IDiarySexp, - ) -> Result { - Ok(RenderDiarySexp {}) - } -} +rnoop!(RenderDiarySexp, IDiarySexp); diff --git a/src/context/document_element.rs b/src/context/document_element.rs index f4f3283..aa10d75 100644 --- a/src/context/document_element.rs +++ b/src/context/document_element.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IDocumentElement; +use super::macros::render; use super::RenderHeading; use super::RenderSection; @@ -16,13 +17,14 @@ pub(crate) enum RenderDocumentElement { Section(RenderSection), } -impl RenderDocumentElement { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - original: &IDocumentElement, - ) -> Result { +render!( + RenderDocumentElement, + IDocumentElement, + original, + config, + output_directory, + output_file, + { match original { IDocumentElement::Heading(inner) => Ok(RenderDocumentElement::Heading( RenderHeading::new(config, output_directory, output_file, inner)?, @@ -32,4 +34,4 @@ impl RenderDocumentElement { )), } } -} +); diff --git a/src/context/drawer.rs b/src/context/drawer.rs index eb25a1b..f6989b7 100644 --- a/src/context/drawer.rs +++ b/src/context/drawer.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IDrawer; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "drawer")] pub(crate) struct RenderDrawer {} -impl RenderDrawer { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IDrawer, - ) -> Result { - Ok(RenderDrawer {}) - } -} +rnoop!(RenderDrawer, IDrawer); diff --git a/src/context/dynamic_block.rs b/src/context/dynamic_block.rs index 2a9e698..bd562e1 100644 --- a/src/context/dynamic_block.rs +++ b/src/context/dynamic_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IDynamicBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "dynamic_block")] pub(crate) struct RenderDynamicBlock {} -impl RenderDynamicBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IDynamicBlock, - ) -> Result { - Ok(RenderDynamicBlock {}) - } -} +rnoop!(RenderDynamicBlock, IDynamicBlock); diff --git a/src/context/element.rs b/src/context/element.rs index 026b812..781ca28 100644 --- a/src/context/element.rs +++ b/src/context/element.rs @@ -21,6 +21,7 @@ use super::footnote_definition::RenderFootnoteDefinition; use super::horizontal_rule::RenderHorizontalRule; use super::keyword::RenderKeyword; use super::latex_environment::RenderLatexEnvironment; +use super::macros::render; use super::paragraph::RenderParagraph; use super::plain_list::RenderPlainList; use super::planning::RenderPlanning; @@ -60,14 +61,15 @@ pub(crate) enum RenderElement { LatexEnvironment(RenderLatexEnvironment), } -impl RenderElement { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - element: &IElement, - ) -> Result { - match element { +render!( + RenderElement, + IElement, + original, + config, + output_directory, + output_file, + { + match original { IElement::Paragraph(inner) => Ok(RenderElement::Paragraph(RenderParagraph::new( config, output_directory, @@ -187,4 +189,4 @@ impl RenderElement { )), } } -} +); diff --git a/src/context/entity.rs b/src/context/entity.rs index 4cce5f3..4b60a44 100644 --- a/src/context/entity.rs +++ b/src/context/entity.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IEntity; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "entity")] @@ -13,15 +15,16 @@ pub(crate) struct RenderEntity { html: String, } -impl RenderEntity { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - entity: &IEntity, - ) -> Result { +render!( + RenderEntity, + IEntity, + original, + config, + output_directory, + output_file, + { Ok(RenderEntity { - html: entity.html.clone(), + html: original.html.clone(), }) } -} +); diff --git a/src/context/example_block.rs b/src/context/example_block.rs index 5a848a4..a15868a 100644 --- a/src/context/example_block.rs +++ b/src/context/example_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IExampleBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "example_block")] pub(crate) struct RenderExampleBlock {} -impl RenderExampleBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IExampleBlock, - ) -> Result { - Ok(RenderExampleBlock {}) - } -} +rnoop!(RenderExampleBlock, IExampleBlock); diff --git a/src/context/export_block.rs b/src/context/export_block.rs index d81e3a2..837df0f 100644 --- a/src/context/export_block.rs +++ b/src/context/export_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IExportBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "export_block")] pub(crate) struct RenderExportBlock {} -impl RenderExportBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IExportBlock, - ) -> Result { - Ok(RenderExportBlock {}) - } -} +rnoop!(RenderExportBlock, IExportBlock); diff --git a/src/context/export_snippet.rs b/src/context/export_snippet.rs index 1fb98ec..4a422c0 100644 --- a/src/context/export_snippet.rs +++ b/src/context/export_snippet.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IExportSnippet; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "export_snippet")] pub(crate) struct RenderExportSnippet {} -impl RenderExportSnippet { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IExportSnippet, - ) -> Result { - Ok(RenderExportSnippet {}) - } -} +rnoop!(RenderExportSnippet, IExportSnippet); diff --git a/src/context/fixed_width_area.rs b/src/context/fixed_width_area.rs index fafd6cf..c31fbc8 100644 --- a/src/context/fixed_width_area.rs +++ b/src/context/fixed_width_area.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IFixedWidthArea; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "fixed_width_area")] pub(crate) struct RenderFixedWidthArea {} -impl RenderFixedWidthArea { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IFixedWidthArea, - ) -> Result { - Ok(RenderFixedWidthArea {}) - } -} +rnoop!(RenderFixedWidthArea, IFixedWidthArea); diff --git a/src/context/footnote_definition.rs b/src/context/footnote_definition.rs index a8cb9ce..e443fc1 100644 --- a/src/context/footnote_definition.rs +++ b/src/context/footnote_definition.rs @@ -9,22 +9,15 @@ use crate::intermediate::IRealFootnoteDefinition; use super::ast_node::IntoRenderAstNode; use super::ast_node::RenderAstNode; +use super::macros::render; +use super::macros::rnoop; #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "footnote_definition")] pub(crate) struct RenderFootnoteDefinition {} -impl RenderFootnoteDefinition { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IFootnoteDefinition, - ) -> Result { - Ok(RenderFootnoteDefinition {}) - } -} +rnoop!(RenderFootnoteDefinition, IFootnoteDefinition); #[derive(Debug, Serialize)] #[serde(tag = "type")] @@ -36,13 +29,14 @@ pub(crate) struct RenderRealFootnoteDefinition { contents: Vec, } -impl RenderRealFootnoteDefinition { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - original: &IRealFootnoteDefinition, - ) -> Result { +render!( + RenderRealFootnoteDefinition, + IRealFootnoteDefinition, + original, + config, + output_directory, + output_file, + { let contents = { let mut ret = Vec::new(); for obj in original.contents.iter() { @@ -58,4 +52,4 @@ impl RenderRealFootnoteDefinition { contents, }) } -} +); diff --git a/src/context/footnote_reference.rs b/src/context/footnote_reference.rs index 6ccb536..ce74306 100644 --- a/src/context/footnote_reference.rs +++ b/src/context/footnote_reference.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IFootnoteReference; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "footnote_reference")] @@ -15,17 +17,18 @@ pub(crate) struct RenderFootnoteReference { label: String, } -impl RenderFootnoteReference { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - original: &IFootnoteReference, - ) -> Result { +render!( + RenderFootnoteReference, + IFootnoteReference, + original, + config, + output_directory, + output_file, + { Ok(RenderFootnoteReference { reference_id: original.get_reference_id(), definition_link: format!("#{}", original.get_definition_id()), label: original.get_display_label(), }) } -} +); diff --git a/src/context/heading.rs b/src/context/heading.rs index d69f659..f9f9fa8 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::macros::render; use super::RenderDocumentElement; use super::RenderObject; @@ -18,16 +19,17 @@ pub(crate) struct RenderHeading { children: Vec, } -impl RenderHeading { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - heading: &IHeading, - ) -> Result { +render!( + RenderHeading, + IHeading, + original, + config, + output_directory, + output_file, + { let title = { let mut ret = Vec::new(); - for obj in heading.title.iter() { + for obj in original.title.iter() { ret.push(RenderObject::new( config, output_directory, @@ -40,7 +42,7 @@ impl RenderHeading { let children = { let mut ret = Vec::new(); - for obj in heading.children.iter() { + for obj in original.children.iter() { ret.push(RenderDocumentElement::new( config, output_directory, @@ -52,9 +54,9 @@ impl RenderHeading { }; Ok(RenderHeading { - level: heading.level + 1, // Adding 1 because the page title is going to be h1. + level: original.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 d33379c..92ecb34 100644 --- a/src/context/horizontal_rule.rs +++ b/src/context/horizontal_rule.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IHorizontalRule; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "horizontal_rule")] pub(crate) struct RenderHorizontalRule {} -impl RenderHorizontalRule { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IHorizontalRule, - ) -> Result { - Ok(RenderHorizontalRule {}) - } -} +rnoop!(RenderHorizontalRule, IHorizontalRule); diff --git a/src/context/inline_babel_call.rs b/src/context/inline_babel_call.rs index bb99b65..6ff79db 100644 --- a/src/context/inline_babel_call.rs +++ b/src/context/inline_babel_call.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IInlineBabelCall; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "inline_babel_call")] pub(crate) struct RenderInlineBabelCall {} -impl RenderInlineBabelCall { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IInlineBabelCall, - ) -> Result { - Ok(RenderInlineBabelCall {}) - } -} +rnoop!(RenderInlineBabelCall, IInlineBabelCall); diff --git a/src/context/inline_source_block.rs b/src/context/inline_source_block.rs index ba09caf..4c3f313 100644 --- a/src/context/inline_source_block.rs +++ b/src/context/inline_source_block.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IInlineSourceBlock; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "inline_source_block")] @@ -13,15 +15,16 @@ pub(crate) struct RenderInlineSourceBlock { value: String, } -impl RenderInlineSourceBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - original: &IInlineSourceBlock, - ) -> Result { +render!( + RenderInlineSourceBlock, + IInlineSourceBlock, + original, + config, + output_directory, + output_file, + { Ok(RenderInlineSourceBlock { value: original.value.clone(), }) } -} +); diff --git a/src/context/italic.rs b/src/context/italic.rs index 6f70997..b29320e 100644 --- a/src/context/italic.rs +++ b/src/context/italic.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IItalic; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "italic")] pub(crate) struct RenderItalic {} -impl RenderItalic { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IItalic, - ) -> Result { - Ok(RenderItalic {}) - } -} +rnoop!(RenderItalic, IItalic); diff --git a/src/context/keyword.rs b/src/context/keyword.rs index eb83e3e..c1f7268 100644 --- a/src/context/keyword.rs +++ b/src/context/keyword.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IKeyword; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "keyword")] pub(crate) struct RenderKeyword {} -impl RenderKeyword { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _keyword: &IKeyword, - ) -> Result { - Ok(RenderKeyword {}) - } -} +rnoop!(RenderKeyword, IKeyword); diff --git a/src/context/latex_environment.rs b/src/context/latex_environment.rs index 0bea9c6..a43f5ce 100644 --- a/src/context/latex_environment.rs +++ b/src/context/latex_environment.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ILatexEnvironment; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "latex_environment")] pub(crate) struct RenderLatexEnvironment {} -impl RenderLatexEnvironment { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &ILatexEnvironment, - ) -> Result { - Ok(RenderLatexEnvironment {}) - } -} +rnoop!(RenderLatexEnvironment, ILatexEnvironment); diff --git a/src/context/line_break.rs b/src/context/line_break.rs index aaac49d..aa6b7a9 100644 --- a/src/context/line_break.rs +++ b/src/context/line_break.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ILineBreak; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "line_break")] pub(crate) struct RenderLineBreak {} -impl RenderLineBreak { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ILineBreak, - ) -> Result { - Ok(RenderLineBreak {}) - } -} +rnoop!(RenderLineBreak, ILineBreak); diff --git a/src/context/object.rs b/src/context/object.rs index 931b25e..44fa771 100644 --- a/src/context/object.rs +++ b/src/context/object.rs @@ -19,6 +19,7 @@ use super::inline_source_block::RenderInlineSourceBlock; use super::italic::RenderItalic; use super::latex_fragment::RenderLatexFragment; use super::line_break::RenderLineBreak; +use super::macros::render; use super::org_macro::RenderOrgMacro; use super::plain_link::RenderPlainLink; use super::plain_text::RenderPlainText; @@ -66,14 +67,15 @@ pub(crate) enum RenderObject { Timestamp(RenderTimestamp), } -impl RenderObject { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - object: &IObject, - ) -> Result { - match object { +render!( + RenderObject, + IObject, + original, + config, + output_directory, + output_file, + { + match original { IObject::Bold(inner) => Ok(RenderObject::Bold(RenderBold::new( config, output_directory, @@ -214,4 +216,4 @@ impl RenderObject { )?)), } } -} +); diff --git a/src/context/org_macro.rs b/src/context/org_macro.rs index 7514a43..cdf6659 100644 --- a/src/context/org_macro.rs +++ b/src/context/org_macro.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IOrgMacro; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "org_macro")] pub(crate) struct RenderOrgMacro {} -impl RenderOrgMacro { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IOrgMacro, - ) -> Result { - Ok(RenderOrgMacro {}) - } -} +rnoop!(RenderOrgMacro, IOrgMacro); diff --git a/src/context/paragraph.rs b/src/context/paragraph.rs index c211535..4063e5e 100644 --- a/src/context/paragraph.rs +++ b/src/context/paragraph.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IParagraph; +use super::macros::render; use super::RenderObject; #[derive(Debug, Serialize)] @@ -15,16 +16,17 @@ pub(crate) struct RenderParagraph { children: Vec, } -impl RenderParagraph { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - paragraph: &IParagraph, - ) -> Result { +render!( + RenderParagraph, + IParagraph, + original, + config, + output_directory, + output_file, + { let children = { let mut ret = Vec::new(); - for obj in paragraph.children.iter() { + for obj in original.children.iter() { ret.push(RenderObject::new( config, output_directory, @@ -37,4 +39,4 @@ impl RenderParagraph { Ok(RenderParagraph { children }) } -} +); diff --git a/src/context/plain_link.rs b/src/context/plain_link.rs index 57c58ba..ffb5481 100644 --- a/src/context/plain_link.rs +++ b/src/context/plain_link.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPlainLink; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "plain_link")] pub(crate) struct RenderPlainLink {} -impl RenderPlainLink { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IPlainLink, - ) -> Result { - Ok(RenderPlainLink {}) - } -} +rnoop!(RenderPlainLink, IPlainLink); diff --git a/src/context/plain_list.rs b/src/context/plain_list.rs index 25840b8..d7be696 100644 --- a/src/context/plain_list.rs +++ b/src/context/plain_list.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPlainList; +use super::macros::render; use super::plain_list_item::RenderPlainListItem; #[derive(Debug, Serialize)] @@ -16,13 +17,14 @@ pub(crate) struct RenderPlainList { children: Vec, } -impl RenderPlainList { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - original: &IPlainList, - ) -> Result { +render!( + RenderPlainList, + IPlainList, + original, + config, + output_directory, + output_file, + { let list_type = match original.list_type { organic::types::PlainListType::Unordered => "unordered".to_owned(), organic::types::PlainListType::Ordered => "ordered".to_owned(), @@ -46,4 +48,4 @@ impl RenderPlainList { children, }) } -} +); diff --git a/src/context/plain_list_item.rs b/src/context/plain_list_item.rs index df18dee..4fa2edc 100644 --- a/src/context/plain_list_item.rs +++ b/src/context/plain_list_item.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPlainListItem; +use super::macros::render; use super::RenderElement; use super::RenderObject; @@ -17,13 +18,14 @@ pub(crate) struct RenderPlainListItem { children: Vec, } -impl RenderPlainListItem { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - original: &IPlainListItem, - ) -> Result { +render!( + RenderPlainListItem, + IPlainListItem, + original, + config, + output_directory, + output_file, + { let tag = { let mut ret = Vec::new(); for obj in original.tag.iter() { @@ -51,4 +53,4 @@ impl RenderPlainListItem { }; Ok(RenderPlainListItem { tag, children }) } -} +); diff --git a/src/context/plain_text.rs b/src/context/plain_text.rs index 66fa8ff..15d91c3 100644 --- a/src/context/plain_text.rs +++ b/src/context/plain_text.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPlainText; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "plain_text")] @@ -13,15 +15,16 @@ pub(crate) struct RenderPlainText { source: String, } -impl RenderPlainText { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - original: &IPlainText, - ) -> Result { +render!( + RenderPlainText, + IPlainText, + original, + config, + output_directory, + output_file, + { Ok(RenderPlainText { source: original.source.clone(), }) } -} +); diff --git a/src/context/planning.rs b/src/context/planning.rs index b81d70d..6a13895 100644 --- a/src/context/planning.rs +++ b/src/context/planning.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPlanning; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "planning")] pub(crate) struct RenderPlanning {} -impl RenderPlanning { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IPlanning, - ) -> Result { - Ok(RenderPlanning {}) - } -} +rnoop!(RenderPlanning, IPlanning); diff --git a/src/context/property_drawer.rs b/src/context/property_drawer.rs index fcbbfe2..d19ba3b 100644 --- a/src/context/property_drawer.rs +++ b/src/context/property_drawer.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IPropertyDrawer; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "property_drawer")] pub(crate) struct RenderPropertyDrawer {} -impl RenderPropertyDrawer { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IPropertyDrawer, - ) -> Result { - Ok(RenderPropertyDrawer {}) - } -} +rnoop!(RenderPropertyDrawer, IPropertyDrawer); diff --git a/src/context/quote_block.rs b/src/context/quote_block.rs index 5866442..cae413d 100644 --- a/src/context/quote_block.rs +++ b/src/context/quote_block.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IQuoteBlock; +use super::macros::render; use super::RenderElement; #[derive(Debug, Serialize)] @@ -15,13 +16,14 @@ pub(crate) struct RenderQuoteBlock { children: Vec, } -impl RenderQuoteBlock { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - original: &IQuoteBlock, - ) -> Result { +render!( + RenderQuoteBlock, + IQuoteBlock, + original, + config, + output_directory, + output_file, + { let children = { let mut ret = Vec::new(); for obj in original.children.iter() { @@ -37,4 +39,4 @@ impl RenderQuoteBlock { Ok(RenderQuoteBlock { children }) } -} +); diff --git a/src/context/radio_link.rs b/src/context/radio_link.rs index 57b47c0..06c727f 100644 --- a/src/context/radio_link.rs +++ b/src/context/radio_link.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IRadioLink; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "radio_link")] pub(crate) struct RenderRadioLink {} -impl RenderRadioLink { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IRadioLink, - ) -> Result { - Ok(RenderRadioLink {}) - } -} +rnoop!(RenderRadioLink, IRadioLink); diff --git a/src/context/radio_target.rs b/src/context/radio_target.rs index 2e32b9c..5bbfd56 100644 --- a/src/context/radio_target.rs +++ b/src/context/radio_target.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IRadioTarget; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "radio_target")] pub(crate) struct RenderRadioTarget {} -impl RenderRadioTarget { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IRadioTarget, - ) -> Result { - Ok(RenderRadioTarget {}) - } -} +rnoop!(RenderRadioTarget, IRadioTarget); diff --git a/src/context/regular_link.rs b/src/context/regular_link.rs index 58ccd4a..91efe9e 100644 --- a/src/context/regular_link.rs +++ b/src/context/regular_link.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IRegularLink; +use super::macros::render; use super::RenderObject; #[derive(Debug, Serialize)] @@ -16,16 +17,17 @@ pub(crate) struct RenderRegularLink { children: Vec, } -impl RenderRegularLink { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - regular_link: &IRegularLink, - ) -> Result { +render!( + RenderRegularLink, + IRegularLink, + original, + config, + output_directory, + output_file, + { let children = { let mut ret = Vec::new(); - for obj in regular_link.children.iter() { + for obj in original.children.iter() { ret.push(RenderObject::new( config, output_directory, @@ -37,8 +39,8 @@ impl RenderRegularLink { }; Ok(RenderRegularLink { - raw_link: regular_link.raw_link.clone(), + raw_link: original.raw_link.clone(), children, }) } -} +); diff --git a/src/context/section.rs b/src/context/section.rs index 87c5a12..3f92fe9 100644 --- a/src/context/section.rs +++ b/src/context/section.rs @@ -6,6 +6,7 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISection; +use super::macros::render; use super::RenderElement; #[derive(Debug, Serialize)] @@ -15,16 +16,17 @@ pub(crate) struct RenderSection { children: Vec, } -impl RenderSection { - pub(crate) fn new( - config: &Config, - output_directory: &Path, - output_file: &Path, - section: &ISection, - ) -> Result { +render!( + RenderSection, + ISection, + original, + config, + output_directory, + output_file, + { let children = { let mut ret = Vec::new(); - for obj in section.children.iter() { + for obj in original.children.iter() { ret.push(RenderElement::new( config, output_directory, @@ -37,4 +39,4 @@ impl RenderSection { Ok(RenderSection { children }) } -} +); diff --git a/src/context/special_block.rs b/src/context/special_block.rs index 3646d51..cb42967 100644 --- a/src/context/special_block.rs +++ b/src/context/special_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISpecialBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "special_block")] pub(crate) struct RenderSpecialBlock {} -impl RenderSpecialBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &ISpecialBlock, - ) -> Result { - Ok(RenderSpecialBlock {}) - } -} +rnoop!(RenderSpecialBlock, ISpecialBlock); diff --git a/src/context/src_block.rs b/src/context/src_block.rs index dd6402a..16735ce 100644 --- a/src/context/src_block.rs +++ b/src/context/src_block.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISrcBlock; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "src_block")] @@ -13,15 +15,16 @@ pub(crate) struct RenderSrcBlock { lines: Vec, } -impl RenderSrcBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - original: &ISrcBlock, - ) -> Result { +render!( + RenderSrcBlock, + ISrcBlock, + original, + config, + output_directory, + output_file, + { Ok(RenderSrcBlock { lines: original.lines.clone(), }) } -} +); diff --git a/src/context/statistics_cookie.rs b/src/context/statistics_cookie.rs index a66845d..35dc122 100644 --- a/src/context/statistics_cookie.rs +++ b/src/context/statistics_cookie.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IStatisticsCookie; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "statistics_cookie")] pub(crate) struct RenderStatisticsCookie {} -impl RenderStatisticsCookie { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IStatisticsCookie, - ) -> Result { - Ok(RenderStatisticsCookie {}) - } -} +rnoop!(RenderStatisticsCookie, IStatisticsCookie); diff --git a/src/context/strike_through.rs b/src/context/strike_through.rs index 92d3c9b..be6f960 100644 --- a/src/context/strike_through.rs +++ b/src/context/strike_through.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IStrikeThrough; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "strike_through")] pub(crate) struct RenderStrikeThrough {} -impl RenderStrikeThrough { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IStrikeThrough, - ) -> Result { - Ok(RenderStrikeThrough {}) - } -} +rnoop!(RenderStrikeThrough, IStrikeThrough); diff --git a/src/context/subscript.rs b/src/context/subscript.rs index db2bb37..b54c5e1 100644 --- a/src/context/subscript.rs +++ b/src/context/subscript.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISubscript; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "subscript")] pub(crate) struct RenderSubscript {} -impl RenderSubscript { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ISubscript, - ) -> Result { - Ok(RenderSubscript {}) - } -} +rnoop!(RenderSubscript, ISubscript); diff --git a/src/context/superscript.rs b/src/context/superscript.rs index 43c4bfc..bb030c5 100644 --- a/src/context/superscript.rs +++ b/src/context/superscript.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ISuperscript; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "superscript")] pub(crate) struct RenderSuperscript {} -impl RenderSuperscript { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ISuperscript, - ) -> Result { - Ok(RenderSuperscript {}) - } -} +rnoop!(RenderSuperscript, ISuperscript); diff --git a/src/context/table.rs b/src/context/table.rs index a549858..6b21b74 100644 --- a/src/context/table.rs +++ b/src/context/table.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ITable; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "table")] pub(crate) struct RenderTable {} -impl RenderTable { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &ITable, - ) -> Result { - Ok(RenderTable {}) - } -} +rnoop!(RenderTable, ITable); diff --git a/src/context/target.rs b/src/context/target.rs index 7bacbbc..0509e84 100644 --- a/src/context/target.rs +++ b/src/context/target.rs @@ -6,6 +6,8 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ITarget; +use super::macros::render; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "target")] @@ -13,15 +15,16 @@ pub(crate) struct RenderTarget { id: String, } -impl RenderTarget { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - target: &ITarget, - ) -> Result { +render!( + RenderTarget, + ITarget, + original, + config, + output_directory, + output_file, + { Ok(RenderTarget { - id: target.id.clone(), + id: original.id.clone(), }) } -} +); diff --git a/src/context/timestamp.rs b/src/context/timestamp.rs index 2995aa1..73b6031 100644 --- a/src/context/timestamp.rs +++ b/src/context/timestamp.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::ITimestamp; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "timestamp")] pub(crate) struct RenderTimestamp {} -impl RenderTimestamp { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &ITimestamp, - ) -> Result { - Ok(RenderTimestamp {}) - } -} +rnoop!(RenderTimestamp, ITimestamp); diff --git a/src/context/underline.rs b/src/context/underline.rs index 2573e7f..cfc1aa6 100644 --- a/src/context/underline.rs +++ b/src/context/underline.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IUnderline; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "underline")] pub(crate) struct RenderUnderline {} -impl RenderUnderline { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IUnderline, - ) -> Result { - Ok(RenderUnderline {}) - } -} +rnoop!(RenderUnderline, IUnderline); diff --git a/src/context/verbatim.rs b/src/context/verbatim.rs index d114631..2456d0c 100644 --- a/src/context/verbatim.rs +++ b/src/context/verbatim.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IVerbatim; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "verbatim")] pub(crate) struct RenderVerbatim {} -impl RenderVerbatim { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _comment: &IVerbatim, - ) -> Result { - Ok(RenderVerbatim {}) - } -} +rnoop!(RenderVerbatim, IVerbatim); diff --git a/src/context/verse_block.rs b/src/context/verse_block.rs index 94834e8..9e4cef2 100644 --- a/src/context/verse_block.rs +++ b/src/context/verse_block.rs @@ -6,18 +6,11 @@ use crate::config::Config; use crate::error::CustomError; use crate::intermediate::IVerseBlock; +use super::macros::rnoop; + #[derive(Debug, Serialize)] #[serde(tag = "type")] #[serde(rename = "verse_block")] pub(crate) struct RenderVerseBlock {} -impl RenderVerseBlock { - pub(crate) fn new( - _config: &Config, - _output_directory: &Path, - _output_file: &Path, - _original: &IVerseBlock, - ) -> Result { - Ok(RenderVerseBlock {}) - } -} +rnoop!(RenderVerseBlock, IVerseBlock);