1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! # docx-templating
//!
//! A Rust library for generating Microsoft Word documents (`.docx`) from templates
//! with variable placeholders, conditional sections, and loops.
//!
//! ## Features
//!
//! - **Variable replacement**: `{{user.name}}` with nested path support
//! - **Conditionals**: `{% if condition %} ... {% elif condition %} ... {% else %} ... {% endif %}`
//! - **Comparisons and boolean logic**: `{% if total > 100 and paid %}`
//! - **Arithmetic**: `{{price * quantity}}`, `{{subtotal - discount}}`
//! - **Loops**: `{% for item in items %} ... {% endfor %}`
//! - **Filters**: `{{name | upper}}`, `{{nickname | default: "friend"}}`,
//! `{{total | round: 2}}`, `{{created_at | date: "%Y-%m-%d"}}`, and custom
//! filters on [`TemplateOptions`]
//! - **Headers, footers, footnotes and endnotes**: opt in with
//! [`TemplateOptions::headers_and_footers`] and [`TemplateOptions::footnotes`]
//! - **Safe XML handling**: Automatic escaping, no injection vulnerabilities
//! - **Typed context**: render accepts JSON or any borrowed `serde::Serialize` value
//!
//! ## Architecture
//!
//! The crate is a pipeline with typed boundaries:
//!
//! 1. **Domain** (`domain`) - the lossless document tree, template binding,
//! placement, resolved plan and evaluator. It never touches XML, ZIP or the
//! filesystem.
//! 2. **Adapters** (`adapters`) - parse XML into the document model and write it
//! back, and read and write the DOCX package.
//! 3. **Public API** - `Template`, `Context`, `IntoContext`, `RenderedDocument`,
//! options and errors.
//!
//! `tests/architecture.rs` enforces the boundary between the domain and the
//! adapters.
//!
//! ## Example
//!
//! ```rust,no_run
//! use docx_templating::Template;
//! use serde_json::json;
//!
//! let data = json!({
//! "user": {
//! "name": "Ada Lovelace"
//! }
//! });
//!
//! let output = Template::from_path("template.docx")?
//! .render(data)?;
//!
//! output.write_to_file("output.docx")?;
//! # Ok::<(), docx_templating::Error>(())
//! ```
//!
//! Any borrowed [`serde::Serialize`] value works as the context, so a caller can
//! pass their own struct instead of building JSON:
//!
//! ```rust,no_run
//! use docx_templating::Template;
//! use serde::Serialize;
//!
//! #[derive(Serialize)]
//! struct Invoice {
//! total: u32,
//! }
//!
//! # fn example() -> docx_templating::Result<()> {
//! let template = Template::from_path("template.docx")?;
//! let rendered = template.render(&Invoice { total: 42 })?;
//! rendered.write_to_file("output.docx")?;
//! # Ok(())
//! # }
//! ```
//!
//! For a template that is rendered once, [`render`] loads and renders it in a
//! single call:
//!
//! ```rust,no_run
//! # fn example() -> docx_templating::Result<()> {
//! let rendered = docx_templating::render(
//! "template.docx",
//! serde_json::json!({ "name": "Ada" }),
//! )?;
//! rendered.write_to_file("output.docx")?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Status
//!
//! **Current version: 1.0.0**, with every phase of the roadmap implemented.
//! Variable replacement, conditionals, paragraph loops, table-row loops,
//! multi-part rendering and hardening are production-ready.
//! The public API is frozen for 1.x: new features are additive and breaking
//! changes wait for 2.0.
//!
//! The main document is always rendered. Headers, footers, footnotes and
//! endnotes are rendered when
//! [`TemplateOptions::headers_and_footers`] and [`TemplateOptions::footnotes`]
//! ask for it; otherwise those parts are copied through unchanged.
//!
// Public modules
// Pipeline layers. The domain is pure; the adapters translate formats.
// Public API surface
// Public re-exports
pub use ;
pub use ;
pub use BindingError;
pub use RenderError;
pub use PlanError;
pub use ;
pub use ;
pub use ;
pub use RenderedDocument;
pub use ;