Files
natter/src/context/render_context.rs
Tom Alexander 3867f965d2 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.
2025-02-08 17:29:09 -05:00

47 lines
1.6 KiB
Rust

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> {
pub(crate) config: &'intermediate Config,
pub(crate) output_root_directory: &'intermediate Path,
pub(crate) output_file: &'intermediate Path,
/// An optional string that gets added to IDs in HTML.
///
/// This is useful for cases where you may have conflicting HTML
/// 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> {
pub(crate) fn new(
config: &'intermediate Config,
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,
})
}
}