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

..03-May-2022-

.github/workflows/H03-May-2022-4838

benches/H03-May-2022-5949

src/H03-May-2022-2,4231,865

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

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D26-Jan-201930 43

CHANGELOG.mdH A D03-Jan-20211.7 KiB4736

CONTRIBUTING.mdH A D26-Jan-20192.6 KiB6841

Cargo.tomlH A D01-Jan-19701.2 KiB4236

Cargo.toml.orig-cargoH A D03-Jan-2021596 2822

LICENSE-APACHEH A D26-Jan-201910.6 KiB202169

LICENSE-MITH A D26-Jan-20191 KiB2622

README.mdH A D03-Jan-20214.5 KiB13091

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