turbo_power 0.1.0 → 0.1.2

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: 2100e6501a16f8b18459a8cb2072e8d9c8f0fda27363a9185275886b4f9e102c
4
- data.tar.gz: 3bd04cb90cc78d23a481240217403f0aea950fca60e83fb800093a68938468bc
3
+ metadata.gz: 3c9df9b4805eb75df7767c66ca573d21ef4bcd94203f19cc7be3982aa2a55e5f
4
+ data.tar.gz: d343c3de805f702633fe5dfc8935bee4117e935bb2d604ff651fe5cf46736fb6
5
5
  SHA512:
6
- metadata.gz: b05a8b3f4423f0cf19acc08983bdc4e9cd99586b462a971f5e889b9adbe452a3d79f4b2feba087a569f3a8533156bb62484eadddd7b0798ed2fcee6cba2b8b07
7
- data.tar.gz: 4998190fa7ef683921c6460a291ff16800bb452578f98bade23844b2500ae26ae8418d3f97da095a99523ca0d1ce722939b8247812a30a3592856f026778cb32
6
+ metadata.gz: fd57269d083dda4a54dc1aba8dea27fd967c98a8c7aae31661178645cd97bc89a3a86b15b4140a73057a2181e77e53db2d21a236a88047990bb109515bf3ae87
7
+ data.tar.gz: eb2d9e17097ceb48da7f11caf084073c062787f198d38d04994124c245ed2466ceacc5ca377db584539993ba10829e7481835190ba7037a9177d6a4e42b9a426
data/Gemfile CHANGED
@@ -9,5 +9,3 @@ gem "rake", "~> 13.0"
9
9
  gem "minitest", "~> 5.0"
10
10
 
11
11
  gem "rubocop", "~> 1.21"
12
-
13
- gem "turbo-rails", github: "marcoroth/turbo-rails", branch: "custom-action-helpers"
data/Gemfile.lock CHANGED
@@ -1,39 +1,74 @@
1
- GIT
2
- remote: https://github.com/marcoroth/turbo-rails.git
3
- revision: ba0c355b74441778f35b58608e2baafc6c0b3c46
4
- branch: custom-action-helpers
5
- specs:
6
- turbo-rails (1.1.1)
7
- actionpack (>= 6.0.0)
8
- activejob (>= 6.0.0)
9
- railties (>= 6.0.0)
10
-
11
1
  PATH
12
2
  remote: .
13
3
  specs:
14
- turbo_power (0.1.0)
15
- turbo-rails
4
+ turbo_power (0.1.2)
5
+ turbo-rails (~> 1.3.0)
6
+ turbo_ready
16
7
 
17
8
  GEM
18
9
  remote: https://rubygems.org/
19
10
  specs:
20
- actionpack (7.0.3.1)
21
- actionview (= 7.0.3.1)
22
- activesupport (= 7.0.3.1)
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)
23
39
  rack (~> 2.0, >= 2.2.0)
24
40
  rack-test (>= 0.6.3)
25
41
  rails-dom-testing (~> 2.0)
26
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
27
- actionview (7.0.3.1)
28
- activesupport (= 7.0.3.1)
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)
29
52
  builder (~> 3.1)
30
53
  erubi (~> 1.4)
31
54
  rails-dom-testing (~> 2.0)
32
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
33
- activejob (7.0.3.1)
34
- activesupport (= 7.0.3.1)
56
+ activejob (7.0.4)
57
+ activesupport (= 7.0.4)
35
58
  globalid (>= 0.3.6)
36
- activesupport (7.0.3.1)
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)
37
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
38
73
  i18n (>= 1.6, < 2)
39
74
  minitest (>= 5.1)
@@ -42,17 +77,37 @@ GEM
42
77
  builder (3.2.4)
43
78
  concurrent-ruby (1.1.10)
44
79
  crass (1.0.6)
80
+ digest (3.1.0)
45
81
  erubi (1.11.0)
46
82
  globalid (1.0.0)
47
83
  activesupport (>= 5.0)
48
84
  i18n (1.12.0)
49
85
  concurrent-ruby (~> 1.0)
50
86
  json (2.6.2)
51
- loofah (2.18.0)
87
+ loofah (2.19.0)
52
88
  crass (~> 1.0.2)
53
89
  nokogiri (>= 1.5.9)
