From 01df904bb385a51e166d2f79705c93d16cedd829 Mon Sep 17 00:00:00 2001 From: Jaime Valdemoros Date: Sun, 7 Jan 2018 15:24:37 +0000 Subject: [PATCH] Initial Preprocessor trait implementation --- src/book/mod.rs | 15 ++++++++++++++- src/preprocess/mod.rs | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/book/mod.rs b/src/book/mod.rs index 4101f6a9..a50726d3 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -23,7 +23,7 @@ use toml::Value; use utils; use renderer::{CmdRenderer, HtmlHandlebars, RenderContext, Renderer}; -use preprocess; +use preprocess::{self, Preprocessor}; use errors::*; use config::Config; @@ -40,6 +40,9 @@ pub struct MDBook { /// The URL used for live reloading when serving up the book. pub livereload: Option, + + /// List of pre-processors to be run on the book + preprocessors: Vec> } impl MDBook { @@ -86,12 +89,15 @@ impl MDBook { let renderers = determine_renderers(&config); + let preprocessors = vec![]; + Ok(MDBook { root, config, book, renderers, livereload, + preprocessors, }) } @@ -192,6 +198,13 @@ impl MDBook { self } + /// You can add a new preprocessor by using this method. + /// The only requirement is for your renderer to implement the Preprocessor trait. + pub fn with_preprecessor(&mut self, preprocessor: P) -> &mut Self { + self.preprocessors.push(Box::new(preprocessor)); + self + } + /// Run `rustdoc` tests on the book, linking against the provided libraries. pub fn test(&mut self, library_paths: Vec<&str>) -> Result<()> { let library_args: Vec<&str> = (0..library_paths.len()) diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index 19b2f4d4..6f4fb21d 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -1 +1,5 @@ pub mod links; + +pub trait Preprocessor { + +} \ No newline at end of file