text-template 0.1.0

Small template engine for use with plain text (e.g. creating text email), not intended for HTML.
Documentation
  • Coverage
  • 53.85%
    7 out of 13 items documented1 out of 8 items with examples
  • Size
  • Source code size: 13.72 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.13 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • boeckmann

Simple text template engine for rust

This library implements text templates with named placeholder elements like Hello ${title }${name}. The space after title is significant in the sense that it is only included in the output if title is not empty. This is to prevent two consecutive whitespaces for example if a person has no title.

Please see https://docs.rs/crate/text-template for API documentation.

Example

use text_template::*;
use std::collections::HashMap;
 
let template = Template::from("Hello ${title }${name}");
 
let mut values = HashMap::new();
values.insert("name", "Jane");
 
let text = template.fill_in(&values);

assert_eq!(text.to_string(), "Hello Jane");
assert_eq!(template.to_string(), "Hello ${title }${name}");