90
+ mail (2.7.1)
91
+ mini_mime (>= 0.1.1)
92
+ marcel (1.0.2)
54
93
  method_source (1.0.0)
94
+ mini_mime (1.1.2)
55
95
  minitest (5.16.3)
96
+ net-imap (0.2.3)
97
+ digest
98
+ net-protocol
99
+ strscan
100
+ net-pop (0.1.1)
101
+ digest
102
+ net-protocol
103
+ timeout
104
+ net-protocol (0.1.3)
105
+ timeout
106
+ net-smtp (0.3.1)
107
+ digest
108
+ net-protocol
109
+ timeout
110
+ nio4r (2.5.8)
56
111
  nokogiri (1.13.8-x86_64-darwin)
57
112
  racc (~> 1.4)
58
113
  parallel (1.22.1)
@@ -62,14 +117,28 @@ GEM
62
117
  rack (2.2.4)
63
118
  rack-test (2.0.2)
64
119
  rack (>= 1.3)
120
+ rails (7.0.4)
121
+ actioncable (= 7.0.4)
122
+ actionmailbox (= 7.0.4)
123
+ actionmailer (= 7.0.4)
124
+ actionpack (= 7.0.4)
125
+ actiontext (= 7.0.4)
126
+ actionview (= 7.0.4)
127
+ activejob (= 7.0.4)
128
+ activemodel (= 7.0.4)
129
+ activerecord (= 7.0.4)
130
+ activestorage (= 7.0.4)
131
+ activesupport (= 7.0.4)
132
+ bundler (>= 1.15.0)
133
+ railties (= 7.0.4)
65
134
  rails-dom-testing (2.0.3)
66
135
  activesupport (>= 4.2.0)
67
136
  nokogiri (>= 1.6)
68
137
  rails-html-sanitizer (1.4.3)
69
138
  loofah (~> 2.3)
70
- railties (7.0.3.1)
71
- actionpack (= 7.0.3.1)
72
- activesupport (= 7.0.3.1)
139
+ railties (7.0.4)
140
+ actionpack (= 7.0.4)
141
+ activesupport (= 7.0.4)
73
142
  method_source
74
143
  rake (>= 12.2)
75
144
  thor (~> 1.0)
@@ -91,10 +160,22 @@ GEM
91
160
  rubocop-ast (1.21.0)
92
161
  parser (>= 3.1.1.0)
93
162
  ruby-progressbar (1.11.0)
163
+ strscan (3.0.4)
94
164
  thor (1.2.1)
165
+ timeout (0.3.0)
166
+ turbo-rails (1.3.0)
167
+ actionpack (>= 6.0.0)
168
+ activejob (>= 6.0.0)
169
+ railties (>= 6.0.0)
170
+ turbo_ready (0.1.0)
171
+ rails (>= 6.1)
172
+ turbo-rails (>= 1.1)
95
173
  tzinfo (2.0.5)
96
174
  concurrent-ruby (~> 1.0)
97
175
  unicode-display_width (2.2.0)
176
+ websocket-driver (0.7.5)
177
+ websocket-extensions (>= 0.1.0)
178
+ websocket-extensions (0.1.5)
98
179
  zeitwerk (2.6.0)
99
180
 
100
181
  PLATFORMS
@@ -104,7 +185,6 @@ DEPENDENCIES
104
185
  minitest (~> 5.0)
105
186
  rake (~> 13.0)
106
187
  rubocop (~> 1.21)
107
- turbo-rails!
108
188
  turbo_power!
109
189
 
110
190
  BUNDLED WITH
