2023-12-19 14:54:12 -05:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
|
use crate::error::CustomError;
|
|
|
|
|
|
2025-02-08 17:27:20 -05:00
|
|
|
use super::dependency_manager::RefDependencyManager;
|
|
|
|
|
|
2023-12-19 14:54:12 -05:00
|
|
|
/// 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,
|
2023-12-19 18:03:59 -05:00
|
|
|
pub(crate) output_root_directory: &'intermediate Path,
|
2023-12-19 14:54:12 -05:00
|
|
|
pub(crate) output_file: &'intermediate Path,
|
2023-12-19 17:51:35 -05:00
|
|
|
|
|
|
|
|
/// 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>,
|
2025-02-08 17:27:20 -05:00
|
|
|
|
|
|
|
|
/// 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,
|
2023-12-19 14:54:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'intermediate> RenderContext<'intermediate> {
|
|
|
|
|
pub(crate) fn new(
|
|
|
|
|
config: &'intermediate Config,
|
|
|
|
|
output_directory: &'intermediate Path,
|
|
|
|
|
output_file: &'intermediate Path,
|
2023-12-19 17:51:35 -05:00
|
|
|
id_addition: Option<&'intermediate str>,
|
2025-02-08 17:27:20 -05:00
|
|
|
dependency_manager: RefDependencyManager,
|
2023-12-19 14:54:12 -05:00
|
|
|
) -> Result<RenderContext<'intermediate>, CustomError> {
|
|
|
|
|
Ok(RenderContext {
|
|
|
|
|
config,
|
2023-12-19 18:03:59 -05:00
|
|
|
output_root_directory: output_directory,
|
2023-12-19 14:54:12 -05:00
|
|
|
output_file,
|
2023-12-19 17:51:35 -05:00
|
|
|
id_addition,
|
2025-02-08 17:27:20 -05:00
|
|
|
dependency_manager,
|
2023-12-19 14:54:12 -05:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|