turbo_power 0.2.0 → 0.3.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: 9fe460f5963de71ca3deae0ec792bda57273a54a0e938d13c0da62887c76a014
4
- data.tar.gz: 934234dfb39b37bc81b62388f332a1782d18e18b383ad53dabfe22f41cc29e4d
3
+ metadata.gz: 9d0cf2328b31e22e539408a960588cbd9ce68297ed1ac36f74dce79c1be8d121
4
+ data.tar.gz: 314ea1dd8efaae21dde0b4b0e7a6e8654d744ec31e01920d87cb5fc862c4175a
5
5
  SHA512:
6
- metadata.gz: b1d2a5b0554a5e85cb1b9de0f9102733b6b07d37a0f3d16055b3d89637bd31ec07f21eeb3b178e737934f0fb6cbdd7ab022b78fb61976deb23c950db1b55f0a0
7
- data.tar.gz: 2c1b293a1aabd7bd591201b357302192352bccc8a75bab05a626beb9556beaecb45a93096d6dcfb5746235b279e2b91643dd64d68dd2009b7121a883d3c34253
6
+ metadata.gz: d1195a4d9057abdf92df80452176ad592b5966e35e567fe57e38ac135240c1c6053397c041788a7ead9478e39bc3eee9cc2c7373c9ed2851dbf886d34de6731e
7
+ data.tar.gz: 95a088485d9674e56a123f6c5a67da38b6d748e058ce8a0bb7c730568bb6c58001d8b385dc4f38fed8dba80ac62087f729aeb95777bbecfe0d7b7227aa119dd5
data/Gemfile.lock CHANGED
@@ -3,83 +3,37 @@ PATH
3
3
  specs:
4
4
  turbo_power (0.2.0)
5
5
  turbo-rails (~> 1.3.0)
6
- turbo_ready
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
10
9
  specs:
11
- actioncable (7.0.4)
12
- actionpack (= 7.0.4)
13
- activesupport (= 7.0.4)
14
- nio4r (~> 2.0)
15
- websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.4)
17
- actionpack (= 7.0.4)
18
- activejob (= 7.0.4)
19
- activerecord (= 7.0.4)
20
- activestorage (= 7.0.4)
21
- activesupport (= 7.0.4)
22
- mail (>= 2.7.1)
23
- net-imap
24
- net-pop
25
- net-smtp
26
- actionmailer (7.0.4)
27
- actionpack (= 7.0.4)
28
- actionview (= 7.0.4)
29
- activejob (= 7.0.4)
30
- activesupport (= 7.0.4)
31
- mail (~> 2.5, >= 2.5.4)
32
- net-imap
33
- net-pop
34
- net-smtp
35
- rails-dom-testing (~> 2.0)
36
- actionpack (7.0.4)
37
- actionview (= 7.0.4)
38
- activesupport (= 7.0.4)
10
+ actionpack (7.0.4.2)
11
+ actionview (= 7.0.4.2)
12
+ activesupport (= 7.0.4.2)
39
13
  rack (~> 2.0, >= 2.2.0)
40
14
  rack-test (>= 0.6.3)
41
15
  rails-dom-testing (~> 2.0)
42
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.4)
44
- actionpack (= 7.0.4)
45
- activerecord (= 7.0.4)
46
- activestorage (= 7.0.4)
47
- activesupport (= 7.0.4)
48
- globalid (>= 0.6.0)
49
- nokogiri (>= 1.8.5)
50
- actionview (7.0.4)
51
- activesupport (= 7.0.4)
17
+ actionview (7.0.4.2)
18
+ activesupport (= 7.0.4.2)
52
19
  builder (~> 3.1)
53
20
  erubi (~> 1.4)
54
21
  rails-dom-testing (~> 2.0)
55
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.4)
57
- activesupport (= 7.0.4)
23
+ activejob (7.0.4.2)
24
+ activesupport (= 7.0.4.2)
58
25
  globalid (>= 0.3.6)
59
- activemodel (7.0.4)
60
- activesupport (= 7.0.4)
61
- activerecord (7.0.4)
62
- activemodel (= 7.0.4)
63
- activesupport (= 7.0.4)
64
- activestorage (7.0.4)
65
- actionpack (= 7.0.4)
66
- activejob (= 7.0.4)
67
- activerecord (= 7.0.4)
68
- activesupport (= 7.0.4)
69
- marcel (~> 1.0)
70
- mini_mime (>= 1.1.0)
71
- activesupport (7.0.4)
26
+ activesupport (7.0.4.2)
72
27
  concurrent-ruby (~> 1.0, >= 1.0.2)
