wip: add router
This commit is contained in:
1 parent
9874f342e2
commit
d298b626d3
17 files changed
+617
-20
No files matched your search
@@ -5,6 +5,7 @@ use syn::parse_macro_input;
|
||||
pub(crate) mod htm;
|
||||
pub(crate) mod ifmt;
|
||||
pub(crate) mod props;
|
||||
pub(crate) mod router;
|
||||
pub(crate) mod rsx;
|
||||
|
||||
#[proc_macro]
|
||||
@@ -82,12 +83,9 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
|
||||
/// }}
|
||||
///
|
||||
/// // Matching
|
||||
/// // Matching will throw a Rust error about "no two closures are the same type"
|
||||
/// // To fix this, call "render" method or use the "in" syntax to produce VNodes.
|
||||
/// // There's nothing we can do about it, sorry :/ (unless you want *really* unhygenic macros)
|
||||
/// {match true {
|
||||
/// true => rsx!(cx, h1 {"Top text"}),
|
||||
/// false => cx.render(rsx!( h1 {"Bottom text"}))
|
||||
/// true => rsx!(h1 {"Top text"}),
|
||||
/// false => rsx!(h1 {"Bottom text"})
|
||||
/// }}
|
||||
///
|
||||
/// // Conditional rendering
|
||||
@@ -95,11 +93,11 @@ pub fn derive_typed_builder(input: proc_macro::TokenStream) -> proc_macro::Token
|
||||
/// // You can convert a bool condition to rsx! with .then and .or
|
||||
/// {true.then(|| rsx!(div {}))}
|
||||
///
|
||||
/// // True conditions need to be rendered (same reasons as matching)
|
||||
/// // True conditions
|
||||
/// {if true {
|
||||
/// rsx!(cx, h1 {"Top text"})
|
||||
/// rsx!(h1 {"Top text"})
|
||||
/// } else {
|
||||
/// rsx!(cx, h1 {"Bottom text"})
|
||||
/// rsx!(h1 {"Bottom text"})
|
||||
/// }}
|
||||
///
|
||||
/// // returning "None" is a bit noisy... but rare in practice
|
||||
@@ -186,3 +184,31 @@ pub fn rsx(s: TokenStream) -> TokenStream {
|
||||
Ok(s) => s.to_token_stream().into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Derive macro used to mark an enum as Routable.
|
||||
///
|
||||
/// This macro can only be used on enums. Every varient of the macro needs to be marked
|
||||
/// with the `at` attribute to specify the URL of the route. It generates an implementation of
|
||||
/// `yew_router::Routable` trait and `const`s for the routes passed which are used with `Route`
|
||||
/// component.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # use yew_router::Routable;
|
||||
/// #[derive(Debug, Clone, Copy, PartialEq, Routable)]
|
||||
/// enum Routes {
|
||||
/// #[at("/")]
|
||||
/// Home,
|
||||
/// #[at("/secure")]
|
||||
/// Secure,
|
||||
/// #[at("/404")]
|
||||
/// NotFound,
|
||||
/// }
|
||||
/// ```
|
||||
#[proc_macro_derive(Routable, attributes(at, not_found))]
|
||||
pub fn routable_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
use router::{routable_derive_impl, Routable};
|
||||
let input = parse_macro_input!(input as Routable);
|
||||
routable_derive_impl(input).into()
|
||||
}
|
||||
Reference in new issue
Block a user