Add a dependency manager for render-time actions.

This will be used for supporting things like copying static files or rendering code blocks like gnuplot or graphviz.
This commit is contained in:
Tom Alexander
2025-02-08 17:27:20 -05:00
parent 5cac44c625
commit 3867f965d2
5 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
use std::path::PathBuf;
pub(crate) type RefDependencyManager = std::sync::Arc<std::sync::Mutex<DependencyManager>>;
#[derive(Debug)]
pub(crate) struct DependencyManager {
/// A stack of paths for the files being visited.
///
/// The last entry is the current file being processed. This can be used for handling relative-path links.
file_stack: Vec<PathBuf>,
}
impl DependencyManager {
pub(crate) fn new() -> Self {
DependencyManager {
file_stack: Vec::new(),
}
}
}

View File

@@ -11,6 +11,7 @@ mod clock;
mod code;
mod comment;
mod comment_block;
mod dependency_manager;
mod diary_sexp;
mod document_element;
mod drawer;
@@ -72,6 +73,7 @@ pub(crate) use blog_post_page::RenderBlogPostPage;
pub(crate) use blog_post_page::RenderBlogPostPageInput;
pub(crate) use blog_stream::RenderBlogStream;
pub(crate) use blog_stream::RenderBlogStreamInput;
pub(crate) use dependency_manager::DependencyManager;
pub(crate) use document_element::RenderDocumentElement;
pub(crate) use element::RenderElement;
pub(crate) use footnote_definition::RenderRealFootnoteDefinition;

View File

@@ -3,6 +3,8 @@ use std::path::Path;
use crate::config::Config;
use crate::error::CustomError;
use super::dependency_manager::RefDependencyManager;
/// The supporting information used for converting the intermediate representation into the dust context for rendering.
#[derive(Debug, Clone)]
pub(crate) struct RenderContext<'intermediate> {
@@ -16,6 +18,13 @@ pub(crate) struct RenderContext<'intermediate> {
/// IDs, for example, multiple blog posts with footnotes in a blog
/// stream.
pub(crate) id_addition: Option<&'intermediate str>,
/// Tracks dependencies from rendering Org document(s).
///
/// Examples of dependencies would be:
/// - Static files that need to be copied to the output folder
/// - Code blocks that need to be executed (for example, gnuplot graphs)
pub(crate) dependency_manager: RefDependencyManager,
}
impl<'intermediate> RenderContext<'intermediate> {
@@ -24,12 +33,14 @@ impl<'intermediate> RenderContext<'intermediate> {
output_directory: &'intermediate Path,
output_file: &'intermediate Path,
id_addition: Option<&'intermediate str>,
dependency_manager: RefDependencyManager,
) -> Result<RenderContext<'intermediate>, CustomError> {
Ok(RenderContext {
config,
output_root_directory: output_directory,
output_file,
id_addition,
dependency_manager,
})
}
}