73
28
  i18n (>= 1.6, < 2)
74
29
  minitest (>= 5.1)
75
30
  tzinfo (~> 2.0)
76
31
  ast (2.4.2)
77
32
  builder (3.2.4)
78
- concurrent-ruby (1.1.10)
33
+ concurrent-ruby (1.2.0)
79
34
  crass (1.0.6)
80
- date (3.3.3)
81
35
  erubi (1.12.0)
82
- globalid (1.0.0)
36
+ globalid (1.1.0)
83
37
  activesupport (>= 5.0)
84
38
  i18n (1.12.0)
85
39
  concurrent-ruby (~> 1.0)
@@ -87,56 +41,26 @@ GEM
87
41
  loofah (2.19.1)
88
42
  crass (~> 1.0.2)
89
43
  nokogiri (>= 1.5.9)
90
- mail (2.8.0)
91
- mini_mime (>= 0.1.1)
92
- net-imap
93
- net-pop
94
- net-smtp
95
- marcel (1.0.2)
96
44
  method_source (1.0.0)
97
- mini_mime (1.1.2)
98
- minitest (5.16.3)
99
- net-imap (0.3.4)
100
- date
101
- net-protocol
102
- net-pop (0.1.2)
103
- net-protocol
104
- net-protocol (0.2.1)
105
- timeout
106
- net-smtp (0.3.3)
107
- net-protocol
108
- nio4r (2.5.8)
109
- nokogiri (1.13.10-x86_64-darwin)
45
+ mini_portile2 (2.8.1)
46
+ minitest (5.17.0)
47
+ nokogiri (1.14.1-x86_64-darwin)
110
48
  racc (~> 1.4)
111
49
  parallel (1.22.1)
112
50
  parser (3.1.3.0)
113
51
  ast (~> 2.4.1)
114
52
  racc (1.6.2)
115
- rack (2.2.5)
53
+ rack (2.2.6.2)
116
54
  rack-test (2.0.2)
117
55
  rack (>= 1.3)
118
- rails (7.0.4)
119
- actioncable (= 7.0.4)
120
- actionmailbox (= 7.0.4)
121
- actionmailer (= 7.0.4)
122
- actionpack (= 7.0.4)
123
- actiontext (= 7.0.4)
124
- actionview (= 7.0.4)
125
- activejob (= 7.0.4)
126
- activemodel (= 7.0.4)
127
- activerecord (= 7.0.4)
128
- activestorage (= 7.0.4)
129
- activesupport (= 7.0.4)
130
- bundler (>= 1.15.0)
131
- railties (= 7.0.4)
132
56
  rails-dom-testing (2.0.3)
133
57
  activesupport (>= 4.2.0)
134
58
  nokogiri (>= 1.6)
135
- rails-html-sanitizer (1.4.4)
59
+ rails-html-sanitizer (1.5.0)
136
60
  loofah (~> 2.19, >= 2.19.1)
137
- railties (7.0.4)
138
- actionpack (= 7.0.4)
139
- activesupport (= 7.0.4)
61
+ railties (7.0.4.2)
62
+ actionpack (= 7.0.4.2)
63
+ activesupport (= 7.0.4.2)
140
64
  method_source
141
65
  rake (>= 12.2)
142
66
  thor (~> 1.0)
@@ -165,23 +89,17 @@ GEM
165
89
  actionpack (>= 5.2)
166
90
  activesupport (>= 5.2)
167
91
  sprockets (>= 3.0.0)
168
- sqlite3 (1.5.4-x86_64-darwin)
92
+ sqlite3 (1.5.4)
93
+ mini_portile2 (~> 2.8.0)
169
94
  thor (1.2.1)
170
- timeout (0.3.1)
171
- turbo-rails (1.3.2)
95
+ turbo-rails (1.3.3)
172
96
  actionpack (>= 6.0.0)
173
97
  activejob (>= 6.0.0)
174
98
  railties (>= 6.0.0)
