From 3319ad4eba22632dfb8a4ab35cd4437011b43d28 Mon Sep 17 00:00:00 2001 From: SB Software Agent Date: Mon, 23 Feb 2026 23:21:06 +0100 Subject: [PATCH 1/3] CSS-39 Add Stylesheet nth_of_type helper and selector coverage --- spec/selector_spec.cr | 10 +++++++++- src/stylesheet.cr | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/spec/selector_spec.cr b/spec/selector_spec.cr index 18109b1..8837431 100644 --- a/spec/selector_spec.cr +++ b/spec/selector_spec.cr @@ -74,7 +74,7 @@ module CSS::SelectorSpec display :none end - rule div <= CSS::NthOfType.new(:odd) do + rule div <= nth_of_type(:odd) do display :none end @@ -182,6 +182,14 @@ module CSS::SelectorSpec end end + describe "Style.nth_of_type" do + it "returns nth-of-type selector helper objects" do + Style.nth_of_type(3).should be_a(CSS::NthOfType) + Style.nth_of_type("2n+1").should be_a(CSS::NthOfType) + Style.nth_of_type(:odd).should be_a(CSS::NthOfType) + end + end + describe "MultiSelectorStyle.to_s" do it "renders comma-separated selectors and nested rules" do expected = <<-CSS diff --git a/src/stylesheet.cr b/src/stylesheet.cr index 5dad1ca..5125257 100644 --- a/src/stylesheet.cr +++ b/src/stylesheet.cr @@ -28,6 +28,18 @@ module CSS CSS::CalcFunctionCall.new(calculation) end + def self.nth_of_type(exp : Int32) + CSS::NthOfType.new(exp) + end + + def self.nth_of_type(exp : String) + CSS::NthOfType.new(exp) + end + + def self.nth_of_type(exp : CSS::NthOfType::Static) + CSS::NthOfType.new(exp) + end + # Type-safe helper for length/percentage `clamp()` values. # # Note: this helper enforces units for non-zero number literals (same as property setters). From 6180591e2b0fcfd780e756b9715ac44d081cf42e Mon Sep 17 00:00:00 2001 From: SB Software Agent Date: Mon, 23 Feb 2026 23:33:46 +0100 Subject: [PATCH 2/3] CSS-39 Simplify nth_of_type helper signature --- src/stylesheet.cr | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/stylesheet.cr b/src/stylesheet.cr index 5125257..d0708aa 100644 --- a/src/stylesheet.cr +++ b/src/stylesheet.cr @@ -28,15 +28,7 @@ module CSS CSS::CalcFunctionCall.new(calculation) end - def self.nth_of_type(exp : Int32) - CSS::NthOfType.new(exp) - end - - def self.nth_of_type(exp : String) - CSS::NthOfType.new(exp) - end - - def self.nth_of_type(exp : CSS::NthOfType::Static) + def self.nth_of_type(exp : Int32 | String | CSS::NthOfType::Static) CSS::NthOfType.new(exp) end From 81d49368cbf5c9fbaf15b8c1bdfe5017f94cc58c Mon Sep 17 00:00:00 2001 From: SB Software Agent Date: Tue, 24 Feb 2026 21:06:12 +0100 Subject: [PATCH 3/3] CSS-39 Remove nth_of_type helper type assertion spec --- spec/selector_spec.cr | 8 -------- 1 file changed, 8 deletions(-) diff --git a/spec/selector_spec.cr b/spec/selector_spec.cr index 8837431..e6d9e14 100644 --- a/spec/selector_spec.cr +++ b/spec/selector_spec.cr @@ -182,14 +182,6 @@ module CSS::SelectorSpec end end - describe "Style.nth_of_type" do - it "returns nth-of-type selector helper objects" do - Style.nth_of_type(3).should be_a(CSS::NthOfType) - Style.nth_of_type("2n+1").should be_a(CSS::NthOfType) - Style.nth_of_type(:odd).should be_a(CSS::NthOfType) - end - end - describe "MultiSelectorStyle.to_s" do it "renders comma-separated selectors and nested rules" do expected = <<-CSS