SnapFire
An ergonomic web templating engine with live-reload, featuring first-class support for Tera and Actix Web.
SnapFire is designed to provide a seamless and productive development experience for building server-rendered web applications in Rust. It offers a simple, fluent API for integrating the powerful Tera templating engine into an Actix Web application, and its standout feature is a zero-overhead, "it-just-works" live-reload system for development.
Features
- ✅ Simple & Ergonomic API: A clean builder pattern for easy setup and configuration.
- ✅ Full Tera Integration: Use all of Tera's features, including template inheritance, macros, and custom filters.
- ✅ Live Reload for Development: Changes to templates or static assets (
.css) are automatically pushed to the browser, providing instant feedback without a full page refresh. - ✅ Production Optimized: All development features (file watcher, WebSocket, middleware) are compiled out in release builds by default, ensuring zero performance overhead.
- ✅ Robust & Configurable: Sensible defaults for a great out-of-the-box experience, with powerful overrides for custom setups.
Quickstart
1. Add snapfire to your dependencies
# Cargo.toml
[]
= "0.4.0" # Replace with the latest version
= "4"
= "1"
= "0.11"
2. Set up your Actix Web main.rs
This example shows a simple server with two pages and live-reload enabled for development.
// src/main.rs
use ;
use ;
use Context;
// An Actix handler that renders a template.
async
async
3. Create your templates
Create a templates/ directory with an index.html file.
<!-- templates/index.html -->
{{ site_name }} | {{ page_title }}
Hello from SnapFire!
4. Run your app!
# This will run with the "devel" feature enabled.
Now, open your browser to http://127.0.0.1:3000. Try changing your index.html file—the browser will instantly reload!
Production Builds
The live-reload functionality is enabled by a Cargo feature called devel. To build your application for production, you must disable this feature to remove the file watcher, WebSocket server, and script injection middleware.
Your configure_routes and InjectSnapFireScript calls are automatically compiled to no-ops in this case, so you don't need to add any #[cfg] attributes to your own code.
Configuration
SnapFire's TeraWebBuilder provides a fluent API for configuration.
let app_state = builder
// Add global variables available to all templates.
.add_global
.add_global
// For power-users: get direct access to the Tera instance
// before it's finalized to register custom filters, functions, etc.
.configure_tera
// --- Dev-Reload Specific Configuration ---
// Watch an additional directory for changes.
.watch_static
// Customize the WebSocket URL.
.ws_path
// Disable automatic script injection.
.auto_inject_script
.build?;
License
This project is licensed under the Mozilla Public License 2.0. See the LICENSE file for details.