pub struct TemplateOptions {
pub missing_value_policy: MissingValuePolicy,
pub line_break_policy: LineBreakPolicy,
pub preserve_whitespace: bool,
pub headers_and_footers: bool,
pub footnotes: bool,
pub filters: FilterRegistry,
}Expand description
Configuration options for template rendering.
§Examples
use docx_templating::{TemplateOptions, MissingValuePolicy, LineBreakPolicy};
let options = TemplateOptions::default()
.missing_value_policy(MissingValuePolicy::Empty)
.line_break_policy(LineBreakPolicy::SplitParagraph)
.preserve_whitespace(false);Fields§
§missing_value_policy: MissingValuePolicyPolicy for missing variables.
line_break_policy: LineBreakPolicyPolicy for newline characters in resolved values.
preserve_whitespace: boolWhether to emit xml:space="preserve" on <w:t> elements whose
replacement text has leading or trailing whitespace.
When true (the default) the rewriter adds the attribute automatically
so Word does not strip significant spaces from the rendered value.
Set to false to suppress the attribute entirely, letting Word apply
its own whitespace-normalisation rules.
Whether headers and footers are templated.
When false (the default) word/header*.xml and word/footer*.xml
are copied into the output unchanged, so a placeholder in a header
stays as written.
footnotes: boolWhether footnotes and endnotes are templated.
When false (the default) word/footnotes.xml and
word/endnotes.xml are copied into the output unchanged.
filters: FilterRegistryFilters available to the template.
Starts with the built in text filters upper, lower, trim,
default, len and join and the number filters round, fixed,
thousands and percent. The dates feature also adds date and
timezone. Add or replace a filter with TemplateOptions::filter.
Implementations§
Source§impl TemplateOptions
impl TemplateOptions
Sourcepub fn missing_value_policy(self, policy: MissingValuePolicy) -> Self
pub fn missing_value_policy(self, policy: MissingValuePolicy) -> Self
Set the missing value policy.
Sourcepub fn line_break_policy(self, policy: LineBreakPolicy) -> Self
pub fn line_break_policy(self, policy: LineBreakPolicy) -> Self
Set the line break policy.
Sourcepub fn preserve_whitespace(self, preserve: bool) -> Self
pub fn preserve_whitespace(self, preserve: bool) -> Self
Set whether to preserve edge whitespace in replacement values.
When true (the default) the rewriter emits xml:space="preserve" on
<w:t> elements whose replacement text starts or ends with whitespace,
preventing Word from stripping those spaces. Set to false to suppress
the attribute and let Word normalise whitespace itself.
Set whether headers and footers are templated.
Disabled by default. Enable it when the template puts placeholders in a header or a footer.
§Examples
use docx_templating::TemplateOptions;
let options = TemplateOptions::default().headers_and_footers(true);
assert!(options.headers_and_footers);Sourcepub fn footnotes(self, process: bool) -> Self
pub fn footnotes(self, process: bool) -> Self
Set whether footnotes and endnotes are templated.
Disabled by default. Enable it when the template puts placeholders in a footnote or an endnote.
§Examples
use docx_templating::TemplateOptions;
let options = TemplateOptions::default().footnotes(true);
assert!(options.footnotes);Sourcepub fn filter<F>(self, name: impl Into<String>, filter: F) -> Self
pub fn filter<F>(self, name: impl Into<String>, filter: F) -> Self
Register a filter for {{value | name}} and {{value | name: "arg"}}.
A filter registered here replaces a built in filter with the same name. The closure receives the current value and the optional argument written after a colon, and returns the value for the next filter in the chain.
§Examples
use docx_templating::{FilterError, TemplateOptions};
use serde_json::Value;
let options = TemplateOptions::default().filter("shout", |value, _| {
let text = value
.as_str()
.ok_or_else(|| FilterError::new("value is not a string"))?;
Ok(Value::String(format!("{}!", text.to_uppercase())))
});
assert!(options.filters.contains("shout"));