Initial Preprocessor trait implementation

This commit is contained in:
Jaime Valdemoros 2018-01-07 15:24:37 +00:00
parent bf093e2f5f
commit 01df904bb3
2 changed files with 18 additions and 1 deletions

View File

@ -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<String>,
/// List of pre-processors to be run on the book
preprocessors: Vec<Box<Preprocessor>>
}
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<P: Preprocessor + 'static>(&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())

View File

@ -1 +1,5 @@
pub mod links;
pub trait Preprocessor {
}