forge_doc/preprocessor/
mod.rs

1//! Module containing documentation preprocessors.
2
3use crate::{Comments, Document};
4use alloy_primitives::map::HashMap;
5use std::{fmt::Debug, path::PathBuf};
6
7mod contract_inheritance;
8pub use contract_inheritance::{ContractInheritance, CONTRACT_INHERITANCE_ID};
9
10mod inheritdoc;
11pub use inheritdoc::{Inheritdoc, INHERITDOC_ID};
12
13mod infer_hyperlinks;
14pub use infer_hyperlinks::{InferInlineHyperlinks, INFER_INLINE_HYPERLINKS_ID};
15
16mod git_source;
17pub use git_source::{GitSource, GIT_SOURCE_ID};
18
19mod deployments;
20pub use deployments::{Deployment, Deployments, DEPLOYMENTS_ID};
21
22/// The preprocessor id.
23#[derive(Debug, PartialEq, Eq, Hash)]
24pub struct PreprocessorId(&'static str);
25
26/// Preprocessor output.
27/// Wraps all existing preprocessor outputs
28/// in a single abstraction.
29#[derive(Clone, Debug)]
30pub enum PreprocessorOutput {
31    /// The contract inheritance output.
32    /// The map of contract base idents to the path of the base contract.
33    ContractInheritance(HashMap<String, PathBuf>),
34    /// The inheritdoc output.
35    /// The map of inherited item keys to their comments.
36    Inheritdoc(HashMap<String, Comments>),
37    /// The git source output.
38    /// The git url of the item path.
39    GitSource(String),
40    /// The deployments output.
41    /// The deployment address of the item path.
42    Deployments(Vec<Deployment>),
43}
44
45/// Trait for preprocessing and/or modifying existing documents
46/// before writing the to disk.
47pub trait Preprocessor: Debug {
48    /// The id of the preprocessor.
49    /// Used to write data to document context.
50    fn id(&self) -> PreprocessorId;
51
52    /// Preprocess the collection of documents
53    fn preprocess(&self, documents: Vec<Document>) -> Result<Vec<Document>, eyre::Error>;
54}