From 77a7e3d1f5687b8832f8e597b4d9f419af8ba08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E6=AC=A7?= Date: Thu, 9 Nov 2023 15:45:07 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Invalid=20macro=20temporarily=20?= =?UTF-8?q?removed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/proto-macros/tests/genereate_app.rs | 72 ++++++++++---------- packages/proto/src/lib.rs | 1 - packages/proto/src/macros/generate_app.rs | 56 --------------- packages/proto/src/macros/mod.rs | 1 - 4 files changed, 36 insertions(+), 94 deletions(-) delete mode 100644 packages/proto/src/macros/generate_app.rs diff --git a/packages/proto-macros/tests/genereate_app.rs b/packages/proto-macros/tests/genereate_app.rs index 2c26132..4fc97bd 100644 --- a/packages/proto-macros/tests/genereate_app.rs +++ b/packages/proto-macros/tests/genereate_app.rs @@ -1,51 +1,51 @@ #[cfg(test)] mod test { - use hikari_proto::generate_app; + // use hikari_proto::generate_app; fn generate() { - generate_app! { - #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] - pub enum Route { - #[at("/")] - Portal { recommend_list: Vec } - - #[at("/u/:id")] - Personal { id: String, name: String, email: String } - - #[at("/t/:id")] - Thread { id: String, title: String, content: String, comments: Vec } - - #[not_found] - #[at("/404")] - NotFound - } - - #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] - pub struct Theme { - pub primary_color: String, - pub secondary_color: String, - } - - #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] - pub struct UserToken { - pub token: String, - } - } + // generate_app! { + // #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] + // pub enum Route { + // #[at("/")] + // Portal { recommend_list: Vec } + + // #[at("/u/:id")] + // Personal { id: String, name: String, email: String } + + // #[at("/t/:id")] + // Thread { id: String, title: String, content: String, comments: Vec } + + // #[not_found] + // #[at("/404")] + // NotFound + // } + + // #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] + // pub struct Theme { + // pub primary_color: String, + // pub secondary_color: String, + // } + + // #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] + // pub struct UserToken { + // pub token: String, + // } + // } } #[test] fn render_at_client() { - generate().hydrate(web_sys::window()?.document()?.get_element_by_id("_root")?); + // generate().hydrate(web_sys::window()?.document()?.get_element_by_id("_root")?); } #[test] fn render_at_server() { - generate().render_to_string(Route::Personal { - id: "114514", - name: "homo", - email: "homo@red.tea", - }); + // generate().render_to_string(Route::Personal { + // id: "114514", + // name: "homo", + // email: "homo@red.tea", + // }); - let stream = generate().render_to_stream(); + // let stream = generate().render_to_stream(); } } diff --git a/packages/proto/src/lib.rs b/packages/proto/src/lib.rs index 64e8af7..34ae947 100644 --- a/packages/proto/src/lib.rs +++ b/packages/proto/src/lib.rs @@ -1,4 +1,3 @@ mod macros; -pub use macros::generate_app::*; pub use macros::register_routes::*; diff --git a/packages/proto/src/macros/generate_app.rs b/packages/proto/src/macros/generate_app.rs deleted file mode 100644 index 1944476..0000000 --- a/packages/proto/src/macros/generate_app.rs +++ /dev/null @@ -1,56 +0,0 @@ -#[macro_export] -macro_rules! generate_structs { - ($(#[$meta:meta])* $vis:vis struct $name:ident { $($field:tt)* } $($rest:tt)*) => { - $(#[$meta])* - $vis struct $name { - $($field)* - } - generate_structs! { $($rest)* } - }; - () => {} -} - -#[macro_export] -macro_rules! generate_app { - ( - $(#[$route_meta:meta])* - $route_vis:vis enum $route_enum:ident { - $( - $(#[$($variant_meta:meta)*])* - $variant:ident $( { $( $field:ident : $field_ty:ty ),* } )? - )* - } - - $($rest:tt)* - ) => { - #[derive(yew_router::Routable)] - $(#[$route_meta])* - $route_vis enum $route_enum { - $( - $(#[$($variant_meta)*])* - $variant $( { $( $field : $field_ty ),* } )? - )* - } - - generate_structs! { $($rest)* } - - #[cfg(feature = "web")] - impl $props_enum { - $props_vis fn hydrate(element: web_sys::Element) -> Result { - let props_json = element - .get_attribute("_props") - .ok_or_else(|| JsValue::from_str("Missing _props attribute"))?; - let props: Self = serde_json::from_str(&props_json)?; - Ok(props) - } - } - - #[cfg(not(feature = "web"))] - impl $props_enum { - $props_vis fn render_to_string(&self) -> Result { - let props_json = serde_json::to_string(self)?; - Ok(props_json) - } - } - }; -} diff --git a/packages/proto/src/macros/mod.rs b/packages/proto/src/macros/mod.rs index 78e47dc..85e97a0 100644 --- a/packages/proto/src/macros/mod.rs +++ b/packages/proto/src/macros/mod.rs @@ -1,2 +1 @@ -pub mod generate_app; pub mod register_routes;