plf/lib.rs
1//! # Tera
2//!
3//! A powerful, fast and easy-to-use template engine for Rust
4//!
5//! This crate provides an implementation of the Tera template engine, which is designed for use in
6//! Rust applications. Inspired by [Jinja2] and [Django] templates, Tera provides a familiar and
7//! expressive syntax for creating dynamic HTML, XML, and other text-based documents. It supports
8//! template inheritance, variable interpolation, conditionals, loops, filters, and custom
9//! functions, enabling developers to build complex applications with ease.
10//!
11//! See the [site](http://keats.github.io/tera/) for more information and to get started.
12//!
13//! ## Features
14//!
15//! - High-performance template rendering
16//! - Safe and sandboxed execution environment
17//! - Template inheritance and includes
18//! - Expressive and familiar syntax
19//! - Extensible with custom filters and functions
20//! - Automatic escaping of HTML/XML by default
21//! - Template caching and auto-reloading for efficient development
22//! - Built-in support for JSON and other data formats
23//! - Comprehensive error messages and debugging information
24//!
25//! ## Example
26//!
27//! ```rust
28//! use plf::Tera;
29//!
30//! // Create a new Tera instance and add a template from a string
31//! let mut tera = Tera::new();
32//! tera.register_filter("do_nothing", do_nothing_filter);
33//! tera.load_from_glob("examples/basic/templates/**/*")?;
34//! // Prepare the context with some data
35//! let mut context = plf::Context::new();
36//! context.insert("name", "World");
37//!
38//! // Render the template with the given context
39//! let rendered = tera.render("hello", &context)?;
40//! assert_eq!(rendered, "Hello, World!");
41//! ```
42//!
43//! ## Getting Started
44//!
45//! Add the following to your Cargo.toml file:
46//!
47//! ```toml
48//! [dependencies]
49//! tera = "2"
50//! ```
51//!
52//! Then, consult the official documentation and examples to learn more about using Tera in your
53//! Rust projects.
54//!
55//! [Jinja2]: http://jinja.pocoo.org/
56//! [Django]: https://docs.djangoproject.com/en/3.1/topics/templates/
57
58#![deny(missing_docs)]
59
60mod args;
61mod components;
62mod context;
63mod delimiters;
64mod errors;
65mod filters;
66mod functions;
67#[cfg(feature = "glob_fs")]
68mod globbing;
69mod parsing;
70mod reporting;
71mod template;
72mod tera;
73mod tests;
74mod utils;
75/// The value type used by Tera and supporting types (`Key`, `Map`, `Number`, `ValueKind`).
76pub mod value;
77pub(crate) mod vm;
78
79pub use crate::tera::{EscapeFn, Tera};
80pub use args::Kwargs;
81pub use components::{ComponentArg, ComponentArgType, ComponentInfo};
82pub use context::Context;
83pub use delimiters::Delimiters;
84pub use errors::{Error, ErrorKind, TeraResult};
85pub use filters::Filter;
86pub use functions::Function;
87pub use tests::Test;
88pub use utils::escape_html;
89pub use value::number::Number;
90pub use value::{Map, Value};
91pub use vm::state::State;
92
93#[cfg(feature = "glob_fs")]
94#[doc(hidden)]
95pub use globbing::load_from_glob;
96
97#[cfg(feature = "fast_hash")]
98pub(crate) use ahash::{AHashMap as HashMap, AHashSet as HashSet};
99#[cfg(not(feature = "fast_hash"))]
100pub(crate) use std::collections::{HashMap, HashSet};
101
102#[cfg(test)]
103mod snapshot_tests;