Fixed the `build.use-default-preprocessors` flag

This commit is contained in:
Michael Bryan 2018-09-09 19:02:50 +08:00
parent 40ede19103
commit 18a36ec1fa
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
2 changed files with 22 additions and 4 deletions

View File

@ -360,16 +360,20 @@ fn determine_preprocessors(config: &Config) -> Result<Vec<Box<Preprocessor>>> {
.and_then(|value| value.as_table()) .and_then(|value| value.as_table())
.map(|table| table.keys()); .map(|table| table.keys());
let mut preprocessors = if config.build.use_default_preprocessors {
default_preprocessors()
} else {
Vec::new()
};
let preprocessor_keys = match preprocessor_keys { let preprocessor_keys = match preprocessor_keys {
Some(keys) => keys, Some(keys) => keys,
// If no preprocessor field is set, default to the LinkPreprocessor and // If no preprocessor field is set, default to the LinkPreprocessor and
// IndexPreprocessor. This allows you to disable default preprocessors // IndexPreprocessor. This allows you to disable default preprocessors
// by setting "preprocess" to an empty list. // 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 { for key in preprocessor_keys {
match key.as_ref() { match key.as_ref() {
"links" => preprocessors.push(Box::new(LinkPreprocessor::new())), "links" => preprocessors.push(Box::new(LinkPreprocessor::new())),
@ -477,6 +481,16 @@ mod tests {
assert_eq!(got.as_ref().unwrap()[1].name(), "index"); 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] #[test]
fn config_complains_if_unimplemented_preprocessor() { fn config_complains_if_unimplemented_preprocessor() {
let cfg_str: &'static str = r#" let cfg_str: &'static str = r#"

View File

@ -564,7 +564,7 @@ mod tests {
[build] [build]
build-dir = "outputs" build-dir = "outputs"
create-missing = false create-missing = false
preprocess = ["first_preprocessor", "second_preprocessor"] use-default-preprocessors = true
[output.html] [output.html]
theme = "./themedir" theme = "./themedir"
@ -575,6 +575,10 @@ mod tests {
[output.html.playpen] [output.html.playpen]
editable = true editable = true
editor = "ace" editor = "ace"
[preprocess.first]
[preprocess.second]
"#; "#;
#[test] #[test]