Skip to content

Commit

Permalink
smarter style macro thanks to coderabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Dec 13, 2024
1 parent 003cf26 commit e323297
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 66 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion demo_respo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ js-sys = "0.3.76"
wasm-bindgen = "0.2.93"
console_error_panic_hook = "0.1.7"
uuid = { version = "1.11.0", features = ["v4", "js"] }
serde = { version = "1.0.215", features = ["derive", "rc"] }
serde = { version = "1.0.216", features = ["derive", "rc"] }
serde_json = "1.0.133"
respo_state_derive = { path = "../respo_state_derive" }

Expand Down
2 changes: 1 addition & 1 deletion respo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lazy_static = "1.5.0"
cirru_parser = "0.1.31"
# cirru_parser = { path = "/Users/chenyong/repo/cirru/parser.rs" }
rust-hsluv = "0.1.4"
serde = { version = "1.0.215", features = ["derive", "rc"] }
serde = { version = "1.0.216", features = ["derive", "rc"] }
serde_json = "1.0.133"
# respo_state_derive = { path = "../respo_state_derive" }
respo_state_derive = "0.0.1"
Expand Down
78 changes: 18 additions & 60 deletions respo/src/node/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,33 +834,8 @@ macro_rules! static_style_seq {
/// if you have more styles to specify, use `static_style_seq!` instead.
#[macro_export]
macro_rules! static_styles {
($a:ident, $b:expr) => {
$crate::static_style_seq!($a, &[$b]);
};
// to allow optional trailing comma
($a:ident, $b:expr,) => {
$crate::static_style_seq!($a, &[$b]);
};
($a:ident, $b:expr, $c:expr) => {
$crate::static_style_seq!($a, &[$b, $c]);
};
($a:ident, $b:expr, $c:expr,) => {
$crate::static_style_seq!($a, &[$b, $c]);
};
($a:ident, $b:expr, $c:expr, $d:expr) => {
$crate::static_style_seq!($a, &[$b, $c, $d]);
};
($a:ident, $b:expr, $c:expr, $d:expr,) => {
$crate::static_style_seq!($a, &[$b, $c, $d]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr) => {
$crate::static_style_seq!($a, &[$b, $c, $d, $e]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr,) => {
$crate::static_style_seq!($a, &[$b, $c, $d, $e]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr) => {
$crate::static_style_seq!($a, &[$b, $c, $d, $e, $f]);
($a:ident, $($b:expr),* $(,)?) => {
$crate::static_style_seq!($a, &[$($b),*]);
};
}

Expand Down Expand Up @@ -889,43 +864,26 @@ macro_rules! contained_style_seq {

/// macro to create a public function of CSS rules(up to 5 tuples) at current file scope,
/// ```rust
/// respo::contained_styles!(the_name,
/// (Some("@container".to_string()), "&", respo::css::respo_style())
/// // Example with multiple container queries
/// respo::contained_style_seq!(responsive_card,
/// &[
/// (None, "&", respo::css::respo_style().width(200.px())),
/// (Some("@container (min-width: 300px)".to_string()), "&", respo::css::respo_style().width(300.px())),
/// ]
/// );
///
/// // Example combining with media queries
/// respo::contained_style_seq!(hybrid_responsive,
/// &[
/// (Some("@media (prefers-color-scheme: dark)".to_string()), "&",
/// respo::css::respo_style().background_color(CssColor::Rgb(20, 20, 20)))
/// ]
/// );
/// ```
/// gets a function like:
/// ```ignore
/// pub fn the_name() -> String
/// ```
/// if you have more styles to specify, use `contained_style_seq!` instead.
#[macro_export]
macro_rules! contained_styles {
($a:ident, $b:expr) => {
$crate::contained_style_seq!($a, &[$b]);
};
// to allow optional trailing comma
($a:ident, $b:expr,) => {
$crate::contained_style_seq!($a, &[$b]);
};
($a:ident, $b:expr, $c:expr) => {
$crate::contained_style_seq!($a, &[$b, $c]);
};
($a:ident, $b:expr, $c:expr,) => {
$crate::contained_style_seq!($a, &[$b, $c]);
};
($a:ident, $b:expr, $c:expr, $d:expr) => {
$crate::contained_style_seq!($a, &[$b, $c, $d]);
};
($a:ident, $b:expr, $c:expr, $d:expr,) => {
$crate::contained_style_seq!($a, &[$b, $c, $d]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr) => {
$crate::contained_style_seq!($a, &[$b, $c, $d, $e]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr,) => {
$crate::contained_style_seq!($a, &[$b, $c, $d, $e]);
};
($a:ident, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr) => {
$crate::contained_style_seq!($a, &[$b, $c, $d, $e, $f]);
($a:ident, $($b:expr),* $(,)?) => {
$crate::contained_style_seq!($a, &[$($b),*]);
};
}

0 comments on commit e323297

Please sign in to comment.