rustysan-sword 0.1.1

Blade-inspired HTML templates for Rust
Documentation

rustysan-sword

Blade-inspired HTML templates for Rust. Templates are .sword.html files that Sword translates to MiniJinja, which it uses privately, and renders against serde data.

Installation

Use a local checkout until the renamed crate is published.

[dependencies]
rustysan-sword = { path = "../rustysan-sword" }
# With Laravel Rust:
# rustysan-sword = { path = "../rustysan-sword", features = ["laravel"] }

Features, none of them on by default:

  • laravel: rustysan_sword::laravel::SwordServiceProvider for Laravel Rust >=0.1.0, <0.3.0.
  • dump: development-only @dump. It also needs Config::dump(true) and a local or testing environment.

Requires Rust 1.99+, the same as Laravel Rust. Tested against Laravel Rust 0.1.0, 0.1.6 and 0.2.0. See installation and setup.

Usage

use rustysan_sword::Sword;
use serde_json::json;

let html = Sword::default().render_source(
    "greeting", "Hello {{ name }}", &json!({"name": "<Ada>"})
)?;
assert_eq!(html, "Hello &lt;Ada&gt;");
# Ok::<(), rustysan_sword::Error>(())

Sword::render resolves dotted names to .sword.html files under ordered template roots, resources/views by default. Guides:

Testing

cargo test
cargo test --features laravel,dump

See all quality checks.

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md and the Rust API Guidelines.

License

MIT. See LICENSE.md.