Find a file
2025-03-18 13:05:42 -04:00
.github Update MSRV to fix CI issues 2024-06-11 08:39:09 -04:00
assets/javascripts/workers/templates Improve comment syntax 2025-03-12 18:02:23 -04:00
benches doc: Fix typo 2021-01-01 18:21:39 +09:00
docs Refactor to support custom escaping schemes 2025-03-12 19:55:39 -04:00
examples Refactor to support custom escaping schemes 2025-03-12 19:55:39 -04:00
resources Update icon.xcf, logo128.png, .gitignore, and 8383 more files 2024-10-04 11:36:36 -04:00
sailfish Remove #[doc(hidden)] from Buffer::clear 2025-03-18 13:05:42 -04:00
sailfish-compiler Allow any ASCII whitespace instead of just space after <% 2025-03-12 19:55:43 -04:00
sailfish-macros Unify Render* and Template* traits 2025-03-12 18:01:42 -04:00
sailfish-tests/integration-tests Fix default impl of Escape::escape_to_buf and add a simple test case for EscapeJsonString 2025-03-13 19:01:45 -04:00
scripts Update The Build Docs Script To Make It Easier To Use Next Time 2024-06-08 10:32:27 -04:00
syntax Don't track node_modules 2025-03-13 13:39:31 -04:00
.gitattributes Add .gitattributes 2020-06-10 00:00:20 +09:00
.gitignore Add source code 2020-06-05 22:31:38 +09:00
Cargo.lock Refactor to support custom escaping schemes 2025-03-12 19:55:39 -04:00
Cargo.toml Update To Latest Version 2024-08-25 20:55:36 -04:00
CHANGELOG.md Add breaking config feature change to CHANGELOG.md 2023-06-21 09:30:54 +02:00
codecov.yml Add codecov.yml 2020-12-30 03:26:24 +09:00
LICENSE Add source code 2020-06-05 22:31:38 +09:00
netlify.toml Add documentation sources 2020-06-09 21:19:59 +09:00
README.md Unify Render* and Template* traits 2025-03-12 18:01:42 -04:00
requirements.txt Update actix.stpl, header.stpl, and 53 more files... 2022-11-29 16:34:26 -05:00
runtime.txt Update Python version 2020-06-09 21:34:46 +09:00
rustfmt.toml Add source code 2020-06-05 22:31:38 +09:00
THIRD_PARTY Add THIRD_PARTY 2020-12-23 22:39:31 +09:00

SailFish

Simple, small, and extremely fast template engine for Rust

TestsVersiondependency statusRust 1.60License: MIT

User Guide | API Docs | Examples

Features

  • Simple and intuitive syntax inspired by EJS
  • Include another template file inside template
  • Built-in filters
  • Minimal dependencies (<15 crates in total)
  • Extremely fast (See benchmarks)
  • Better error message
  • Syntax highlighting support (vscode, vim)
  • Works on Rust 1.60 or later

🐟 Example

Dependencies:

[dependencies]
sailfish = "0.9.0"

You can choose to use TemplateSimple to access fields directly:

Template file (templates/hello.stpl):

<html>
  <body>
    <% for msg in messages { %>
      <div><%= msg %></div>
    <% } %>
  </body>
</html>

Code:

use sailfish::TemplateSimple;

#[derive(TemplateSimple)]
#[template(path = "hello.stpl")]
struct HelloTemplate {
    messages: Vec<String>
}

fn main() {
    let ctx = HelloTemplate {
        messages: vec![String::from("foo"), String::from("bar")],
    };
    println!("{}", ctx.render_once_to_string().unwrap());
}

Or use the more powerful Template/TemplateMut/TemplateOnce:

Template file (templates/hello.stpl):

<html>
  <body>
    <% for msg in &self.messages { %>
      <div><%= msg %></div>
    <% } %>
    <div><%= self.say_hello() %></div>
  </body>
</html>

Code:

use sailfish::Template;

#[derive(Template)]
#[template(path = "hello.stpl")]
struct HelloTemplate {
    messages: Vec<String>
}

impl HelloTemplate {
    fn say_hello(&self) -> String {
        String::from("Hello!")
    }
}

fn main() {
    let ctx = HelloTemplate {
        messages: vec![String::from("foo"), String::from("bar")],
    };
    println!("{}", ctx.render().unwrap());
}

You can find more examples in examples directory.

🐾 Roadmap

  • Template trait (RFC)
  • Template inheritance (block, partials, etc.)

👤 Author

🇯🇵 Ryohei Machida

🤝 Contributing

Contributions, issues and feature requests are welcome!

Since sailfish is an immature library, there are many planned features that is on a stage of RFC. Please leave a comment if you have an idea about its design!

Also I welcome any pull requests to improve sailfish! Find issues with Status: PR Welcome label, and let's create a new pull request!

Show your support

Give a if this project helped you!

📝 License

Copyright © 2020 Ryohei Machida.

This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator