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::SwordServiceProviderfor Laravel Rust>=0.1.0, <0.3.0.dump: development-only@dump. It also needsConfig::dump(true)and alocalortestingenvironment.
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 <Ada>");Sword::render resolves dotted names to .sword.html files under ordered template roots, resources/views by default. Guides:
- Usage: rendering, components, layouts, loops and directives
- Configuration
- Components, including typed components
- Authentication and authorization
- Environment, session and context
@dump- Tracing and async use
- Template cache
- Stacks, once and fragments
- Validation bags and loops
- Diagnostics
- Expression contract
- Laravel adapter
§Testing
cargo test
cargo test --features laravel,dumpSee all quality checks.
§Changelog
See CHANGELOG.md.
§Contributing
See CONTRIBUTING.md and the Rust API Guidelines.
§License
MIT. See LICENSE.md.
Structs§
- Auth
Context - 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.
- Cache
Stats - Snapshot of the renderer’s bounded in-memory cache.
- Component
Error - A failure while registering or preparing a typed component.
- Config
- Validated renderer configuration.
- Config
Builder - Builds a
Config. Values set on the builder override environment-derived ones. - Html
- Trusted markup in a prop. A plain
Stringis always escaped when printed; anHtmlfield is printed as it is, likeView::with_htmldata. - Sword
- A renderer with ordered template roots.
Enums§
- Config
Error - 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:
@productioncontent 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.