175
- turbo_ready (0.1.4)
176
- rails (>= 6.1)
177
- turbo-rails (>= 1.1)
178
- tzinfo (2.0.5)
99
+ tzinfo (2.0.6)
179
100
  concurrent-ruby (~> 1.0)
180
101
  unicode-display_width (2.3.0)
181
- websocket-driver (0.7.5)
182
- websocket-extensions (>= 0.1.0)
183
- websocket-extensions (0.1.5)
184
- zeitwerk (2.6.6)
102
+ zeitwerk (2.6.7)
185
103
 
186
104
  PLATFORMS
187
105
  x86_64-darwin-19
data/README.md CHANGED
@@ -83,26 +83,18 @@ import 'controllers'
83
83
  **Note:** These modifications will continue to work when upgrading Turbo via the [turbo-rails](https://github.com/hotwired/turbo-rails) gem. You can [read more](https://github.com/marcoroth/turbo_power-rails/issues/2) for the reasoning behind these adjustments.
84
84
 
85
85
 
86
- ## Usage
87
-
88
- ### Actions from `turbo_ready`
89
-
90
- * [`turbo_stream.invoke(method, *args, selector: nil, camelize: true, id: nil)`](https://github.com/hopsoft/turbo_ready)
91
-
92
- ### Actions from `turbo-morph`
93
-
94
- * [`turbo_stream.morph(target, html = nil, **attributes, &block)`](https://github.com/marcoroth/turbo-morph)
86
+ ## Custom Actions
95
87
 
96
88
  ### DOM Actions
97
89
 
98
90
  * `turbo_stream.graft(target, parent, **attributes)`
91
+ * [`turbo_stream.morph(target, html = nil, **attributes, &block)`](https://github.com/marcoroth/turbo-morph)
99
92
  * `turbo_stream.inner_html(target, html = nil, **attributes, &block)`
100
93
  * `turbo_stream.insert_adjacent_html(target, html = nil, position: 'beforeend', **attributes, &block)`
101
94
  * `turbo_stream.insert_adjacent_text(target, text, position: 'beforebegin', **attributes)`
102
- * `turbo_stream.morph(target, html = nil, **attribtues, &block)`
103
95
  * `turbo_stream.outer_html(target, html = nil, **attributes, &block)`
104
96
  * `turbo_stream.text_content(target, text, **attributes)`
105
- * `turbo_stream.set_meta(name, content, **attributes)`
97
+ * `turbo_stream.set_meta(name, content)`
106
98
 
107
99
 
108
100
  ### Attribute Actions
@@ -112,7 +104,7 @@ import 'controllers'
112
104
  * `turbo_stream.remove_css_class(target, classes, **attributes)`
113
105
  * `turbo_stream.set_attribute(target, attribute, value, **attributes)`
114
106
  * `turbo_stream.set_dataset_attribute(target, attribute, value, **attributes)`
115
- * `turbo_stream.set_property(target, name, value, **attributes)`
107
+ * `turbo_stream.set_property(target, property, value, **attributes)`
116
108
  * `turbo_stream.set_style(target, name, value, **attributes)`
117
109
  * `turbo_stream.set_styles(target, styles, **attributes)`
118
110
  * `turbo_stream.set_value(target, value, **attributes)`
@@ -144,13 +136,17 @@ import 'controllers'
144
136
  ### Browser Actions
145
137
 
146
138
  * `turbo_stream.reload(**attributes)`
147
- * `turbo_stream.scroll_into_view(target, inline = "nearest", **attributes)`
148
- * `turbo_stream.set_cookie(cookie, **attributes)`
149
- * `turbo_stream.set_cookie_item(key, value, **attributes)`
139
+ * `turbo_stream.scroll_into_view(target, inline = "nearest")`
150
140
  * `turbo_stream.set_focus(target, **attributes)`
151
141
  * `turbo_stream.set_title(title, **attributes)`
152
142
 
153
143
 
144
+ ### Document Actions
145
+
146
+ * `turbo_stream.set_cookie(cookie, **attributes)`
147
+ * `turbo_stream.set_cookie_item(key, value, **attributes)`
148
+
149
+
154
150
  ### Browser History Actions
155
151
 
156
152
  * `turbo_stream.history_go(delta, **attributes)`
@@ -160,25 +156,32 @@ import 'controllers'
160
156
 
161
157
  ### Debug Actions
162
158
 
163
- * `turbo_stream.console_log(message, level = 'log', **attributes)`
164
- * `turbo_stream.console_table(data, columns, **attributes)`
159
+ * `turbo_stream.console_log(message, level = :log)`
160
+ * `turbo_stream.console_table(data, columns)`
165
161
 
166
162
 
167
163
  ### Notification Actions
168
164
 
169
- * `turbo_stream.notification(title, options, **attributes)`
165
+ * `turbo_stream.notification(title, **options)`
170
166
 
171
167
 
172
- ### Turbo Frame Actions
168
+ ### Turbo Actions
173
169
 
174
- * `turbo_stream.turbo_frame_reload(frame_id, **attributes)`
175
- * `turbo_stream.turbo_frame_set_src(frame_id, src, **attributes)`
170
+ * `turbo_stream.redirect_to(url, turbo_action = nil, **attributes)`
171
+ * `turbo_stream.turbo_clear_cache()`
176
172
 
177
173
 
178
- ### Turbo Actions
174
+ ### Turbo Progress Bar Actions
179
175
 
180
- * `turbo_stream.redirect_to(url, turbo_action = "advance", **attributes)`
181
- * `turbo_stream.turbo_clear_cache()`
176
+ * `turbo_stream.turbo_progress_bar_show()`
177
+ * `turbo_stream.turbo_progress_bar_hide()`
178
+ * `turbo_stream.turbo_progress_bar_set_value(value)`
179
+
180
+
181
+ ### Turbo Frame Actions
182
+
183
+ * `turbo_stream.turbo_frame_reload(frame_id)`
184
+ * `turbo_stream.turbo_frame_set_src(frame_id, src)`
182
185
 
183
186
 
184
187
  ## Development
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TurboPower
4
+ module AttributeTransformations
5
+ private
6
+
7
+ def transform_attributes(attributes)
8
+ attributes
9
+ .transform_keys { |key| transform_key(key) }
10
+ .transform_values { |value| transform_value(value) }
11
+ end
12
+
13
+ def transform_key(key)
14
+ key.to_s.underscore.dasherize.to_sym
15
+ end
16
+
17
+ def transform_value(value)
18
+ case value
19
+ when String
20
+ value
21
+ when NilClass
22
+ ""
23
+ else
24
+ value.to_json
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,17 +2,19 @@
2
2
 
3
3
  module TurboPower
4
4
  module StreamHelper
5
+ include ::TurboPower::AttributeTransformations
6
+
5
7
  # Custom Action Helpers
6
8
 
7
9
  ## Also see:
8
10
  ## => https://github.com/hotwired/turbo-rails/pull/374
9
11
 
10
12
  def custom_action(name, target: nil, content: nil, attributes: {})
11
- turbo_stream_action_tag name, target: target, template: content, **attributes
13
+ turbo_stream_action_tag name, target: target, template: content, **transform_attributes(attributes)
12
14
  end
13
15
 
14
16
  def custom_action_all(name, targets: nil, content: nil, attributes: {})
15
- turbo_stream_action_tag name, targets: targets, template: content, **attributes
17
+ turbo_stream_action_tag name, targets: targets, template: content, **transform_attributes(attributes)
16
18
  end
17
19
 
18
20
  # DOM Actions
@@ -139,10 +141,6 @@ module TurboPower
139
141
 
140
142
  # Browser Actions
141
143
 
142
- def redirect_to(url, turbo_action = "advance", **attributes)
143
- custom_action :redirect_to, attributes: attributes.merge(url: url, turbo_action: turbo_action)
144
- end
145
-
146
144
  def reload(**attributes)
147
145
  custom_action :reload, attributes: attributes
148
146
  end
@@ -155,8 +153,8 @@ module TurboPower
155
153
  custom_action :set_cookie, attributes: attributes.merge(cookie: cookie)
156
154
  end
157
155
 
158
- def set_cookie_item(key, value, **attributes)
159
- custom_action :set_cookie_item, attributes: attributes.merge(key: key, value: value)
156
+ def set_cookie_item(key = nil, value = nil, **attributes)
157
+ custom_action :set_cookie_item, attributes: { key: key, value: value }.merge(attributes)
160
158
  end
161
159
 
162
160
  def set_focus(target, **attributes)
@@ -167,10 +165,6 @@ module TurboPower
167
165
  custom_action :set_title, attributes: attributes.merge(title: title)
168
166
  end
169
167
 
170
- def turbo_clear_cache(**attributes)
171
- custom_action :turbo_clear_cache, attributes: attributes
172
- end
173
-
174
168
  # Browser History Actions
175
169
 
176
170
  def history_go(delta, **attributes)
@@ -197,8 +191,32 @@ module TurboPower
197
191
 
198
192
  # Notification Actions
199
193
 
200
- def notification(title, options, **attributes)
201
- custom_action :notification, attributes: attributes.merge(title: title, options: options)
194
+ def notification(title = nil, **attributes)
195
+ custom_action :notification, attributes: { title: title }.merge(attributes)
196
+ end
197
+
198
+ # Turbo Actions
199
+
200
+ def redirect_to(url = nil, turbo_action = "advance", **attributes)
201
+ custom_action :redirect_to, attributes: { url: url, turbo_action: turbo_action }.merge(attributes)
202
+ end
203
+
204
+ def turbo_clear_cache(**attributes)
205
+ custom_action :turbo_clear_cache, attributes: attributes
206
+ end
207
+
208
+ # Turbo Progress Bar Actions
209
+
210
+ def turbo_progress_bar_show(**attributes)
211
+ custom_action :turbo_progress_bar_show, attributes: attributes
212
+ end
213
+
214
+ def turbo_progress_bar_hide(**attributes)
215
+ custom_action :turbo_progress_bar_hide, attributes: attributes
216
+ end
217
+
218
+ def turbo_progress_bar_set_value(value, **attributes)
219
+ custom_action :turbo_progress_bar_set_value, attributes: attributes.merge(value: value)
202
220
  end
203
221
 
204
222
  # Turbo Frame Actions
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboPower
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/turbo_power.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "turbo-rails"
4
- require "turbo_ready"
5
4
 
6
5
  require_relative "turbo_power/version"
7
6
  require_relative "turbo_power/engine"
7
+ require_relative "turbo_power/attribute_transformations"
8
8
  require_relative "turbo_power/stream_helper"
9
9
 
10
10
  module TurboPower
data/turbo_power.gemspec CHANGED
@@ -28,5 +28,4 @@ Gem::Specification.new do |spec|
28
28
  ]
29
29
 
30
30
  spec.add_dependency "turbo-rails", "~> 1.3.0"
31
- spec.add_dependency "turbo_ready"
32
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_power
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-04 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turbo-rails
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.3.0
27
- - !ruby/object:Gem::Dependency
28
- name: turbo_ready
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  description: Power-pack for Turbo Streams
42
28
  email:
43
29
  - marco.roth@hey.com
@@ -55,8 +41,8 @@ files:
55
41
  - bin/console
56
42
  - bin/setup
57
43
  - lib/turbo_power.rb
44
+ - lib/turbo_power/attribute_transformations.rb
58
45
  - lib/turbo_power/engine.rb
59
- - lib/turbo_power/patches/broadcastable.rb
60
46
  - lib/turbo_power/stream_helper.rb
61
47
  - lib/turbo_power/version.rb
62
48
  - turbo_power.gemspec
@@ -83,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
69
  - !ruby/object:Gem::Version
84
70
  version: '0'
85
71
  requirements: []
86
- rubygems_version: 3.3.7
72
+ rubygems_version: 3.4.1
87
73
  signing_key:
88
74
  specification_version: 4
89
75
  summary: Power-pack for Turbo Streams
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Patch for Turbo::Broadcastable which is mixed into ActiveRecord
4
- # SEE: https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb
5
- module TurboBoost::Streams::Patches::Broadcastable
6
- def broadcast_invoke_to(*streamables, method, **kwargs)
7
- Turbo::StreamsChannel.broadcast_invoke_to(*streamables, method, **kwargs)
8
- end
9
-
10
- def broadcast_invoke_later_to(*streamables, method, **kwargs)
11
- Turbo::StreamsChannel.broadcast_invoke_later_to(*streamables, method, **kwargs)
12
- end
13
-
14
- def broadcast_set_title(method, **kwargs)
15
- broadcast_invoke_to(self, method, **kwargs)
16
- end
17
-
18
- def broadcast_invoke_later(method, **kwargs)
19
- broadcast_invoke_later_to(self, method, **kwargs)
20
- end
21
- end