Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/giodamelio/edo
A super simple templating library for Rust.
https://github.com/giodamelio/edo
Last synced: 11 days ago
JSON representation
A super simple templating library for Rust.
- Host: GitHub
- URL: https://github.com/giodamelio/edo
- Owner: giodamelio
- License: mit
- Created: 2016-12-24T05:01:42.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-30T07:26:40.000Z (over 6 years ago)
- Last Synced: 2024-10-20T00:51:32.795Z (23 days ago)
- Language: Rust
- Homepage:
- Size: 35.2 KB
- Stars: 3
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Edo
[![Crates.io Version](https://img.shields.io/crates/v/edo.svg)](https://crates.io/crates/edo) [![Build Status](https://travis-ci.org/giodamelio/edo.svg?branch=master)](https://travis-ci.org/giodamelio/edo) [![Dependency Status](https://dependencyci.com/github/giodamelio/edo/badge)](https://dependencyci.com/github/giodamelio/edo)A super simple templating library for Rust.
[Documentation](https://docs.rs/edo)
# Examples
You can use a simple static replacement.
```rust
use edo::Edo;let mut template: Edo<&str> = Edo::new("Hello {name}").unwrap();
template.register_static("name", "World!");
let output = template.render("");
assert_eq!(output, "Hello World!");
```You can also use a handler function to calculate the value.
```rust
use edo::Edo;let mut template: Edo<&str> = Edo::new("Hello {name}").unwrap();
template.register_handler("name", |_, _| Ok("World!".to_string()));
let output = template.render("");
assert_eq!(output, "Hello World!");
```Your handlers can also take arguments (As a `Vec`).
```rust
use edo::Edo;let mut template: Edo<&str> = Edo::new("{say_hello(World)}").unwrap();
template.register_handler("say_hello", |args, _| Ok(format!("Hello {}", args[0])));
let output = template.render("");
assert_eq!(output, "Hello World");
```Your handlers also take a context argument at render time.
```rust
use edo::Edo;let mut template: Edo<&str> = Edo::new("{say_hello(World)}").unwrap();
template.register_handler("say_hello", |args, _| Ok(format!("Hello {}", args[0])));
let output = template.render("");
assert_eq!(output, "Hello World");
```# License
This code is distributed under the MIT license