[−][src]Macro hiccup::hiccup
hiccup!
:
- The main objective of this lib is to prevent unclosed html tags. This macro is inspired by Clojures hiccup
Basic usage:
The macro `hiccup! receives a mutable string as the first argument and mutates the string to emit the HTML. The order of the elemnts is:
tag
as the first element.- Optional attribute inside the tag should follow the tag name as
{attribute1=>"value1 vlaue2 ... valuen", attr=>"value"}
. Also, the attributes should be inside{...}
and separate each key value pair by,
. The element should be written askey=>"value"
, where key is a symbol, followed by an arrow (=>
), and then the value as a string"value"
. - After (Optional) the tag name or the attributes
{...}
tou should include[...]
that can have other tags, such asp["text"]
or regular string values.
Differences between Clojure and Rust Hiccup:
- Clojure:
[:a {:href "http://github.com"} "GitHub"]
- Rust:
a{href=>"http://github.com"}["GitHub"]
Example
extern crate hiccup; use hiccup::hiccup; fn main() { let mut html = String::new(); let _ = hiccup!(&mut html, html[ head[meta{name=>"author", content=>"Julia Naomi"} title["Hiccup guide"]] body{class=>"amazing hiccup guide"}[ h1{font=>"bold", color=>"red"}["Hiccup is the best!"] p["please lookup clojure's hiccup for better ideas on this macro"]] ]); assert_eq!(html,"<html><head><meta name=\"author\" content=\"Julia Naomi\"/>\ <title>Hiccup guide</title></head><body class=\"amazing hiccup guide\">\ <h1 font=\"bold\" color=\"red\">Hiccup is the best!</h1>\ <p>please lookup clojure\'s hiccup for better ideas on this macro</p></body></html>"); }