Fixed the `build.use-default-preprocessors` flag
This commit is contained in:
parent
40ede19103
commit
18a36ec1fa
|
@ -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#"
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Reference in New Issue