[−][src]Crate bracket
Bracket is a fast and correct implementation of the handlebars general purpose template engine.
It is designed to keep allocations to a minimum by using pointers and string slices into the underlying template wherever possible.
The lexer generates a stream of tokens which are consumed by a parser that transforms them into AST nodes. These nodes can then be stored as compiled templates or passed directly to a renderer.
The goal is to be 100% compatible with the Javascript handlebars implementation; if you notice a discrepancy please report it as a bug.
The main public API is accessed using a Registry which can be used for compiling, rendering, registering partials and configuring helpers.
Errors generated during compilation are of the
SyntaxError type and implement the Debug
trait
which will include the source code that generated the error.
Syntax error, statement is empty --> examples/files/document.md:3:3 | 3 | {{}} | --^
Templates
Templates must always be named so that useful error messages can be generated; if a name is not available the value of unknown will be used as the template name.
Use the registry to compile a template:
let registry = Registry::new(); let template = registry.parse("file-name.md", "{{foo}}").unwrap();
If you are extracting a template from a larger document use ParserOptions to set a line and byte offset:
let registry = Registry::new(); let options = ParserOptions::new(String::from("file-name.md"), 12, 2048); let template = registry.compile("{{foo}}", options).unwrap();
Re-exports
pub use error::Error; |
pub use registry::Registry; |
pub use template::Template; |
pub use escape::EscapeFn; |
Modules
error | Error types. |
escape | Escape function trait and default functions. |
helper | Helper trait and types for the default set of helpers. |
lexer | Iterator for grammar tokens. |
output | Trait and type for rendering to destinations. |
parser | Convert the lexer token stream to AST nodes. |
registry | Primary entry point for compiling and rendering templates. |
render | Render a template to output using the data. |
template | Templates add rendering capability to nodes. |
Type Definitions
RenderResult | Result type returned when rendering templates. |
Result | Result type returned by the registry. |
SyntaxResult | Result type returned when compiling templates. |