stimulizer 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4ffb6c46838fb14026e86fdd23fcdaf02e96c54cc083f61de0700a00a3887da
4
- data.tar.gz: 5d55ddacece2a9458bd3f1b1b44bdaf686e31e1295572d55a0ee83a16af29a26
3
+ metadata.gz: ef63a4056af8d47a2575a6b1fa341cc66f0f4c890ca2545222f939813e81c083
4
+ data.tar.gz: 2b73dca03393d1ec003e8fcf34a4421bd0f3e76026e81b6f79f65de58909229b
5
5
  SHA512:
6
- metadata.gz: db21b71f5bc84d6fc9244d3ef2d918d5512c70aa5fe51c0149e968c85377287681ee5ff1d40b9c84b52861eeb683254f7a3a4bf09e0d3a82457950a9c7c61dc0
7
- data.tar.gz: c7532b43834fe459df96cbbf623493a553a5cbafe8611ae77f682af9e29851fcaa08f68c3d2c246f9a224ba92cd19c04954859b11a6a041222b57c44f5d1031f
6
+ metadata.gz: d9cb1aee522e337bde660667dcf52180fd1d731eb3b99af5959a624e1106883b422d84cf8df1a56c60662dca04a7224ab8bb7e37525638ccb4026dbcdb149205
7
+ data.tar.gz: 0b80d55d640ea93bef07aa5ce379b42963ffc9496c031eb36a853dc4b5a63cf4c4cc6888413938cafff6210bb94d8a9ab851bf173387702be0eb8da0d1fbf170
data/README.md CHANGED
@@ -16,7 +16,7 @@ For example:
16
16
  <div
17
17
  data-controller="mynamespace--deeper--buttons-grid-component"
18
18
  data-mynamespace--deeper--buttons-grid-component-url-value="http://example.com"
19
- data-mynamespace--deeper--buttons-grid-component-url-color="#ff0000"
19
+ data-mynamespace--deeper--buttons-grid-component-color-value="#ff0000"
20
20
  data-action="click->data-mynamespace--deeper--buttons-grid-component#doSomething"
21
21
  >
22
22
  ```
@@ -49,7 +49,7 @@ Or install it yourself as:
49
49
  $ gem install stimulizer
50
50
 
51
51
  ## Usage
52
- Include this in your model:
52
+ Include this in your class:
53
53
 
54
54
  ```ruby
55
55
  class MyComponent < ApplicationComponent
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stimulizer
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/stimulizer.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "stimulizer"
4
+
3
5
  require "active_support/concern"
4
6
  require "dry-configurable"
5
7
  require "lucky_case"
@@ -32,7 +34,15 @@ module Stimulizer
32
34
  end
33
35
 
34
36
  def stimulus_hash(*args)
35
- build_stimulus_hash(*args)
37
+ if args.size == 1 && !args.first.is_a?(Hash)
38
+ build_stimulus_hash(args.first)
39
+ elsif args.size == 1 && args.first.is_a?(Hash)
40
+ build_stimulus_hash(**args.first)
41
+ elsif args.size == 2 && args[1..].all? { |a| a.is_a?(Hash) }
42
+ build_stimulus_hash(args[0], **args[1..].first)
43
+ else
44
+ raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 1..2)"
45
+ end
36
46
  end
37
47
 
38
48
  def stimulus(*args)
@@ -75,7 +85,7 @@ module Stimulizer
75
85
  # ... or combine them:
76
86
  #
77
87
  # <%= stimulus(:controller, target: "button", action: "click->doThing")
78
- def build_stimulus_hash(default_controller = false, controller_name: nil, controller: nil, target: nil, action: nil, params: nil, values: nil, classes: nil)
88
+ def build_stimulus_hash(default_controller = false, controller_name: nil, controller: nil, target: nil, action: nil, params: nil, values: nil, classes: nil, outlets: nil)
79
89
  raise ArgumentError(":controller_name specified, but blank") if controller_name&.blank?
80
90
  raise ArgumentError(":controller specified, but blank") if controller&.blank?
81
91
  raise ArgumentError(":target specified, but blank") if target&.blank?
@@ -83,6 +93,7 @@ module Stimulizer
83
93
  raise ArgumentError(":params specified, but blank") if params&.blank?
84
94
  raise ArgumentError(":values specified, but blank") if values&.blank?
85
95
  raise ArgumentError(":classes specified, but blank") if classes&.blank?
96
+ raise ArgumentError(":outlets specified, but blank") if outlets&.blank?
86
97
 
87
98
  {}.tap do |hash|
88
99
  hash[:"data-controller"] = ""
@@ -129,6 +140,10 @@ module Stimulizer
129
140
  hash[:"data-#{local_controller_name}-#{LuckyCase.dash_case(key.to_s)}-class"] = value
130
141
  end
131
142
 
143
+ outlets&.each do |key, value|
144
+ hash[:"data-#{local_controller_name}-#{LuckyCase.dash_case(key.to_s)}-outlet"] = value
145
+ end
146
+
132
147
  hash[:"data-#{local_controller_name}-target"] = target if target
133
148
  end
134
149
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt E Patterson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-04 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description:
55
+ description:
56
56
  email:
57
57
  - mattp@digimonkey.com
58
58
  executables: []
@@ -81,7 +81,7 @@ metadata:
81
81
  homepage_uri: https://github.com/mepatterson/stimulizer
82
82
  source_code_uri: https://github.com/mepatterson/stimulizer
83
83
  changelog_uri: https://github.com/mepatterson/stimulizer/blob/main/CHANGELOG.md
84
- post_install_message:
84
+ post_install_message:
85
85
  rdoc_options: []
86
86
  require_paths:
87
87
  - lib
@@ -96,8 +96,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.1.6
100
- signing_key:
99
+ rubygems_version: 3.3.7
100
+ signing_key:
101
101
  specification_version: 4
102
102
  summary: Stimulizer provides convenience methods for working with StimulusJS in views,
103
103
  templates, and components.