plait_macros/lib.rs
1//! Procedural macros for the [`plait`](https://docs.rs/plait) HTML templating library.
2//!
3//! This crate provides the [`html!`] and [`component!`] macros. You should depend on the `plait` crate directly -
4//! these macros are re-exported from there with full documentation.
5
6mod ast;
7mod buffer;
8mod codegen;
9mod parse;
10mod utils;
11
12use proc_macro::TokenStream;
13
14/// See [`plait::html!`](https://docs.rs/plait/latest/plait/macro.html.html) for full documentation.
15///
16/// # Example
17///
18/// ```ignore
19/// use plait::{html, ToHtml};
20///
21/// let name = "World";
22/// let page = html! {
23/// div(class: "greeting") {
24/// h1 { "Hello, " (name) "!" }
25/// }
26/// };
27///
28/// assert_eq!(page.to_html(), r#"<div class="greeting"><h1>Hello, World!</h1></div>"#);
29/// ```
30#[proc_macro]
31pub fn html(input: TokenStream) -> TokenStream {
32 codegen::html_impl(input.into()).into()
33}
34
35/// See [`plait::component!`](https://docs.rs/plait/latest/plait/macro.component.html) for full documentation.
36///
37/// # Example
38///
39/// ```ignore
40/// use plait::{component, classes, Class};
41///
42/// component! {
43/// pub fn Button(class: impl Class) {
44/// button(class: classes!("btn", class), #attrs) {
45/// #children
46/// }
47/// }
48/// }
49/// ```
50#[proc_macro]
51pub fn component(input: TokenStream) -> TokenStream {
52 codegen::component_impl(input.into()).into()
53}