rstml_component_macro/
lib.rs

1mod component;
2mod template;
3mod func;
4mod write;
5
6#[proc_macro]
7pub fn html(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
8	write::html(input.into(), true).into()
9}
10
11#[proc_macro]
12pub fn write_html(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
13	write::write_html(input.into()).into()
14}
15
16#[proc_macro_derive(HtmlComponent, attributes(html))]
17pub fn derive_html_component(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
18	component::derive_html_component(input.into()).into()
19}
20
21/// Turns a function into a component function, arguments to the attribute macro are the visibility
22/// for the generated struct and the name of the struct. The function should return `impl HtmlContent`.
23///
24/// # Usage
25///
26/// ```
27/// # use rstml_component::{html, component, HtmlContent};
28/// #[component(pub MyComponent)]
29/// fn my_component(title: impl Into<String>) -> impl HtmlContent {
30///   html! {
31///     <div>{title.into()}</div>
32///   }
33/// }
34#[proc_macro_attribute]
35pub fn component(
36	attr: proc_macro::TokenStream,
37	input: proc_macro::TokenStream,
38) -> proc_macro::TokenStream {
39	func::component(attr.into(), input.into()).into()
40}