vident-view_component 1.0.1 → 2.0.0

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: 225bfeb157d05dba1d6aa7d4dbbe953603a0f957bbc310bf5b403c364abe19ca
4
- data.tar.gz: 7be1253854d4ebe732fefb896471e7d9f51df1b2adb5f27189f8d4ec186b3085
3
+ metadata.gz: '0119bb4269d493240babf4f372fa2f4ef88f514535521ea3c7c6e38b731fcaec'
4
+ data.tar.gz: 78febf371ce786efe61e6e0ff8ce4825b758c29b951ae8e8c047be79a2da0237
5
5
  SHA512:
6
- metadata.gz: 19b8bcf6993c4c4d21ecfaa94ddc5349cb4c6cef29c11494d3cb1f48b4aab35faa08f99dda8801e1a5806d9149918ab836fef8579d39d1ccc5eb295c6c4a8251
7
- data.tar.gz: df67b8477332e2742af34589189726dbb440edc3f6645b26e235ec37d6d594bb38aa86840cba0090d8e2e5c79b783c6a989a79bcb54f07eeae0e4f7a04e7de24
6
+ metadata.gz: 001ba186351e917c4e5b4e1a44759b0c190052b1552951ad1edbfa1df487b146b363fa1ed44e5aa502aaf04ed11883ca27851714772ca9357241f9b91ee40ac5
7
+ data.tar.gz: 9b1c95ea79e3dc111d2adac1a92532e9b8d51dbc72a2e39788213358082576ca717eb3c64c9d26b6da3acb58640ff242ff48e411059281acd3fab32dd071a2c6
data/CHANGELOG.md CHANGED
@@ -6,6 +6,60 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
 
