view_component_css_dsl 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fcd1b87aa8e32ecd595601ffbce3015c1cd7d1119a97967fda706f859499654
4
- data.tar.gz: 3b473073f9fca60d277fa0dd9700cd66b2da76a2f72222830f3a3d76bc294ce7
3
+ metadata.gz: 49d5390931f1620f410e179868a1ab08cfcf4a0fa05164c8b4e7e7ba860fa1b2
4
+ data.tar.gz: 1f51a210129bd2ee1cfd414697e923c60e5be7c0c8870788e193482aacfda6ee
5
5
  SHA512:
6
- metadata.gz: f4c117c6970000983d5acbdbb2d75254ac9875b5f0faeb64e80e78e88dd8644ee5dc3a01c24dfbac1257405cac55aa92c5975c1ac639cf28b8f2632e42002eec
7
- data.tar.gz: a57068184216a9c7f3d0554efa9658805749d35aa57f8d1592a1a7c3f26bb5a2b3bc0333d68e073cb4281e619cff6067c84db55118196ee227b32bdbddfbcc98
6
+ metadata.gz: '0086317b10dbb3b32225d9b7eb9b1695d176c40ea6adad370ca6259366edbb1952038170fa4499ecaa2ad5edfff2af7c2459214140bc2be8dd61b6441fac7e05'
7
+ data.tar.gz: f2286966bae1f1c1b12b2f10e09f58d983281cbfdf0d96c863d98f28b3b7feefae85229d17a440f19d156a51ff7d0dbd2d525660186cb310d6273f15bce4d112
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased]
4
3
 
5
- ## [0.1.0]
4
+
5
+ ## [0.1.1] - 2026-05-15
6
+
7
+ ### Changed
8
+
9
+ - `view_component` dependency pinned to `~> 4.0` (was `>= 4.0`) — RubyGems-recommended SemVer-aware constraint
10
+ - Minimum Ruby version raised to 3.2 (was 3.1), matching the floor for `view_component >= 4.0`
11
+
12
+ ## [0.1.0] - 2026-05-15
13
+
14
+ ### Added
15
+
6
16
  - Initial release. Extracted from SOFware/forge.
data/README.md CHANGED
@@ -327,6 +327,8 @@ bundle exec rspec
327
327
  bundle exec standardrb
