An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Horrorshow

[![Documentation](https://docs.rs/mio/badge.svg)](https://docs.rs/horrorshow/)
[![crates.io](https://img.shields.io/crates/v/horrorshow.svg)](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. 1
  2. \
  3. 2
  4. \
  5. 3
  6. \
  7. 4
  8. \
  9. 5
  10. \
  11. 6
  12. \
  13. 7
  14. \
  15. 8
  16. \
  17. 9
  18. \
  19. 10
  20. \
\


\

Easy!

\
\