Introduce the corresponding non-render types.

This commit is contained in:
Tom Alexander
2023-10-24 00:36:08 -04:00
parent 3b472a9e96
commit 2b7a19a1d4
19 changed files with 91 additions and 10 deletions

View File

@@ -0,0 +1,34 @@
use serde::Serialize;
use super::GlobalSettings;
use super::RenderDocumentElement;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "blog_post_page")]
pub(crate) struct RenderBlogPostPage {
global_settings: GlobalSettings,
/// The title that will be shown visibly on the page.
title: Option<String>,
self_link: Option<String>,
children: Vec<RenderDocumentElement>,
}
impl RenderBlogPostPage {
pub(crate) fn new(
global_settings: GlobalSettings,
title: Option<String>,
self_link: Option<String>,
children: Vec<RenderDocumentElement>,
) -> RenderBlogPostPage {
RenderBlogPostPage {
global_settings,
title,
self_link,
children,
}
}
}

View File

@@ -0,0 +1,11 @@
use serde::Serialize;
use super::RenderHeading;
use super::RenderSection;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderDocumentElement {
Heading(RenderHeading),
Section(RenderSection),
}

5
src/context/element.rs Normal file
View File

@@ -0,0 +1,5 @@
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderElement {}

View File

@@ -0,0 +1,24 @@
use serde::Serialize;
/// The settings that a "global" to a single dustjs render.
#[derive(Debug, Serialize)]
pub(crate) struct GlobalSettings {
/// The title that goes in the html <title> tag in the <head>.
page_title: Option<String>,
css_files: Vec<String>,
js_files: Vec<String>,
}
impl GlobalSettings {
pub(crate) fn new(
page_title: Option<String>,
css_files: Vec<String>,
js_files: Vec<String>,
) -> GlobalSettings {
GlobalSettings {
page_title,
css_files,
js_files,
}
}
}

10
src/context/heading.rs Normal file
View File

@@ -0,0 +1,10 @@
use serde::Serialize;
use super::RenderObject;
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "heading")]
pub(crate) struct RenderHeading {
title: Vec<RenderObject>,
}

15
src/context/mod.rs Normal file
View File

@@ -0,0 +1,15 @@
mod blog_post_page;
mod document_element;
mod element;
mod global_settings;
mod heading;
mod object;
mod section;
pub(crate) use blog_post_page::RenderBlogPostPage;
pub(crate) use document_element::RenderDocumentElement;
pub(crate) use element::RenderElement;
pub(crate) use global_settings::GlobalSettings;
pub(crate) use heading::RenderHeading;
pub(crate) use object::RenderObject;
pub(crate) use section::RenderSection;

5
src/context/object.rs Normal file
View File

@@ -0,0 +1,5 @@
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub(crate) enum RenderObject {}

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

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