Use macros for the intermediate to render step.

This is largely to make changing the type signature of these functions easier by significantly reducing the amount of places that duplicates the signature.
This commit is contained in:
Tom Alexander
2023-10-31 19:48:05 -04:00
parent 5e476e189a
commit ae933b491e
56 changed files with 304 additions and 537 deletions

View File

@@ -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<RenderDocumentElement>,
}
impl RenderHeading {
pub(crate) fn new(
config: &Config,
output_directory: &Path,
output_file: &Path,
heading: &IHeading,
) -> Result<RenderHeading, CustomError> {
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,
})
}
}
);