Skip to main content

Crate rustysan_sword

Crate rustysan_sword 

Source
Expand description

§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;");

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.

Structs§

AuthContext
What a view may know about the current user: whether they are logged in, and the outcome of the authorization checks the template asks about.
CacheStats
Snapshot of the renderer’s bounded in-memory cache.
ComponentError
A failure while registering or preparing a typed component.
Config
Validated renderer configuration.
ConfigBuilder
Builds a Config. Values set on the builder override environment-derived ones.
Html
Trusted markup in a prop. A plain String is always escaped when printed; an Html field is printed as it is, like View::with_html data.
Sword
A renderer with ordered template roots.

Enums§

ConfigError
An invalid Sword configuration. Messages never include variable values.
Error
A Sword lookup, syntax, or rendering failure.

Constants§

CACHE_CAPACITY_ENV
Environment variable holding the template cache capacity.
DEFAULT_CACHE_CAPACITY
Default number of cached templates.
DEFAULT_ENVIRONMENT
The environment name used when none is configured. It is the conservative one, as in Laravel: @production content shows and @env('local') content does not.
ENVIRONMENT_ENV
Environment variable holding the application environment name, such as local.
MAX_CACHE_CAPACITY
Largest accepted cache capacity. The limit counts templates, not bytes.
MAX_ENVIRONMENT_LEN
Longest accepted environment name.
VIEWS_ENV
Environment variable holding template roots, separated like PATH.

Traits§

Component
A component whose props are a Rust struct.