328
328
  ```
329
329
 
330
+ Releases are managed by [reissue](https://github.com/SOFware/reissue). When committing, add Keep-a-Changelog trailers (`Added:`, `Changed:`, `Fixed:`, etc.) and reissue will collate them into `CHANGELOG.md` at release time. To publish a new version, run the "Release gem to RubyGems.org" workflow from GitHub Actions.
331
+
330
332
  ## License
331
333
 
332
334
  MIT. See [LICENSE.txt](LICENSE.txt).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ViewComponentCssDsl
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -12,11 +12,6 @@ require_relative "view_component_css_dsl/version"
12
12
  module ViewComponentCssDsl
13
13
  extend ActiveSupport::Concern
14
14
 
15
- # HTML attributes auto-extracted from kwargs at construction time. Anything in
16
- # this set is captured into @html_attrs instead of being passed to initialize,
17
- # so callers can pass `class:`, `data:`, `aria:`, etc. without the component
18
- # declaring them. To opt out, accept a kwarg with the same name in initialize
19
- # (e.g. `def initialize(class:)`) or use a keyrest name other than html_attrs.
20
15
  HTML_ATTR_KEYS = Set[
21
16
  :alt, :aria, :autofocus,
22
17
  :class, :colspan, :contenteditable,
@@ -206,20 +201,60 @@ module ViewComponentCssDsl
206
201
  # Override `new` to auto-extract HTML attributes from kwargs into @html_attrs,
207
202
  # so components don't need to declare **html_attrs in their initialize signature.
208
203
  # Anything in HTML_ATTR_KEYS that wasn't declared as a kwarg is captured.
204
+ #
205
+ # These can then be referenced in the component's template as `html_attrs`.
206
+ #
207
+ # Why?
208
+ # - DX: All components can accept arbitrary html attrs for free. Dev can pass
209
+ # arbitrary html attrs in at any caller and have it output at the component's
210
+ # top-level element.
211
+ # - Removes boilerplate of putting `**html_attrs` as the last argument in every
212
+ # single component's initialize signature, and then having to set the same as an
213
+ # ivar within the initialize body.
214
+ # - Requires following a pattern of declaring `**html_attrs` in the top level
215
+ # element of every single component's template.
216
+ # - Example template definition:
217
+ #
218
+ # # html_attrs contains :class, :data, etc defined either in the component
219
+ # # or passed in by the caller.
220
+ # <%= tag.my_component **html_attrs do %>
221
+ # <%= content %>
222
+ # <% end %>
223
+ #
224
+ # Example caller:
225
+ #
226
+ # render MyComponent.new(text: "Hello", class: "custom", data: {foo: "bar"})
227
+ #
228
+ # - :text goes to component's #initialize method, as normal
229
+ # - :class, :data, etc are captured and merged into @html_attrs automatically
230
+ # - The component's initialize method will look like:
231
+ #
232
+ # def initialize(text)
233
+ # @text = text
234
+ # end
235
+ #
236
+ # To opt out of this behavior, inherit from ViewComponent::Base directly instead of
237
+ # ApplicationComponent.
238
+ #
209
239
  def new(*args, **kwargs, &block)
210
240
  info = initialize_params_info
211
241
  html_attrs = {}
242
+
243
+ # Only extract HTML attrs if the component uses **html_attrs pattern.
244
+ # Components with other keyrest names (like **options) should receive all kwargs.
212
245
  if info[:uses_html_attrs_keyrest]
246
+ # Extract HTML attrs, but NOT if they're declared component params
213
247
  extractable = HTML_ATTR_KEYS.intersection(kwargs.keys) - info[:declared_kwargs]
214
248
  html_attrs = kwargs.extract!(*extractable)
215
249
  end
216
250
 
217
251
  instance = allocate
252
+ # Set @html_attrs BEFORE initialize so components can access it there
218
253
  instance.instance_variable_set(:@html_attrs, html_attrs)
219
254
  instance.send(:initialize, *args, **kwargs, &block)
220
255
 
221
- # Merge with any @html_attrs the component set inside initialize (older
222
- # components that still declare **html_attrs). Caller-provided values win.
256
+ # Merge with any @html_attrs set by initialize (old pattern components).
257
+ # Caller-provided values (html_attrs) take precedence over component defaults.
223
258
  existing = instance.instance_variable_get(:@html_attrs) || {}
224
259
  instance.instance_variable_set(:@html_attrs, existing.merge(html_attrs))
225
260
  instance
@@ -234,12 +269,17 @@ module ViewComponentCssDsl
234
269
  keyrest_name = nil
235
270
  instance_method(:initialize).parameters.each do |type, name|
236
271
  case type
237
- when :key, :keyreq then declared_kwargs << name
238
- when :keyrest then keyrest_name = name
272
+ when :key, :keyreq
273
+ declared_kwargs << name
274
+ when :keyrest
275
+ keyrest_name = name
239
276
  end
240
277
  end
241
- uses_html_attrs_keyrest = keyrest_name.nil? || keyrest_name == :html_attrs
242
- {declared_kwargs:, uses_html_attrs_keyrest:}
278
+
279
+ {
280
+ declared_kwargs:,
281
+ uses_html_attrs_keyrest: keyrest_name == :html_attrs || keyrest_name.nil?
282
+ }
243
283
  end
244
284
  end
245
285
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_css_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lange
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2026-05-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -44,6 +43,20 @@ dependencies:
44
43
  - - "~>"
45
44
  - !ruby/object:Gem::Version
46
45
  version: '4.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: reissue
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '0.4'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.4'
47
60
  - !ruby/object:Gem::Dependency
48
61
  name: rspec
49
62
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +108,6 @@ metadata:
95
108
  source_code_uri: https://github.com/SOFware/view_component_css_dsl
96
109
  changelog_uri: https://github.com/SOFware/view_component_css_dsl/blob/main/CHANGELOG.md
97
110
  rubygems_mfa_required: 'true'
98
- post_install_message:
99
111
  rdoc_options: []
100
112
  require_paths:
101
113
  - lib
@@ -110,8 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
122
  - !ruby/object:Gem::Version
111
123
  version: '0'
112
124
  requirements: []
113
- rubygems_version: 3.0.3.1
114
- signing_key:
125
+ rubygems_version: 4.0.3
115
126
  specification_version: 4
116
127
  summary: Declarative CSS class DSL for ViewComponent + Tailwind
117
128
  test_files: []