• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

benches/H03-May-2022-5949

ci/H03-May-2022-1815

src/H03-May-2022-1,9621,443

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D26-Jan-201930 43

.travis.ymlH A D26-Jan-2019408 3928

CHANGELOG.mdH A D17-May-2019683 2316

CONTRIBUTING.mdH A D26-Jan-20192.6 KiB6841

Cargo.tomlH A D01-Jan-19701.2 KiB4236

Cargo.toml.orig-cargoH A D17-May-2019596 2822

LICENSE-APACHEH A D26-Jan-201910.6 KiB202169

LICENSE-MITH A D26-Jan-20191 KiB2622

README.mdH A D26-Jan-20194.6 KiB13495

README.md

1<h1 align="center">TinyTemplate</h1>
2
3<div align="center">Minimal Lightweight Text Templating</div>
4
5<div align="center">
6    <a href="https://docs.rs/tinytemplate/">API Documentation</a>
7    |
8    <a href="https://github.com/bheisler/TinyTemplate/blob/master/CHANGELOG.md">Changelog</a>
9</div>
10
11<div align="center">
12	<a href="https://travis-ci.org/bheisler/TinyTemplate">
13        <img src="https://travis-ci.org/bheisler/TinyTemplate.svg?branch=master" alt="Travis-CI">
14    </a>
15    |
16    <a href="https://crates.io/crates/tinytemplate">
17        <img src="https://img.shields.io/crates/v/tinytemplate.svg" alt=Crates.io">
18    </a>
19</div>
20
21TinyTemplate is a small, minimalistic text templating system with limited dependencies.
22
23## Table of Contents
24- [Table of Contents](#table-of-contents)
25  - [Goals](#goals)
26  - [Why TinyTemplate?](#why-tinytemplate)
27  - [Quickstart](#quickstart)
28  - [Compatibility Policy](#compatibility-policy)
29  - [Contributing](#contributing)
30  - [Maintenance](#maintenance)
31  - [License](#license)
32
33### Goals
34
35 The primary design goals are:
36
37 - __Small__: TinyTemplate deliberately does not support many features of more powerful template engines.
38 - __Simple__: TinyTemplate presents a minimal but well-documented user-facing API.
39 - __Lightweight__: TinyTemplate has minimal required dependencies.
40
41Non-goals include:
42
43- __Extensibility__: TinyTemplate supports custom value formatters, but that is all.
44- __Performance__: TinyTemplate provides decent performance, but other template engines are faster.
45
46### Why TinyTemplate?
47
48I created TinyTemplate after noticing that none of the existing template libraries really suited my
49needs for Criterion.rs. Some had large dependency trees to support features that I didn't use. Some
50required adding a build script to convert templates into code at runtime, in search of extreme
51performance that I didn't need. Some had elaborate macro-based DSL's to generate HTML, where I just
52wanted plain text with some markup. Some expect the templates to be provided in a directory of text
53files, but I wanted the template to be included in the binary. I just wanted something small and
54minimal with good documentation but there was nothing like that out there so I wrote my own.
55
56TinyTemplate is well-suited to generating HTML reports and similar text files. It could be used for
57generating HTML or other text in a web-server, but for more-complex use cases another template
58engine may be a better fit.
59
60### Quickstart
61
62First, add TinyTemplate and serde-derive to your `Cargo.toml` file:
63
64```toml
65[dependencies]
66tinytemplate = "1.0"
67serde_derive = "1.0"
68```
69
70Then add this code to "src.rs":
71
72```rust
73#[macro_use]
74extern crate serde_derive;
75extern crate tinytemplate;
76
77use tinytemplate::TinyTemplate;
78use std::error::Error;
79
80#[derive(Serialize)]
81struct Context {
82    name: String,
83}
84
85static TEMPLATE : &'static str = "Hello {name}!";
86
87pub fn main() -> Result<(), Box<dyn Error>> {
88    let mut tt = TinyTemplate::new();
89    tt.add_template("hello", TEMPLATE)?;
90
91    let context = Context {
92        name: "World".to_string(),
93    };
94
95    let rendered = tt.render("hello", &context)?;
96    println!("{}", rendered);
97
98    Ok(())
99}
100```
101
102This should print "Hello World!" to stdout.
103
104### Compatibility Policy
105
106TinyTemplate supports the last three stable minor releases of Rust. At time of writing, this means
107Rust 1.29 or later. Older versions may work, but are not tested or guaranteed.
108
109Currently, the oldest version of Rust believed to work is 1.26. Future versions of TinyTemplate may
110break support for such old versions, and this will not be considered a breaking change. If you
111require TinyTemplate to work on old versions of Rust, you will need to stick to a
112specific patch version of TinyTemplate.
113
114### Contributing
115
116Thanks for your interest! Contributions are welcome.
117
118Issues, feature requests, questions and bug reports should be reported via the issue tracker above.
119In particular, becuase TinyTemplate aims to be well-documented, please report anything you find
120confusing or incorrect in the documentation.
121
122Code or documentation improvements in the form of pull requests are also welcome. Please file or
123comment on an issue to allow for discussion before doing a lot of work, though.
124
125For more details, see the [CONTRIBUTING.md file](https://github.com/bheisler/TinyTemplate/blob/master/CONTRIBUTING.md).
126
127### Maintenance
128
129TinyTemplate was created and is currently maintained by Brook Heisler (@bheisler).
130
131### License
132
133TinyTemplate is dual-licensed under the Apache 2.0 license and the MIT license.
134