Skip to content

Commit

Permalink
Fixed the build.use-default-preprocessors flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Sep 9, 2018
1 parent 40ede19 commit 18a36ec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/book/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,20 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
.and_then(|value| value.as_table())
.map(|table| table.keys());

let mut preprocessors = if config.build.use_default_preprocessors {
default_preprocessors()
} else {
Vec::new()
};

let preprocessor_keys = match preprocessor_keys {
Some(keys) => keys,
// If no preprocessor field is set, default to the LinkPreprocessor and
// IndexPreprocessor. This allows you to disable default preprocessors
// by setting "preprocess" to an empty list.
None => return Ok(default_preprocessors()),
None => return Ok(preprocessors),
};

let mut preprocessors: Vec<Box<Preprocessor>> = Vec::new();

for key in preprocessor_keys {
match key.as_ref() {
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
Expand Down Expand Up @@ -477,6 +481,16 @@ mod tests {
assert_eq!(got.as_ref().unwrap()[1].name(), "index");
}

#[test]
fn use_default_preprocessors_works() {
let mut cfg = Config::default();
cfg.build.use_default_preprocessors = false;

let got = determine_preprocessors(&cfg).unwrap();

assert_eq!(got.len(), 0);
}

#[test]
fn config_complains_if_unimplemented_preprocessor() {
let cfg_str: &'static str = r#"
Expand Down
6 changes: 5 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ mod tests {
[build]
build-dir = "outputs"
create-missing = false
preprocess = ["first_preprocessor", "second_preprocessor"]
use-default-preprocessors = true
[output.html]
theme = "./themedir"
Expand All @@ -575,6 +575,10 @@ mod tests {
[output.html.playpen]
editable = true
editor = "ace"
[preprocess.first]
[preprocess.second]
"#;

#[test]
Expand Down

0 comments on commit 18a36ec

Please sign in to comment.