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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use TokenStream as TS1;
use quote;
use ;
use crate::;
/// Story generation macro
///
/// This macro is used to generate a [Story][holt_book::Story] from a constant
/// expression, as well as registering the story with the inventory.
///
/// Define a `const` that's a list of variants (defined with the [variant]
/// macro). You can set the const type to `()`, since we overwrite the whole
/// const to be a [Story][holt_book::Story].
///
/// You have to pass the following args:
///
/// - `id`: The unique identifier for the story, URL-safe.
/// - `name`: The UI name of the story.
///
/// You can optionally document the story using regular Rust doc comments.
/// Additionally, you can set extra documentation (appended at the end) using
/// the `extra_docs` argument. This should be a reference to a `const &'static
/// str`. This is useful for generated documentation: you can generate a static
/// string in `build.rs` and include it with the `include!` macro.
///
/// # Examples
///
/// ```
/// # use leptos::prelude::*;
/// # use holt_book::StoryVariant;
/// use holt_macros::{story, variant};
///
/// #[variant]
/// fn default() {
/// view! { <button>"Click me!"</button> }.into_any()
/// }
///
/// /// Buttons are for clicking and doing button things
/// #[story(id = "my-story", name = "My Story")]
/// const MY_STORY: () = &[
/// default,
/// ];
/// ```
///
/// Or with extra documentation:
///
/// ```
/// # use leptos::prelude::*;
/// # use holt_book::StoryVariant;
/// # use holt_macros::{story, variant};
/// #
/// # #[variant]
/// # fn default() {
/// # view! { <button>"Click me!"</button> }.into_any()
/// # }
/// #
/// const EXTRA: &str = "Extra documentation for my story";
///
/// /// Buttons are for clicking and doing button things
/// #[story(id = "my-story", name = "My Story", extra_docs = EXTRA)]
/// const MY_STORY: () = &[
/// default,
/// ];
/// ```
/// Story variant generation macro
///
/// This macro converts a function into a [holt_book::StoryVariant] constant,
/// extracting the variant name from the function name and inlining the function
/// body into the render closure.
///
/// # Examples
///
/// ```
/// # use leptos::prelude::*;
/// use holt_macros::variant;
///
/// #[variant]
/// fn default() -> AnyView {
/// view! { <button>Default</button> }.into_any()
/// }
/// ```
///
/// If you want more control over the generated variant, you should create the
/// [holt_book::StoryVariant] struct directly. Note that you'll need to name the
/// variant `xxx_VARIANT` (like `DEFAULT_VARIANT` for the above) so that you can
/// use it in the [story] macro as `default`.