docx-templating 1.0.0

Rust library for DOCX templating with variable replacement, conditionals, and loops
Documentation
//! # Table Data Export — Product Catalogue
//!
//! Exports a product catalogue to a formatted Word table using a
//! table-row loop. The header row (outside the loop) is preserved as-is;
//! the template row is replaced by one row per product.
//!
//! **First run:** `cargo run --bin gen-examples`
//! **Then:** `cargo run --example 09_table_data_export`

use docx_templating::Template;
use serde_json::json;
use std::path::Path;

fn main() {
    let template = Template::from_path("examples/input/catalogue.docx")
        .expect("template not found — run `cargo run --bin gen-examples` first");

    let context = json!({
        "export_date": "2026-08-14",
        "products": [
            { "sku": "KB-001", "name": "Mechanical Keyboard",     "price": "$89.99",  "stock": "150" },
            { "sku": "MS-002", "name": "Wireless Mouse",           "price": "$34.99",  "stock": "89"  },
            { "sku": "MN-003", "name": "27in 4K Monitor",          "price": "$449.99", "stock": "23"  },
            { "sku": "HS-004", "name": "Noise-Cancelling Headset", "price": "$129.99", "stock": "67"  },
            { "sku": "WC-005", "name": "1080p Webcam",             "price": "$79.99",  "stock": "204" }
        ]
    });

    let rendered = template.render(context).expect("render");

    let out_dir = Path::new("examples/output");
    let out_path = out_dir.join("catalogue.docx");
    rendered.write_to_file(&out_path).expect("write");

    println!("Written: {}", out_path.display());
    println!("5 product rows generated; header row preserved.");
}