https://github.com/stebalien/horrorshow-rs
A macro-based html builder for rust
https://github.com/stebalien/horrorshow-rs
html-template rust rust-library
Last synced: about 1 year ago
JSON representation
A macro-based html builder for rust
- Host: GitHub
- URL: https://github.com/stebalien/horrorshow-rs
- Owner: Stebalien
- License: apache-2.0
- Created: 2015-05-03T01:05:52.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T15:33:47.000Z (almost 3 years ago)
- Last Synced: 2025-05-11T00:05:06.919Z (about 1 year ago)
- Topics: html-template, rust, rust-library
- Language: Rust
- Homepage: https://docs.rs/horrorshow/
- Size: 1.46 MB
- Stars: 332
- Watchers: 6
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
- Authors: AUTHORS
Awesome Lists containing this project
README
# Horrorshow
[](https://docs.rs/horrorshow/)
[](https://crates.io/crates/horrorshow)
A macro-based html templating library, compatible with stable rust (currently requires rust >= 1.48).
## Features
This crate will degrade gracefully when compiled without `std` (disable the "std"
feature) and even without `alloc` (disable the "alloc" feature).
When compiled with `alloc` but without `std`:
* `Template::write_to_io()` is not defined.
* Templates may only emit errors implementing `ToString` and all such errors are
immediately converted to strings.
When compiled with just core:
* `RenderBox` is no longer defined (no allocation).
* The `Template::into_string()` and `Template::write_to_string()` are no longer
defined. The only template rendering method available is
`Template::write_to_fmt()`.
* Templates may only emit static `&str` errors, and only the first is recorded.
## Example:
```rust
#[macro_use]
extern crate horrorshow;
use horrorshow::prelude::*;
use horrorshow::helper::doctype;
fn main() {
let actual = format!("{}", html! {
: doctype::HTML;
html {
head {
title : "Hello world!";
}
body {
// attributes
h1(id="heading") {
// Insert escaped text
: "Hello! This is \
Hello! This is <html />
\
Let's count to 10!
\
\
- 1
\
- 2
\
- 3
\
- 4
\
- 5
\
- 6
\
- 7
\
- 8
\
- 9
\
- 10
\
\
\
Easy!
\
\