Hiccup
A Clojure's Hiccup inspired macro. At the moment support for inline code execution is not guaranteed. The main objective of this lib is to prevent unclosed html tags.
Basic elements:
The macro `hiccup! receives a mutable string as the first argument and mutates the string to emit the HTML. The order of the elements is:
tag
as the first element.- Optional attribute inside the tag should follow the tag name as
{attribute1=>"value1 value2 ... 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
{...}
you could include[...]
that can have other tags, such asp["text"]
or regular string values. - Inside the
[...]
you also can substitute your string for some simple rust code inside a(...)
. This can bem something likep[format!("{:?}", 3 + 4)]
ordiv[(x)]
where x was defined in the outside.
Differences between Clojure and Rust Hiccup:
- Clojure:
[:a {:href "http://github.com"} "GitHub"]
- Rust:
a{href=>"http://github.com"}["GitHub"]
Usage
Add dependency to Cargo.toml
:
[]
= "0.1.6"
Code example with hiccup!
macro:
use hiccup;
With remote code execution:
let mut html_inner = String new;
let mut html_outer = String new;
let x = "inner my str";
let y = "my str2";
let z = "my str3";
let _ = hiccup!;
let _ = hiccup!;
assert_eq!;
Contribution
Add the feature you included in the macro as the name of the PR with tests