data/README.md CHANGED
@@ -1,20 +1,122 @@
1
- # TurboPower
1
+ # TurboPower Rails
2
+
3
+ TurboPower Rails is a power-pack for Turbo Streams. This gem provides server-side Ruby helpers for the NPM package [`turbo_power`](https://github.com/marcoroth/turbo_power).
4
+
5
+ ## Important Note
6
+
7
+ This is very much a work in progress right now. This requires the NPM package `@hotwired/turbo >= 7.2.0` or `@hotwired/turbo-rails >= 7.2.0` and the gem `turbo-rails >= 1.3.0`.
8
+
9
+ **Also:** I can't guarantee that the current API stays that way, there might be even more ways to improve it.
2
10
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/turbo_power`. To experiment with that code, run `bin/console` for an interactive prompt.
4
11
 
5
12
  ## Installation
6
13
 
7
14
  Install the gem and add to the application's Gemfile by executing:
8
15
 
9
- $ bundle add turbo_power
16
+ ```shell
17
+ bundle add turbo_power
18
+ ```
19
+
20
+ Install the JavaScript package:
10
21
 
11
- If bundler is not being used to manage dependencies, install the gem by executing:
22
+ ```shell
23
+ yarn add turbo_power
24
+ ```
12
25
 
13
- $ gem install turbo_power
26
+ Initialize TurboPower in `application.js`:
27
+
28
+ ```diff
29
+ // application.js
30
+ import * as Turbo from '@hotwired/turbo'
31
+
32
+ +import TurboPower from 'turbo_power'
33
+ +TurboPower.initialize(Turbo.StreamActions)
34
+ ```
14
35
 
15
36
  ## Usage
16
37
 
17
- TODO: Write usage instructions here
38
+ ### Actions from `turbo_ready`
39
+
40
+ * [`turbo_stream.invoke(method, *args, selector: nil, camelize: true, id: nil)`](https://github.com/hopsoft/turbo_ready)
41
+
42
+ ### Actions from `turbo-morph`
43
+
44
+ * [`turbo_stream.morph(target, html = nil, **attributes, &block)`](https://github.com/marcoroth/turbo-morph)
45
+
46
+ ### DOM Actions
47
+
48
+ * `turbo_stream.graft(target, parent, **attributes)`
49
+ * `turbo_stream.inner_html(target, html = nil, **attributes, &block)`
50
+ * `turbo_stream.insert_adjacent_html(target, html = nil, position: 'beforeend', **attributes, &block)`
51
+ * `turbo_stream.insert_adjacent_text(target, text, position: 'beforebegin', **attributes)`
52
+ * `turbo_stream.morph(target, html = nil, **attribtues, &block)`
53
+ * `turbo_stream.outer_html(target, html = nil, **attributes, &block)`
54
+ * `turbo_stream.text_content(target, text, **attributes)`
55
+ * `turbo_stream.set_meta(name, content, **attributes)`
56
+
57
+
58
+ ### Attribute Actions
59
+
60
+ * `turbo_stream.add_css_class(target, classes, **attributes)`
61
+ * `turbo_stream.remove_attribute(target, attribute, **attributes)`
62
+ * `turbo_stream.remove_css_class(target, classes, **attributes)`
63
+ * `turbo_stream.set_attribute(target, attribute, value, **attributes)`
64
+ * `turbo_stream.set_dataset_attribute(target, attribute, value, **attributes)`
65
+ * `turbo_stream.set_property(target, property, value, **attributes)`
66
+ * `turbo_stream.set_style(target, name, value, **attributes)`
67
+ * `turbo_stream.set_styles(target, styles, **attributes)`
68
+ * `turbo_stream.set_value(target, value, **attributes)`
69
+
70
+
71
+ ### Event Actions
72
+
73
+ * `turbo_stream.dispatch_event(target, name, detail: {}, **attributes)`
74
+
75
+
76
+ ### Storage Actions
77
+
78
+ * `turbo_stream.clear_storage(type, **attributes)`
79
+ * `turbo_stream.clear_local_storage(**attributes)`
80
+ * `turbo_stream.clear_session_storage(**attributes)`
81
+ * `turbo_stream.remove_storage_item(key, type, **attributes)`
82
+ * `turbo_stream.remove_local_storage_item(key, **attributes)`
83
+ * `turbo_stream.remove_session_storage_item(key, **attributes)`
84
+ * `turbo_stream.set_storage_item(key, value, type, **attributes)`
85
+ * `turbo_stream.set_local_storage_item(key, value, **attributes)`
86
+ * `turbo_stream.set_session_storage_item(key, value, **attributes)`
87
+
88
+
89
+ ### Browser Actions
90
+
91
+ * `turbo_stream.redirect_to(url, action_name = nil, **attributes)`
92
+ * `turbo_stream.reload(**attributes)`
93
+ * `turbo_stream.scroll_into_view(target, inline = "nearest", **attributes)`
94
+ * `turbo_stream.set_cookie(cookie, **attributes)`
95
+ * `turbo_stream.set_cookie_item(key, value, **attributes)`
96
+ * `turbo_stream.set_focus(target, **attributes)`
97
+ * `turbo_stream.set_title(title, **attributes)`
98
+
99
+
100
+ ### Browser History Actions
101
+
102
+ * `turbo_stream.history_go(delta, **attributes)`
103
+ * `turbo_stream.push_state(url, title = nil, state = nil, **attributes)`
104
+ * `turbo_stream.replace_state(url, title = nil, state = nil, **attributes)`
105
+
106
+
107
+ ### Debug Actions
108
+
109
+ * `turbo_stream.console_log(message, level = 'log', **attributes)`
110
+ * `turbo_stream.console_table(data, columns, **attributes)`
111
+
112
+ ### Notification Actions
113
+
114
+ * `turbo_stream.notification(title, options, **attributes)`
115
+
116
+ ### Turbo Frame Actions
117
+
118
+ * `turbo_stream.reload_turbo_frame(frame_id, **attributes)`
119
+ * `turbo_stream.set_turbo_frame_src(frame_id, src, **attributes)`
18
120
 
19
121
  ## Development
20
122
 
@@ -24,7 +126,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
24
126
 
25
127
  ## Contributing
26
128
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/turbo_power. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcoroth/turbo_power/blob/master/CODE_OF_CONDUCT.md).
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcoroth/turbo_power-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/marcoroth/turbo_power-rails/blob/master/CODE_OF_CONDUCT.md).
28
130
 
29
131
  ## License
30
132
 
@@ -32,4 +134,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
32
134
 
33
135
  ## Code of Conduct
34
136
 
35
- Everyone interacting in the TurboPower project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/turbo_power/blob/master/CODE_OF_CONDUCT.md).
137
+ Everyone interacting in the TurboPower project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/marcoroth/turbo_power-rails/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require "rake/testtask"
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
8
8
  t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
10
  end
11
11
 
12
12
  require "rubocop/rake_task"
@@ -1,6 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/engine"
2
4
 
3
5
  module TurboPower
4
6
  class Engine < Rails::Engine
7
+ initializer "turbo_power.helpers", after: :initialize do
8
+ Turbo::Streams::TagBuilder.include(TurboPower::StreamHelper)
9
+ end
5
10
  end
6
11
  end
@@ -1,94 +1,106 @@
1
- require "turbo-rails"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TurboPower
4
4
  module StreamHelper
5
+ # Custom Action Helpers
5
6
 
6
- # DOM Mutations
7
+ ## Also see:
8
+ ## => https://github.com/hotwired/turbo-rails/pull/374
9
+
10
+ def custom_action(name, target: nil, content: nil, allow_inferred_rendering: true, attributes: {}, **rendering, &block)
11
+ template = render_template(target, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block)
12
+
13
+ turbo_stream_action_tag name, target: target, template: template, **attributes
14
+ end
15
+
16
+ def custom_action_all(name, targets: nil, content: nil, allow_inferred_rendering: true, attributes: {}, **rendering, &block)
17
+ template = render_template(targets, content, allow_inferred_rendering: allow_inferred_rendering, **rendering, &block)
18
+
19
+ turbo_stream_action_tag name, targets: targets, template: template, **attributes
20
+ end
21
+
22
+ # DOM Actions
7
23
 
8
24
  def graft(target, parent, **attributes)
9
- action_all :graft, targets: target, attributes: attributes.merge(parent: parent)
25
+ custom_action_all :graft, targets: target, attributes: attributes.merge(parent: parent)
10
26
  end
11
27
 
12
28
  def inner_html(target, html = nil, **attributes, &block)
13
- action_all :inner_html, targets: target, content: html, attributes: attributes, &block
29
+ custom_action_all :inner_html, targets: target, content: html, attributes: attributes, &block
14
30
  end
15
31
 
16
32
  def insert_adjacent_html(target, html = nil, position: 'beforeend', **attributes, &block)
17
- action_all :insert_adjacent_html, targets: target, content: html, attributes: attributes.merge(position: position), &block
33
+ custom_action_all :insert_adjacent_html, targets: target, content: html, attributes: attributes.merge(position: position), &block
18
34
  end
19
35
 
20
36
  def insert_adjacent_text(target, text, position: 'beforebegin', **attributes)
21
- action_all :insert_adjacent_text, targets: target, content: "", attributes: attributes.merge(text: text, position: position)
37
+ custom_action_all :insert_adjacent_text, targets: target, content: "", attributes: attributes.merge(text: text, position: position)
22
38
  end
23
39
 
24
- def morph(target, html = nil, **attribtues, &block)
25
- action_all :morph, targets: target, content: html, attributes: attributes, &block
40
+ def morph(target, html = nil, **attributes, &block)
41
+ custom_action_all :morph, targets: target, content: html, attributes: attributes, &block
26
42
  end
27
43
 
28
44
  def outer_html(target, html = nil, **attributes, &block)
29
- action_all :outer_html, targets: target, content: html, attributes: attributes, &block
45
+ custom_action_all :outer_html, targets: target, content: html, attributes: attributes, &block
30
46
  end
31
47
 
32
48
  def text_content(target, text, **attributes)
33
- action_all :text_content, targets: target, attributes: attributes.merge(text: text)
49
+ custom_action_all :text_content, targets: target, attributes: attributes.merge(text: text)
34
50
  end
35
51
 
52
+ def set_meta(name, content, **attributes)
53
+ custom_action :set_meta, attributes: attributes.merge(name: name, content: content)
54
+ end
36
55
 
37
- # Element Attribute/Property Mutations
38
-
56
+ # Attribute Actions
39
57
 
40
58
  def add_css_class(target, classes, **attributes)
41
- action_all :add_css_class, targets: target, attributes: attributes.merge(classes: classes)
59
+ custom_action_all :add_css_class, targets: target, attributes: attributes.merge(classes: classes)
42
60
  end
43
61
 
44
62
  def remove_attribute(target, attribute, **attributes)
45
- action_all :remove_attribute, targets: target, attributes: attributes.merge(attribute: attribute)
63
+ custom_action_all :remove_attribute, targets: target, attributes: attributes.merge(attribute: attribute)
46
64
  end
47
65
 
48
66
  def remove_css_class(target, classes, **attributes)
49
- action_all :remove_css_class, targets: target, attributes: attributes.merge(classes: classes)
67
+ custom_action_all :remove_css_class, targets: target, attributes: attributes.merge(classes: classes)
50
68
  end
51
69
 
52
70
  def set_attribute(target, attribute, value, **attributes)
53
- action_all :set_attribute, targets: target, attributes: attributes.merge(attribute: attribute, value: value)
71
+ custom_action_all :set_attribute, targets: target, attributes: attributes.merge(attribute: attribute, value: value)
54
72
  end
55
73
 
56
74
  def set_dataset_attribute(target, attribute, value, **attributes)
57
- action_all :set_dataset_attribute, targets: target, attributes: attributes.merge(attribute: attribute, value: value)
75
+ custom_action_all :set_dataset_attribute, targets: target, attributes: attributes.merge(attribute: attribute, value: value)
58
76
  end
59
77
 
60
78
  def set_property(target, property, value, **attributes)
61
- action_all :set_property, targets: target, attributes: attributes.merge(property: property, value: value)
79
+ custom_action_all :set_property, targets: target, attributes: attributes.merge(property: property, value: value)
62
80
  end
63
81
 
64
82
  def set_style(target, name, value, **attributes)
65
- action_all :set_style, targets: target, attributes: attributes.merge(name: name, value: value)
83
+ custom_action_all :set_style, targets: target, attributes: attributes.merge(name: name, value: value)
66
84
  end
67
85
 
68
86
  def set_styles(target, styles, **attributes)
69
- action_all :set_styles, targets: target, attributes: attributes.merge(styles: styles)
87
+ custom_action_all :set_styles, targets: target, attributes: attributes.merge(styles: styles)
70
88
  end
71
89
 
72
90
  def set_value(target, value, **attributes)
73
- action_all :set_value, targets: target, attribtues: attributes.merge(value: value)
91
+ custom_action_all :set_value, targets: target, attribtues: attributes.merge(value: value)
74
92
  end
75
93
 
76
-
77
- # DOM Events
94
+ # Event Actions
78
95
 
79
96
  def dispatch_event(target, name, detail: {}, **attributes)
80
- action_all :dispatch_event, targets: target, attributes: attributes.merge(detail: detail)
81
- end
82
-
83
- def set_meta(name, content)
84
- action :set_meta, attributes: attributes.merge(name: name, content: content)
97
+ custom_action_all :dispatch_event, targets: target, attributes: attributes.merge(name: name, detail: detail)
85
98
  end
86
99
 
87
-
88
- # LocalStorage / SessionStorage
100
+ # Storage Actions
89
101
 
90
102
  def clear_storage(type, **attributes)
91
- action :clear_storage, attributes: attributes.merge(type: type)
103
+ custom_action :clear_storage, attributes: attributes.merge(type: type)
92
104
  end
93
105
 
94
106
  def clear_local_storage(**attributes)
@@ -99,9 +111,8 @@ module TurboPower
99
111
  clear_storage("session", **attributes)
100
112
  end
101
113
 
102
-
103
114
  def remove_storage_item(key, type, **attributes)
104
- action :remove_storage_item, attributes: attributes.merge(key: key, type: type)
115
+ custom_action :remove_storage_item, attributes: attributes.merge(key: key, type: type)
105
116
  end
106
117
 
107
118
  def remove_local_storage_item(key, **attributes)
@@ -112,9 +123,8 @@ module TurboPower
112
123
  remove_storage_item(key, "session", **attributes)
113
124
  end
114
125
 
115
-
116
126
  def set_storage_item(key, value, type, **attributes)
117
- action :set_storage_item, attributes: attributes.merge(key: key, type: type, value: value)
127
+ custom_action :set_storage_item, attributes: attributes.merge(key: key, type: type, value: value)
118
128
  end
119
129
 
120
130
  def set_local_storage_item(key, value, **attributes)
@@ -125,64 +135,74 @@ module TurboPower
125
135
  set_storage_item(key, value, "session", **attributes)
126
136
  end
127
137
 
128
-
129
- # Browser Manipulations
138
+ # Browser Actions
130
139
 
131
140
  def redirect_to(url, action_name = nil, **attributes)
132
- action :redirect_to, attributes: attributes.merge(url: url, action: action_name)
141
+ custom_action :redirect_to, attributes: attributes.merge(url: url, action: action_name)
133
142
  end
134
143
 
135
144
  def reload(**attributes)
136
- action :relaod, attributes: attributes
145
+ custom_action :reload, attributes: attributes
137
146
  end
138
147
 
139
- def scroll_into_view(target, inline = "nearest")
140
- action_all :relaod, targets: target, attributes: attributes.merge(inline: inline)
148
+ def scroll_into_view(target, inline = "nearest", **attributes)
149
+ custom_action_all :scroll_into_view, targets: target, attributes: attributes.merge(inline: inline)
141
150
  end
142
151
 
143
152
  def set_cookie(cookie, **attributes)
144
- action :set_cookie, attributes: attributes.merge(cookie: cookie)
153
+ custom_action :set_cookie, attributes: attributes.merge(cookie: cookie)
145
154
  end
146
155
 
147
156
  def set_cookie_item(key, value, **attributes)
148
- action :set_cookie, attributes: attributes.merge(key: key, value: value)
157
+ custom_action :set_cookie_item, attributes: attributes.merge(key: key, value: value)
149
158
  end
150
159
 
151
160
  def set_focus(target, **attributes)
152
- action_all :set_focus, targets: target, attributes: attributes
161
+ custom_action_all :set_focus, targets: target, attributes: attributes
153
162
  end
154
163
 
164
+ def set_title(title, **attributes)
165
+ custom_action :set_title, attributes: attributes.merge(title: title)
166
+ end
155
167
 
156
- # Browser History
168
+ # Browser History Actions
157
169
 
158
170
  def history_go(delta, **attributes)
159
- action :history_go, attributes: attributes.merge(delta: delta)
171
+ custom_action :history_go, attributes: attributes.merge(delta: delta)
160
172
  end
161
173
 
162
174
  def push_state(url, title = nil, state = nil, **attributes)
163
- action :push_state, attributes: attributes.merge(url: url, title: title, state: state)
175
+ custom_action :push_state, attributes: attributes.merge(url: url, title: title, state: state)
164
176
  end
165
177
 
166
178
  def replace_state(url, title = nil, state = nil, **attributes)
167
- action :replace_state, attributes: attributes.merge(url: url, title: title, state: state)
179
+ custom_action :replace_state, attributes: attributes.merge(url: url, title: title, state: state)
168
180
  end
169
181
 
182
+ # Debug Actions
170
183
 
171
- # Notifications
172
-
173
- def console_log(message, level: :log)
174
- action :console_log, attributes: { message: message, level: level }
184
+ def console_log(message, level = :log, **attributes)
185
+ custom_action :console_log, attributes: attributes.merge(message: message, level: level)
175
186
  end
176
187
 
177
188
  def console_table(data, columns, **attributes)
178
- action :console_table, attributes: attributes.merge(data: data, columns: columns)
189
+ custom_action :console_table, attributes: attributes.merge(data: data, columns: columns)
179
190
  end
180
191
 
192
+ # Notification Actions
193
+
181
194
  def notification(title, options, **attributes)
182
- action :notification, attributes: attributes.merge(title: title, options: options)
195
+ custom_action :notification, attributes: attributes.merge(title: title, options: options)
196
+ end
197
+
198
+ # Turbo Frame Actions
199
+
200
+ def reload_turbo_frame(frame_id, **attributes)
201
+ custom_action :reload_turbo_frame, target: frame_id, attributes: attributes
183
202
  end
184
203
 
204
+ def set_turbo_frame_src(frame_id, src, **attributes)
205
+ custom_action :reload_turbo_frame, target: frame_id, attributes: attributes.merge(src: src)
206
+ end
185
207
  end
186
208
  end
187
-
188
- Turbo::Streams::TagBuilder.prepend(TurboPower::StreamHelper)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboPower
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/turbo_power.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "turbo-rails"
4
+ require "turbo_ready"
5
+
3
6
  require_relative "turbo_power/version"
7
+ require_relative "turbo_power/engine"
4
8
  require_relative "turbo_power/stream_helper"
5
9
 
6
10
  module TurboPower
data/test/test_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
4
- require "turbo_power"
5
4
 
5
+ require "turbo_power"
6
6
  require "minitest/autorun"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ module TurboPower
6
+ class StreamHelperTest < Minitest::Test
7
+ def test_that_it_has_a_version_number
8
+ refute_nil ::TurboPower::VERSION
9
+ end
10
+ end
11
+ end
File without changes
data/turbo_power.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Marco Roth"]
9
9
  spec.email = ["marco.roth@hey.com"]
10
10
 
11
- spec.summary = "Powerpack for Turbo"
11
+ spec.summary = "Power-pack for Turbo Streams"
12
12
  spec.description = spec.summary
13
13
  spec.homepage = "https://github.com/marcoroth/turbo_power-rails"
14
14
  spec.license = "MIT"
@@ -28,5 +28,6 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.test_files = Dir["test/**/*.rb"]
30
30
 
31
- spec.add_dependency "turbo-rails"
31
+ spec.add_dependency "turbo-rails", "~> 1.3.0"
32
+ spec.add_dependency "turbo_ready"
32
33
  end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_power
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Roth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-26 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: turbo-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: turbo_ready
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -24,7 +38,7 @@ dependencies:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
- description: Powerpack for Turbo
41
+ description: Power-pack for Turbo Streams
28
42
  email:
29
43
  - marco.roth@hey.com
30
44
  executables: []
@@ -38,7 +52,6 @@ files:
38
52
  - LICENSE.txt
39
53
  - README.md
40
54
  - Rakefile
41
- - app/helpers/turbo_power/streams/action_helper.rb
42
55
  - bin/console
43
56
  - bin/setup
44
57
  - lib/turbo_power.rb
@@ -46,7 +59,8 @@ files:
46
59
  - lib/turbo_power/stream_helper.rb
47
60
  - lib/turbo_power/version.rb
48
61
  - test/test_helper.rb
49
- - test/test_turbo_power.rb
62
+ - test/turbo_power/stream_helper_test.rb
63
+ - test/turbo_power_test.rb
50
64
  - turbo_power.gemspec
51
65
  homepage: https://github.com/marcoroth/turbo_power-rails
52
66
  licenses:
@@ -73,7 +87,8 @@ requirements: []
73
87
  rubygems_version: 3.3.3
74
88
  signing_key:
75
89
  specification_version: 4
76
- summary: Powerpack for Turbo
90
+ summary: Power-pack for Turbo Streams
77
91
  test_files:
78
92
  - test/test_helper.rb
79
- - test/test_turbo_power.rb
93
+ - test/turbo_power/stream_helper_test.rb
94
+ - test/turbo_power_test.rb
@@ -1,11 +0,0 @@
1
- require "turbo-rails"
2
-
3
- module TurboPower
4
- module Streams
5
- module ActionHelper
6
- include TurboPower::StreamHelper
7
- end
8
- end
9
- end
10
-
11
- Turbo::Streams::TagBuilder.prepend(TurboPower::StreamHelper)