9
+ ## [2.0.0] - 2026-04-24
10
+
11
+ Vident 2.0 is a ground-up rearchitecture of the DSL, attribute resolution, and composition model. The public shape of `stimulus do ... end`, `root_element`, `child_element`, outlets, props, and the `stimulus_*:` prop/kwarg API is preserved for common cases, but several internals and a handful of edge-case behaviours changed. See `doc/reviews/v1-gotchas.md` for the full list of fixed gotchas; the highlights are below.
12
+
13
+ ### Breaking
14
+
15
+ - **Namespace consolidation.** The `Vident2::*` namespace used during side-by-side development has been removed. Everything now lives under `Vident::*` directly: `Vident::Component`, `Vident::Capabilities::*`, `Vident::Phlex::HTML`, `Vident::ViewComponent::Base`, `Vident::Stimulus::*` (value classes), `Vident::Internals::*` (DSL/Resolver/Plan). Upgrade path is a `s/Vident2::/Vident::/g` on project code.
16
+ - **Legacy collection classes removed.** `Vident::StimulusAction`, `StimulusTarget`, `StimulusController`, `StimulusValue`, `StimulusParam`, `StimulusOutlet`, `StimulusClass`, and each of their `*Collection` companions (plus `StimulusBuilder`, `StimulusDataAttributeBuilder`, `StimulusAttributeBase`, `StimulusAttributes`, `StimulusAction::Descriptor`) are gone. The 2.0 equivalents live under `Vident::Stimulus::*` (`Action`, `Target`, `Controller`, `Value`, `Param`, `Outlet`, `ClassMap`, `Collection`). `#to_h` now uses **Symbol keys** uniformly; V1 returned String keys for some primitives.
17
+ - **`child_element` strictness.** Passing both `stimulus_<singular>:` and `stimulus_<plural>:` kwargs now raises `ArgumentError` (`"mutually exclusive — pass one or the other."`). V1 silently dropped the singular when the plural was an empty array (latent since 1.0.0, see "Fixed" below). Workaround at call sites that relied on the V1 shape: `stimulus_targets: [:input, *control_targets]`.
18
+ - **`stimulus_controllers:` prop appends instead of replacing.** V1 replaced the implied controller when you passed `stimulus_controllers:` at render time; V2 appends, so the root element carries `data-controller="implied extra"`. Migration: if you wanted to *replace*, add `no_stimulus_controller` at the class level.
19
+ - **Outlet DSL procs now resolve.** V1 silently passed a proc through as the outlet selector string, emitting literal `#<Proc:0x...>`. V2 evaluates the proc in the instance binding and emits the returned string. This turns previously broken code into working code, but if you relied on the proc-as-identity string for some reason, you'll now see a different data attribute.
20
+ - **`nil` vs `false` drop rule.** V1 dropped both `nil` and `false` proc returns silently via a `blank?` filter. V2 drops only `nil`; `false` reaches the parser and raises `Vident::ParseError`. Fix: return `nil` (not `false`) to mean "don't emit this entry."
21
+ - **`no_stimulus_controller` + DSL body now raises loudly.** V1 raised a bare `StandardError` at instance init. V2 raises `Vident::DeclarationError` at `stimulus do ... end` time with the offending class name and caller location in the message.
22
+ - **StableId strategy.** Unchanged from 1.0, but reiterated here because it's the biggest gotcha during upgrade. `Vident::StableId` requires an explicit `strategy` and per-request seed — `bin/rails generate vident:install` sets both up correctly.
23
+
24
+ ### Added
25
+
26
+ - **Fluent action DSL.** Inside `stimulus do ... end`, the singular `action(...)` call returns a chainable builder: `action(:escape).on(:keydown).keyboard("esc").window`, `action(:save).modifier(:prevent, :stop)`, `action(:delete).when { admin? }`. Chain methods: `.on`, `.call_method`, `.modifier`, `.keyboard`, `.window`, `.on_controller`, `.when`.
27
+ - **Kwargs shorthand for actions.** `action :save, on: :click, modifier: [:prevent, :stop], keyboard: "ctrl+s", window: true, on_controller: :admin, call_method: :handle_save, when: -> { ... }` — equivalent to the fluent chain, pick whichever reads better. Unknown kwargs raise `ArgumentError`.
28
+ - **Controller aliases.** `controller "admin/users", as: :admin` inside `stimulus do` declares a short alias; `action(...).on_controller(:admin)` or `action(..., on_controller: :admin)` then routes through it. Unknown alias refs raise `Vident::DeclarationError`. Runtime inputs (`stimulus_actions: [{method: :save, controller: :admin}]`) resolve the same map.
29
+ - **Capability mixin composition.** `Vident::Component` is a composition root that includes twelve focused capability mixins (`Tailwind`, `Declarable`, `Identifiable`, `StimulusDeclaring`, `StimulusParsing`, `StimulusMutation`, `StimulusDraft`, `StimulusDataEmitting`, `ClassListBuilding`, `RootElementRendering`, `ChildElementRendering`, `Inspectable`), plus an opt-in `Caching` mixin (thirteen in total, including Caching). Mixin order mirrors capability dependencies.
30
+ - **Singular DSL primitives.** `value(:name, *, **)`, `param(:name, *, **)`, `outlet(:name, *, **)`, `class_map(:name, *, **)`, `controller(path, as: nil)`, `controllers(*paths)`, `target(:name).when { ... }` — full set of singular entry points alongside the plural forms.
31
+ - **Draft → Plan seal pattern.** Internal: `after_component_initialize` mutators (e.g. `add_stimulus_actions`) still work against a mutable Draft; the Draft seals into an immutable Plan once rendering begins. Prevents the V1 "mutator silently ignored post-render" class of bug.
32
+ - **Phase-split proc resolution.** DSL procs are evaluated in two phases: static (after_initialize, no `view_context`) and procs (`before_template` / `before_render`, `view_context`/`helpers` wired). Procs can now call Rails helpers (`number_with_precision`, url helpers, `t`, `l`, etc.) safely — already backported to 1.0.2.
33
+ - `has_stimulus_controller` class method re-enables the implied controller in a subclass after a parent declared `no_stimulus_controller` (#27).
34
+ - `root_element_class_list(extra = nil)` and `root_element_data_attributes` for components rendering through third-party tag helpers instead of `root_element(...)` (#25; V1 names `render_classes` / `stimulus_data_attributes` — see UPGRADING.md §8).
35
+ - Class-level Stimulus builders — `MyComponent.stimulus_target(:x)` etc. — return value objects without a component instance (#18).
36
+ - `Vident::Types::*` — seven named Literal unions for the built-in `stimulus_*:` prop types, reusable from user components (#16).
37
+ - `cache_component(*keys, **options, &block)` on both adapter base classes — fragment-caches the block using the Vident-computed `cache_key` (#13).
38
+ - Shared `Vident::Stimulus::Base` + `Combinable` for the value classes: `with(**overrides)` combinator, canonical `deconstruct_keys` (restores pattern matching — previously shadowed by the `to_h` data-attribute override), and `Action.parse([event, existing_action])` merge form (#28).
39
+
40
+ ### Fixed
41
+
42
+ - `child_element` no longer silently drops a `stimulus_<singular>:` kwarg when `stimulus_<plural>:` is also passed with an empty array. The V1 helper returned early on an empty-but-truthy plural, losing the singular and emitting no data attribute — latent since 1.0.0, surfaced by call sites like `child_element(:input, stimulus_target: :input, stimulus_targets: control_targets)` where `control_targets` defaulted to `[]`. V2 raises `ArgumentError` on both-set (see Breaking); workaround on 1.x is `stimulus_targets: [:input, *control_targets]` (also works on 2.x).
43
+ - Outlet DSL procs now resolve instead of being treated as identity strings (see Breaking).
44
+ - `add_stimulus_actions([:click, :handle])` now treats the Array as *one* action descriptor (event + method pair) rather than splatting it into two separate `:click` and `:handle` actions. Matches the DSL's `actions [:click, :handle]` semantics — the V1 asymmetry is gone.
45
+
46
+ ### Removed
47
+
48
+ - `Vident::StimulusAction::Descriptor` typed data class. The V2 equivalent is `Vident::Stimulus::Action` itself — the Hash shape accepted by the DSL (`{event:, method:, controller:, options:, keyboard:, window:}`) parses directly into the value class now. Callers that instantiated `Descriptor` explicitly should swap to `Vident::Stimulus::Action.parse(hash, implied: ...)` or just pass the Hash.
49
+ - Legacy top-level requires like `require "vident/stimulus_action"`. The main `require "vident"` loads the whole surface; deep requires for individual value classes still work (`require "vident/stimulus/action"`) but are no longer the documented path.
50
+
51
+
52
+ ## [1.0.2] - 2026-04-21
53
+
54
+ ### Changed
55
+
56
+ - Stimulus DSL procs (`values foo: -> { ... }`, `actions -> { ... }`, etc.) now resolve at **render time** — Phlex's `before_template` for `Vident::Phlex::HTML`, ViewComponent's `before_render` for `Vident::ViewComponent::Base` — instead of in `after_initialize`. Procs can now reach `helpers` / `view_context`, so they can call Rails helpers (`number_with_precision`, `t`, `l`, url helpers, etc.). Non-proc DSL entries still land in the collections at init time, so `after_component_initialize` mutators and external readers see them in the same order as before.
57
+
58
+ ### Added
59
+
60
+ - `phlex_helpers :name1, :name2, ...` class macro on `Vident::Phlex::HTML` — opts the component into Phlex's per-helper Rails adapters (`Phlex::Rails::Helpers::<CamelCase>`) so DSL procs can call helpers bare (`number_with_precision(@amount, precision: 2)`) instead of via the deprecated `helpers.<method>`. Unknown helper names raise `ArgumentError` at class definition.
61
+
62
+
9
63
  ## [1.0.0] - 2026-04-19
10
64
 
11
65
  ### Breaking
data/README.md CHANGED
@@ -79,9 +79,13 @@ class ButtonComponent < Vident::ViewComponent::Base
79
79
 
80
80
  # Configure Stimulus integration
81
81
  stimulus do
82
- # Setup actions, including with proc to evaluate on instance
83
- actions [:click, :handle_click],
84
- -> { [stimulus_scoped_event(:my_custom_event), :handle_this] if should_handle_this? }
82
+ # Fluent action DSL: reads left-to-right as "the handle_click method fires on the click event".
83
+ action(:handle_click).on(:click)
84
+ # Kwargs shorthand — same result, pick whichever reads better:
85
+ action :handle_submit, on: :submit, modifier: [:prevent, :stop]
86
+ # Proc for conditional / cross-component wiring, evaluated in the instance at render time.
87
+ action(-> { [stimulus_scoped_event(:my_custom_event), :handle_this] if should_handle_this? })
88
+
85
89
  # Map the clicked_count prop as a Stimulus value
86
90
  values_from_props :clicked_count
87
91
  # Dynamic values using procs (evaluated in component context)
@@ -178,7 +182,7 @@ Use the component in your views:
178
182
  <%= render ButtonComponent.new(text: "Cancel", url: "/home", style: :secondary) %>
179
183
 
180
184
  <!-- Override things -->
181
- <%= render ButtonComponent.new(text: "Cancel", url: "/home" classes: "bg-red-900", html_options: {role: "button"}) %>
185
+ <%= render ButtonComponent.new(text: "Cancel", url: "/home", classes: "bg-red-900", html_options: {role: "button"}) %>
182
186
  ```
183
187
 
184
188
  The rendered HTML includes all Stimulus data attributes:
@@ -227,7 +231,7 @@ class CardComponent < Vident::ViewComponent::Base
227
231
  # Property with validation
228
232
  prop :size, _Union(:small, :medium, :large), default: :medium
229
233
 
230
- # Boolean property (creates predicate method)
234
+ # Boolean property (pass `predicate: :public` to also generate a `?` method)
231
235
  prop :featured, _Boolean, default: false
232
236
  end
233
237
  ```
@@ -271,7 +275,7 @@ The `root_element` helper method renders your component's root element with all
271
275
  ```ruby
272
276
  # In your component class
273
277
  def root_element_classes
274
- ["card", featured? ? "card-featured" : nil]
278
+ ["card", @featured ? "card-featured" : nil]
275
279
  end
276
280
 
277
281
  private
@@ -362,17 +366,41 @@ class ToggleComponent < Vident::ViewComponent::Base
362
366
  end
363
367
  ```
364
368
 
365
- **Action modifiers**the Array form `[:click, :method]` handles the common case. For Stimulus's modifier syntax (`:once`/`:prevent`/`:stop`/`:passive`/`:"!passive"`/`:capture`/`:self`, keyboard filters, `@window`), pass a Hash or a `Vident::StimulusAction::Descriptor`:
369
+ **Action modifiers — fluent DSL.** Singular `action(...)` returns a builder you chain with event, modifier, keyboard, and window setters. Kwargs shorthand is equivalent:
366
370
 
367
371
  ```ruby
368
- actions({event: :click, method: :submit, options: [:once, :prevent]})
369
- actions({event: :keydown, method: :on_key, keyboard: "ctrl+a"})
370
- actions({event: :resize, method: :on_resize, window: true})
371
- # or, if you want a typed, passable object:
372
- actions Vident::StimulusAction::Descriptor.new(event: :click, method: :save, options: [:prevent])
372
+ stimulus do
373
+ action(:submit).on(:click).modifier(:once, :prevent) # click:once:prevent->implied#submit
374
+ action(:on_key).on(:keydown).keyboard("ctrl+a") # keydown.ctrl+a->implied#onKey
375
+ action(:on_resize).on(:resize).window # resize@window->implied#onResize
376
+
377
+ # kwargs shorthand — same result:
378
+ action :submit, on: :click, modifier: [:once, :prevent]
379
+ action :on_key, on: :keydown, keyboard: "ctrl+a"
380
+ action :on_resize, on: :resize, window: true
381
+ action :save, on: :click, call_method: :handle_save
382
+
383
+ # conditional inclusion via `.when` / `when:`:
384
+ action(:delete).when { admin? }
385
+ end
373
386
  ```
374
387
 
375
- Unknown option symbols raise `ArgumentError` at attribute construction, not at render.
388
+ Chain methods: `.on`, `.call_method`, `.modifier`, `.keyboard`, `.window`, `.on_controller`, `.when`. Recognised kwargs: `on:`, `call_method:`, `modifier:` (Symbol or Array), `keyboard:`, `window:`, `on_controller:`, `when:`. Unknown kwargs or modifier symbols raise `ArgumentError`.
389
+
390
+ **Controller aliases.** Declare a short alias with `controller "path", as: :sym`, then reference it from action entries via the fluent `.on_controller(:sym)` or the `on_controller: :sym` kwarg:
391
+
392
+ ```ruby
393
+ stimulus do
394
+ controller "admin/users", as: :admin
395
+
396
+ action(:save).on(:click).on_controller(:admin) # click->admin--users#save
397
+ action :save, on: :click, on_controller: :admin # same, kwargs form
398
+ end
399
+ ```
400
+
401
+ Unknown aliases raise `Vident::DeclarationError` at render time.
402
+
403
+ **Legacy Hash form.** Still accepted for compat — `actions({event: :click, method: :submit, options: [:once, :prevent]})` parses the same way. The Hash descriptor is folded directly into `Vident::Stimulus::Action` — pass a Hash and it is parsed in place. Accepted keys: `method:`, `event:`, `controller:`, `options:`, `keyboard:`, `window:`.
376
404
 
377
405
  ### Dynamic Values and Classes with Procs
378
406
 
@@ -415,7 +443,10 @@ class DynamicComponent < Vident::ViewComponent::Base
415
443
  end
416
444
  ```
417
445
 
418
- Procs have access to instance variables, component methods, and Rails helpers.
446
+ Procs have access to instance variables and component methods. They run at render time (Phlex `before_template` / ViewComponent `before_render`), so they can reach the view context:
447
+
448
+ - **Phlex**: `helpers` is deprecated in phlex-rails. Opt in per Rails helper by including the matching adapter — e.g. `include Phlex::Rails::Helpers::NumberWithPrecision` — and call the helper bare (`number_with_precision(@amount, precision: 2)`) inside the proc. Vident ships a `phlex_helpers :number_with_precision, :t, :l` class macro on `Vident::Phlex::HTML` that does the right include for each name. See [phlex.fun/rails/helpers](https://www.phlex.fun/rails/helpers) for the full list of adapters.
449
+ - **ViewComponent**: call `helpers.<method>` or `view_context.<method>` directly.
419
450
 
420
451
  **Important**: Each proc returns a single value for its corresponding stimulus attribute. If a proc returns an array, that entire array is treated as a single value, not multiple separate values. To provide multiple values for an attribute, use multiple procs or mix procs with static values:
421
452
 
@@ -486,14 +517,14 @@ class MyComponent < Vident::ViewComponent::Base
486
517
  # This would generate: "my-component:dataLoaded"
487
518
  puts stimulus_scoped_event(:data_loaded)
488
519
 
489
- # For window events, this generates: "my-component:dataLoaded@window"
520
+ # For window events, this generates: :"my-component:dataLoaded@window"
490
521
  puts stimulus_scoped_event_on_window(:data_loaded)
491
522
  end
492
523
  end
493
524
 
494
525
  # Available as both class and instance methods:
495
- MyComponent.stimulus_scoped_event(:data_loaded) # => "my-component:dataLoaded"
496
- MyComponent.new.stimulus_scoped_event(:data_loaded) # => "my-component:dataLoaded"
526
+ MyComponent.stimulus_scoped_event(:data_loaded) # => :"my-component:dataLoaded"
527
+ MyComponent.new.stimulus_scoped_event(:data_loaded) # => :"my-component:dataLoaded"
497
528
  ```
498
529
 
499
530
  This is useful for:
@@ -529,7 +560,7 @@ class CustomComponent < Vident::ViewComponent::Base
529
560
  end
530
561
  ```
531
562
 
532
- All stimulus props accept Symbol paths as well as Strings (e.g. `stimulus_controllers: [:custom, :"admin/users"]`). `stimulus_values:` and `stimulus_classes:` additionally accept Array entries (for cross-controller: `[["admin/users", :name, "value"]]`) and pre-built `StimulusValue`/`StimulusValueCollection` / `StimulusClass`/`StimulusClassCollection` instances, so you can compose attribute sets outside the component and pass them in.
563
+ All stimulus props accept Symbol paths as well as Strings (e.g. `stimulus_controllers: [:custom, :"admin/users"]`). `stimulus_values:` and `stimulus_classes:` additionally accept Array entries (for cross-controller: `[["admin/users", :name, "value"]]`) and pre-built `Vident::Stimulus::Value` / `Vident::Stimulus::ClassMap` instances, so you can compose attribute sets outside the component and pass them in.
533
564
 
534
565
  or you can use tag helpers to generate HTML with Stimulus attributes:
535
566
 
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+
1
5
  module Vident
2
6
  module ViewComponent
3
7
  class Base < ::ViewComponent::Base
4
- include Vident::Component
8
+ include ::Vident::Component
5
9
 
6
10
  class << self
7
11
  def cache_component_modified_time
@@ -17,7 +21,6 @@ module Vident
17
21
  end
18
22
 
19
23
  def template_path
20
- # Check for common ViewComponent template extensions in order of preference
21
24
  extensions = [".html.erb", ".erb", ".html.haml", ".haml", ".html.slim", ".slim"]
22
25
  base_path = Rails.root.join(components_base_path, virtual_path)
23
26
 
@@ -26,7 +29,6 @@ module Vident
26
29
  return potential_path if File.exist?(potential_path)
27
30
  end
28
31
 
29
- # Return the default .html.erb path if no template is found
30
32
  Rails.root.join(components_base_path, "#{virtual_path}.html.erb").to_s
31
33
  end
32
34
 
@@ -39,12 +41,30 @@ module Vident
39
41
  end
40
42
  end
41
43
 
42
- SELF_CLOSING_TAGS = Set[:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
44
+ SELF_CLOSING_TAGS = Set[*%i[area base br col embed hr img input link meta param source track wbr]].freeze
45
+
46
+ # DSL procs stay unresolved until `@view_context` is set; resolve them here.
47
+ def before_render
48
+ resolve_stimulus_attributes_at_render_time
49
+ super
50
+ end
43
51
 
52
+ # Fragment-cache the block's rendered String using the Vident-computed
53
+ # `cache_key`. Useful inside a `call` method; for sidecar ERB templates
54
+ # use the native `<% cache cache_key do %>` pattern instead.
55
+ def cache_component(*extra_keys, expires_in: nil, &block)
56
+ unless respond_to?(:cacheable?) && cacheable?
57
+ raise ::Vident::ConfigurationError,
58
+ "#{self.class.name} is not cacheable — `include Vident::Caching` and declare `with_cache_key` first."
59
+ end
60
+ ::Rails.cache.fetch([cache_key, *extra_keys], expires_in: expires_in) { capture(&block) }
61
+ end
62
+
63
+ # Capture block first so children can mutate this Draft before it seals (outlet-host pattern).
44
64
  def root_element(**overrides, &block)
45
65
  tag_type = root_element_tag_type
46
- child_content = view_context.capture(self, &block) if block_given? # Evaluate before generating the outer tag options to ensure DSL methods are executed
47
- options = resolve_root_element_attributes_before_render(overrides)
66
+ child_content = view_context.capture(self, &block) if block
67
+ options = build_root_element_attributes(overrides)
48
68
  if SELF_CLOSING_TAGS.include?(tag_type)
49
69
  view_context.tag(tag_type, options)
50
70
  else
@@ -52,61 +72,41 @@ module Vident
52
72
  end
53
73
  end
54
74
 
55
- def as_stimulus_targets(...)
56
- to_data_attribute_string(**stimulus_targets(...))
57
- end
75
+ def as_stimulus_targets(...) = to_data_attribute_string(**stimulus_targets(...).to_h)
58
76
 
59
- def as_stimulus_target(...)
60
- to_data_attribute_string(**stimulus_target(...))
61
- end
77
+ def as_stimulus_target(...) = to_data_attribute_string(**stimulus_target(...).to_h)
62
78
 
63
- def as_stimulus_actions(...)
64
- to_data_attribute_string(**stimulus_actions(...))
65
- end
79
+ def as_stimulus_actions(...) = to_data_attribute_string(**stimulus_actions(...).to_h)
66
80
 
67
- def as_stimulus_action(...)
68
- to_data_attribute_string(**stimulus_action(...))
69
- end
81
+ def as_stimulus_action(...) = to_data_attribute_string(**stimulus_action(...).to_h)
70
82
 
71
- def as_stimulus_controllers(...)
72
- to_data_attribute_string(**stimulus_controllers(...))
73
- end
83
+ def as_stimulus_controllers(...) = to_data_attribute_string(**stimulus_controllers(...).to_h)
74
84
 
75
- def as_stimulus_controller(...)
76
- to_data_attribute_string(**stimulus_controller(...))
77
- end
85
+ def as_stimulus_controller(...) = to_data_attribute_string(**stimulus_controller(...).to_h)
78
86
 
79
- def as_stimulus_outlets(...)
80
- to_data_attribute_string(**stimulus_outlets(...))
81
- end
87
+ def as_stimulus_outlets(...) = to_data_attribute_string(**stimulus_outlets(...).to_h)
82
88
 
83
- def as_stimulus_outlet(...)
84
- to_data_attribute_string(**stimulus_outlet(...))
85
- end
89
+ def as_stimulus_outlet(...) = to_data_attribute_string(**stimulus_outlet(...).to_h)
86
90
 
87
- def as_stimulus_values(...)
88
- to_data_attribute_string(**stimulus_values(...))
89
- end
91
+ def as_stimulus_values(...) = to_data_attribute_string(**stimulus_values(...).to_h)
90
92
 
91
- def as_stimulus_value(...)
92
- to_data_attribute_string(**stimulus_value(...))
93
- end
93
+ def as_stimulus_value(...) = to_data_attribute_string(**stimulus_value(...).to_h)
94
94
 
95
- def as_stimulus_params(...)
96
- to_data_attribute_string(**stimulus_params(...))
97
- end
95
+ def as_stimulus_params(...) = to_data_attribute_string(**stimulus_params(...).to_h)
98
96
 
99
- def as_stimulus_param(...)
100
- to_data_attribute_string(**stimulus_param(...))
101
- end
97
+ def as_stimulus_param(...) = to_data_attribute_string(**stimulus_param(...).to_h)
102
98
 
103
- def as_stimulus_classes(...)
104
- to_data_attribute_string(**stimulus_classes(...))
105
- end
99
+ def as_stimulus_classes(...) = to_data_attribute_string(**stimulus_classes(...).to_h)
106
100
 
107
- def as_stimulus_class(...)
108
- to_data_attribute_string(**stimulus_class(...))
109
- end
101
+ def as_stimulus_class(...) = to_data_attribute_string(**stimulus_class(...).to_h)
102
+
103
+ alias_method :as_target, :as_stimulus_target
104
+ alias_method :as_action, :as_stimulus_action
105
+ alias_method :as_controller, :as_stimulus_controller
106
+ alias_method :as_outlet, :as_stimulus_outlet
107
+ alias_method :as_value, :as_stimulus_value
108
+ alias_method :as_param, :as_stimulus_param
109
+ alias_method :as_class, :as_stimulus_class
110
110
 
111
111
  private
112
112
 
@@ -1,6 +1,7 @@
1
- require "vident/view_component/version"
1
+ # frozen_string_literal: true
2
+
3
+ require "view_component"
2
4
  require "vident/view_component/base"
3
- require "vident/view_component/engine" if defined?(Rails)
4
5
 
5
6
  module Vident
6
7
  module ViewComponent
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vident-view_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
@@ -55,14 +55,14 @@ dependencies:
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: 1.0.1
58
+ version: 2.0.0
59
59
  type: :runtime
60
60
  prerelease: false
61
61
  version_requirements: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: 1.0.1
65
+ version: 2.0.0
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: view_component
68
68
  requirement: !ruby/object:Gem::Requirement
@@ -95,8 +95,6 @@ files:
95
95
  - README.md
96
96
  - lib/vident/view_component.rb
97
97
  - lib/vident/view_component/base.rb
98
- - lib/vident/view_component/engine.rb
99
- - lib/vident/view_component/version.rb
100
98
  homepage: https://github.com/stevegeek/vident
101
99
  licenses:
102
100
  - MIT
@@ -1,17 +0,0 @@
1
- module Vident
2
- module ViewComponent
3
- class Engine < ::Rails::Engine
4
- lib_path = File.expand_path("../../../../lib/", __FILE__)
5
- config.autoload_paths << lib_path
6
- config.eager_load_paths << lib_path
7
-
8
- config.before_initialize do
9
- Rails.autoloaders.each do |autoloader|
10
- autoloader.inflector.inflect(
11
- "version" => "VERSION"
12
- )
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- module Vident
2
- module ViewComponent
3
- VERSION = Vident::VERSION
4
- end
5
- end