1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Snax is an implementation of a JSX-like grammar for Rust. You can use it as
//! part of the `snax` crate, which provides a complete, untyped DOM that's
//! quick to turn into a string.
//!
//! If you're a proc macro author, you can also consume the `snax_syntax` to
//! produce whatever structures you need for your project. This can be used to
//! support a typed DOM or any React-like framework!
//!
//! ## Installation
//! Snax requires Rust 1.32 or newer.
//!
//! It isn't published to crates.io yet, but you can use a Git dependency:
//!
//! ```toml
//! snax = { git = "https://github.com/LPGhatguy/snax.git" }
//! ```
//!
//! Some things are still a bit in flux, so I'm sorry in advance if I break
//! anything!
//!
//! ## Examples
//!
//! ### Simple Page
//! ```rust
//! use snax::snax;
//!
//! fn main() {
//! let page_title = "Hello, world, from Snax!";
//!
//! let page = snax! {
//! /* Snax supports regular multi-line Rust comments. */
//! <html>
//! <head>
//! /*
//! Literal strings need to be quoted, unlike JSX.
//! This makes whitespace much more explicit, which is
//! useful!
//! */
//! <title>"Hello, Snax!"</title>
//! </head>
//! <body>
//! /*
//! Snax supports embedding Rust expressions that return
//! `impl IntoIterator<HtmlContent>`. String and &str work
//! great here!
//! */
//! <h1>
//! { page_title }
//! </h1>
//! </body>
//! </html>
//! };
//!
//! // The result of the snax! macro is HtmlContent.
//! // It implements Display and gives you compact HTML without a doctype!
//! println!("<!doctype html>");
//! println!("{}", page);
//! }
//! ```
//!
//! ### Composition via functions
//! Snax is designed to work well when using functions to reuse pieces of HTML!
//!
//! ```rust
//! use snax::{snax, Fragment, HtmlContent};
//!
//! fn user_widget<'a>(name: &'a str, age: u32) -> HtmlContent<'a> {
//! snax! {
//! <div class="user">
//! { name } " is " { age.to_string() } " years old!"
//! </div>
//! }
//! }
//!
//! fn users() -> HtmlContent<'static> {
//! let users = vec![
//! ("Gandalf", 34),
//! ("Arwen Undómie", 75),
//! ("Primula Brandybuck", 133),
//! ];
//!
//! snax! {
//! <div class="users">
//! { Fragment::new(users.iter().map(|(name, age)| user_widget(name, *age))) }
//! </div>
//! }
//! }
//! ```
//!
//! ## License
//! Snax is available under the MIT license. See [LICENSE.txt](LICENSE.txt) for
//! details.
use proc_macro_hack;
pub use snax;
pub use *;