allow an empty field name if filters are provided
This is to make it easier for add-ons to provide extra content that degrades nicely on platforms that don't have the add-on.
This commit is contained in:
parent
a34e5b3246
commit
99c45c5fbc
@ -316,6 +316,16 @@ fn render_into(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Replacement { key: "", filters } if !filters.is_empty() => {
|
||||||
|
// if a filter is provided, we accept an empty field name to
|
||||||
|
// mean 'pass an empty string to the filter, and it will add
|
||||||
|
// its own text'
|
||||||
|
rendered_nodes.push(RenderedNode::Replacement {
|
||||||
|
field_name: "".to_string(),
|
||||||
|
current_text: "".to_string(),
|
||||||
|
filters: filters.iter().map(|&f| f.to_string()).collect(),
|
||||||
|
})
|
||||||
|
}
|
||||||
Replacement { key, filters } => {
|
Replacement { key, filters } => {
|
||||||
// apply built in filters if field exists
|
// apply built in filters if field exists
|
||||||
let (text, remaining_filters) = match context.fields.get(key) {
|
let (text, remaining_filters) = match context.fields.get(key) {
|
||||||
@ -741,6 +751,17 @@ mod test {
|
|||||||
text: "{unknown field foo:text:X}".to_owned()
|
text: "{unknown field foo:text:X}".to_owned()
|
||||||
}]
|
}]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// a blank field is allowed if it has filters
|
||||||
|
tmpl = PT::from_text("{{filter:}}").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
tmpl.render(&ctx),
|
||||||
|
vec![FN::Replacement {
|
||||||
|
field_name: "".to_string(),
|
||||||
|
current_text: "".to_string(),
|
||||||
|
filters: vec!["filter".to_string()]
|
||||||
|
}]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_complete_template(nodes: &Vec<RenderedNode>) -> Option<&str> {
|
fn get_complete_template(nodes: &Vec<RenderedNode>) -> Option<&str> {
|
||||||
|
Loading…
Reference in New Issue
Block a user