sailfish/README.md

102 lines
3.1 KiB
Markdown
Raw Permalink Normal View History

2020-06-04 16:39:33 -04:00
<div align="center">
![SailFish](./resources/logo.png)
Simple, small, and extremely fast template engine for Rust
2022-02-19 00:47:00 -05:00
[![Tests](https://github.com/rust-sailfish/sailfish/workflows/Tests/badge.svg)](https://github.com/rust-sailfish/sailfish/actions?query=workflow%3ATests)
2020-06-05 10:42:06 -04:00
[![Version](https://img.shields.io/crates/v/sailfish)](https://crates.io/crates/sailfish)
2022-02-19 00:47:00 -05:00
[![dependency status](https://deps.rs/repo/github/rust-sailfish/sailfish/status.svg)](https://deps.rs/repo/github/rust-sailfish/sailfish)
2023-03-05 06:28:28 -05:00
[![Rust 1.60](https://img.shields.io/badge/rust-1.60+-lightgray.svg)](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html)
2022-02-19 00:47:00 -05:00
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/rust-sailfish/sailfish/blob/master/LICENSE)
2020-06-05 10:42:06 -04:00
2022-04-22 10:51:59 -04:00
[User Guide](https://rust-sailfish.github.io/sailfish/) | [API Docs](https://docs.rs/sailfish) | [Examples](./examples)
2020-06-04 16:39:33 -04:00
</div>
## ✨ Features
2024-03-11 17:33:11 -04:00
- Simple and intuitive syntax inspired by [EJS](https://ejs.co/)
- Include another template file inside template
- Built-in filters
- Minimal dependencies (<15 crates in total)
- Extremely fast (See [benchmarks](https://github.com/djc/template-benchmarks-rs))
- Better error message
- Syntax highlighting support ([vscode](./syntax/vscode), [vim](./syntax/vim))
- Works on Rust 1.60 or later
2020-06-04 16:39:33 -04:00
## 🐟 Example
Dependencies:
```toml
[dependencies]
sailfish = "0.8.3"
2020-06-04 16:39:33 -04:00
```
Template file (templates/hello.stpl):
```erb
2020-06-04 16:39:33 -04:00
<html>
<body>
2020-06-19 05:27:19 -04:00
<% for msg in &messages { %>
<div><%\html msg %></div>
2020-06-19 05:27:19 -04:00
<% } %>
2020-06-04 16:39:33 -04:00
</body>
</html>
```
Code:
```rust
2024-03-11 17:33:11 -04:00
use sailfish::RenderOnce;
2020-06-04 16:39:33 -04:00
2024-03-11 17:33:11 -04:00
#[derive(RenderOnce)]
2020-06-04 16:39:33 -04:00
#[template(path = "hello.stpl")]
2020-06-19 05:27:19 -04:00
struct HelloTemplate {
messages: Vec<String>
2020-06-04 16:39:33 -04:00
}
fn main() {
2020-06-19 05:27:19 -04:00
let ctx = HelloTemplate {
2020-12-24 01:53:35 -05:00
messages: vec![String::from("foo"), String::from("bar")],
};
2020-06-19 05:27:19 -04:00
println!("{}", ctx.render_once().unwrap());
2020-06-04 16:39:33 -04:00
}
```
You can find more examples in [examples](./examples) directory.
## 🐾 Roadmap
2024-03-11 17:33:11 -04:00
- `Render` derive macro ([RFC](https://github.com/rust-sailfish/sailfish/issues/3))
- Template inheritance (block, partials, etc.)
2020-06-04 16:39:33 -04:00
## 👤 Author
2020-07-02 05:28:22 -04:00
🇯🇵 **Ryohei Machida**
2020-06-04 16:39:33 -04:00
2024-03-11 17:33:11 -04:00
- GitHub: [@Kogia-sima](https://github.com/Kogia-sima)
2020-06-04 16:39:33 -04:00
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
2022-02-19 00:47:00 -05:00
Since sailfish is an immature library, there are many [planned features](https://github.com/rust-sailfish/sailfish/labels/Type%3A%20RFC) that is on a stage of RFC. Please leave a comment if you have an idea about its design!
2020-06-19 05:27:19 -04:00
2022-04-22 10:51:59 -04:00
Also I welcome any pull requests to improve sailfish! Find issues with [Status: PR Welcome](https://github.com/rust-sailfish/sailfish/issues?q=is%3Aissue+is%3Aopen+label%3A%22Status%3A+PR+Welcome%22) label, and [let's create a new pull request](https://github.com/rust-sailfish/sailfish/pulls)!
2020-06-04 16:39:33 -04:00
## Show your support
Give a ⭐️ if this project helped you!
## 📝 License
Copyright © 2020 [Ryohei Machida](https://github.com/Kogia-sima).
2022-02-19 00:47:00 -05:00
This project is [MIT](https://github.com/rust-sailfish/sailfish/blob/master/LICENSE) licensed.
2020-06-04 16:39:33 -04:00
2024-03-11 17:33:11 -04:00
---
2020-06-04 16:39:33 -04:00
_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_