turbo_ready 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d874913424577d763aad4fcc948b8527f85f0ac27b47b81a520f4dd6c999a6a0
4
+ data.tar.gz: ec9feee0db78ef6f8affa77a67e9420849e830d6cd861e081e4d59b6d2f7287e
5
+ SHA512:
6
+ metadata.gz: 25ba8ba8685ecb0d9a63ae5a509b146e089ced8fad07a3b754d24cfc2bd853fdab55ff1da776c0145dc49b57178c0ffdcf7a7710ce1d02d3eafaa047f2b6289e
7
+ data.tar.gz: 546fbda6d1bc72701d45e1c84925893e9d8c88c56521983fb693e7162861e9a929b9b7c0c66ea1e9525540f4cbf4d45bdbe770ea275019724714fadbf41f8b17
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ natehop@gmail.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ # Specify your gem's dependencies in turbo_ready.gemspec.
7
+ gemspec
8
+
9
+ # Start debugger with binding.b [https://github.com/ruby/debug]
10
+ # gem "debug", ">= 1.0.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,249 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ turbo_ready (0.0.1)
5
+ rails (>= 7.0)
6
+ turbo-rails (>= 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.3.1)
12
+ actionpack (= 7.0.3.1)
13
+ activesupport (= 7.0.3.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.3.1)
17
+ actionpack (= 7.0.3.1)
18
+ activejob (= 7.0.3.1)
19
+ activerecord (= 7.0.3.1)
20
+ activestorage (= 7.0.3.1)
21
+ activesupport (= 7.0.3.1)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.3.1)
27
+ actionpack (= 7.0.3.1)
28
+ actionview (= 7.0.3.1)
29
+ activejob (= 7.0.3.1)
30
+ activesupport (= 7.0.3.1)
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.3.1)
37
+ actionview (= 7.0.3.1)
38
+ activesupport (= 7.0.3.1)
39
+ rack (~> 2.0, >= 2.2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.3.1)
44
+ actionpack (= 7.0.3.1)
45
+ activerecord (= 7.0.3.1)
46
+ activestorage (= 7.0.3.1)
47
+ activesupport (= 7.0.3.1)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.3.1)
51
+ activesupport (= 7.0.3.1)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.3.1)
57
+ activesupport (= 7.0.3.1)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.3.1)
60
+ activesupport (= 7.0.3.1)
61
+ activerecord (7.0.3.1)
62
+ activemodel (= 7.0.3.1)
63
+ activesupport (= 7.0.3.1)
64
+ activestorage (7.0.3.1)
65
+ actionpack (= 7.0.3.1)
66
+ activejob (= 7.0.3.1)
67
+ activerecord (= 7.0.3.1)
68
+ activesupport (= 7.0.3.1)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.3.1)
72
+ concurrent-ruby (~> 1.0, >= 1.0.2)
73
+ i18n (>= 1.6, < 2)
74
+ minitest (>= 5.1)
75
+ tzinfo (~> 2.0)
76
+ ast (2.4.2)
77
+ auto_injector (0.8.0)
78
+ marameters (~> 0.6)
79
+ zeitwerk (~> 2.6)
80
+ builder (3.2.4)
81
+ byebug (11.1.3)
82
+ coderay (1.1.3)
83
+ cogger (0.3.0)
84
+ pastel (~> 0.8)
85
+ refinements (~> 9.6)
86
+ zeitwerk (~> 2.6)
87
+ concurrent-ruby (1.1.10)
88
+ crass (1.0.6)
89
+ digest (3.1.0)
90
+ dry-container (0.10.1)
91
+ concurrent-ruby (~> 1.0)
92
+ dry-core (0.8.1)
93
+ concurrent-ruby (~> 1.0)
94
+ dry-monads (1.4.0)
95
+ concurrent-ruby (~> 1.0)
96
+ dry-core (~> 0.7)
97
+ erubi (1.11.0)
98
+ globalid (1.0.0)
99
+ activesupport (>= 5.0)
100
+ i18n (1.12.0)
101
+ concurrent-ruby (~> 1.0)
102
+ json (2.6.2)
103
+ loofah (2.18.0)
104
+ crass (~> 1.0.2)
105
+ nokogiri (>= 1.5.9)
106
+ magic_frozen_string_literal (1.2.0)
107
+ mail (2.7.1)
108
+ mini_mime (>= 0.1.1)
109
+ marameters (0.6.0)
110
+ refinements (~> 9.6)
111
+ zeitwerk (~> 2.6)
112
+ marcel (1.0.2)
113
+ method_source (1.0.0)
114
+ mini_mime (1.1.2)
115
+ minitest (5.16.3)
116
+ net-imap (0.2.3)
117
+ digest
118
+ net-protocol
119
+ strscan
120
+ net-pop (0.1.1)
121
+ digest
122
+ net-protocol
123
+ timeout
124
+ net-protocol (0.1.3)
125
+ timeout
126
+ net-smtp (0.3.1)
127
+ digest
128
+ net-protocol
129
+ timeout
130
+ nio4r (2.5.8)
131
+ nokogiri (1.13.8-aarch64-linux)
132
+ racc (~> 1.4)
133
+ nokogiri (1.13.8-arm64-darwin)
134
+ racc (~> 1.4)
135
+ parallel (1.22.1)
136
+ parser (3.1.2.1)
137
+ ast (~> 2.4.1)
138
+ pastel (0.8.0)
139
+ tty-color (~> 0.5)
140
+ pry (0.14.1)
141
+ coderay (~> 1.1)
142
+ method_source (~> 1.0)
143
+ pry-byebug (3.10.1)
144
+ byebug (~> 11.0)
145
+ pry (>= 0.13, < 0.15)
146
+ racc (1.6.0)
147
+ rack (2.2.4)
148
+ rack-test (2.0.2)
149
+ rack (>= 1.3)
150
+ rails (7.0.3.1)
151
+ actioncable (= 7.0.3.1)
152
+ actionmailbox (= 7.0.3.1)
153
+ actionmailer (= 7.0.3.1)
154
+ actionpack (= 7.0.3.1)
155
+ actiontext (= 7.0.3.1)
156
+ actionview (= 7.0.3.1)
157
+ activejob (= 7.0.3.1)
158
+ activemodel (= 7.0.3.1)
159
+ activerecord (= 7.0.3.1)
160
+ activestorage (= 7.0.3.1)
161
+ activesupport (= 7.0.3.1)
162
+ bundler (>= 1.15.0)
163
+ railties (= 7.0.3.1)
164
+ rails-dom-testing (2.0.3)
165
+ activesupport (>= 4.2.0)
166
+ nokogiri (>= 1.6)
167
+ rails-html-sanitizer (1.4.3)
168
+ loofah (~> 2.3)
169
+ railties (7.0.3.1)
170
+ actionpack (= 7.0.3.1)
171
+ activesupport (= 7.0.3.1)
172
+ method_source
173
+ rake (>= 12.2)
174
+ thor (~> 1.0)
175
+ zeitwerk (~> 2.5)
176
+ rainbow (3.1.1)
177
+ rake (13.0.6)
178
+ refinements (9.6.0)
179
+ regexp_parser (2.5.0)
180
+ rexml (3.2.5)
181
+ rubocop (1.35.0)
182
+ json (~> 2.3)
183
+ parallel (~> 1.10)
184
+ parser (>= 3.1.2.1)
185
+ rainbow (>= 2.2.2, < 4.0)
186
+ regexp_parser (>= 1.8, < 3.0)
187
+ rexml (>= 3.2.5, < 4.0)
188
+ rubocop-ast (>= 1.20.1, < 2.0)
189
+ ruby-progressbar (~> 1.7)
190
+ unicode-display_width (>= 1.4.0, < 3.0)
191
+ rubocop-ast (1.21.0)
192
+ parser (>= 3.1.1.0)
193
+ rubocop-performance (1.14.3)
194
+ rubocop (>= 1.7.0, < 2.0)
195
+ rubocop-ast (>= 0.4.0)
196
+ ruby-progressbar (1.11.0)
197
+ runcom (8.5.0)
198
+ refinements (~> 9.6)
199
+ xdg (~> 6.5)
200
+ spek (0.5.0)
201
+ dry-monads (~> 1.4)
202
+ refinements (~> 9.6)
203
+ versionaire (~> 10.5)
204
+ zeitwerk (~> 2.5)
205
+ standard (1.16.0)
206
+ rubocop (= 1.35.0)
207
+ rubocop-performance (= 1.14.3)
208
+ standardrb (1.0.1)
209
+ standard
210
+ strscan (3.0.4)
211
+ thor (1.2.1)
212
+ timeout (0.3.0)
213
+ tocer (14.3.0)
214
+ auto_injector (~> 0.7)
215
+ cogger (~> 0.2)
216
+ dry-container (~> 0.10)
217
+ refinements (~> 9.6)
218
+ runcom (~> 8.5)
219
+ spek (~> 0.5)
220
+ zeitwerk (~> 2.6)
221
+ tty-color (0.6.0)
222
+ turbo-rails (1.1.1)
223
+ actionpack (>= 6.0.0)
224
+ activejob (>= 6.0.0)
225
+ railties (>= 6.0.0)
226
+ tzinfo (2.0.5)
227
+ concurrent-ruby (~> 1.0)
228
+ unicode-display_width (2.2.0)
229
+ versionaire (10.5.0)
230
+ refinements (~> 9.6)
231
+ websocket-driver (0.7.5)
232
+ websocket-extensions (>= 0.1.0)
233
+ websocket-extensions (0.1.5)
234
+ xdg (6.5.0)
235
+ zeitwerk (2.6.0)
236
+
237
+ PLATFORMS
238
+ aarch64-linux-musl
239
+ arm64-darwin-21
240
+
241
+ DEPENDENCIES
242
+ magic_frozen_string_literal
243
+ pry-byebug
244
+ standardrb
245
+ tocer
246
+ turbo_ready!
247
+
248
+ BUNDLED WITH
249
+ 2.3.17
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Nate Hopkins (hopsoft)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,239 @@
1
+ <p align="center">
2
+ <img height="200" src="https://ik.imagekit.io/hopsoft/turbo-ready-logo_jYFJI1jgT.png?ik-sdk-version=javascript-1.4.3&updatedAt=1661471047153" />
3
+ <h3 align="center">
4
+ Turbo Stream's Swiss Army Knife
5
+ </h3>
6
+ <h1 align="center">
7
+ Welcome to TurboReady 👋
8
+ </h1>
9
+ <p align="center">
10
+ <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
11
+ <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-275-brightgreen.svg?style=flat" />
12
+ </a>
13
+ <a href="https://github.com/testdouble/standard" target="_blank">
14
+ <img alt="Ruby Code Style" src="https://img.shields.io/badge/Ruby_Code_Style-standard-brightgreen.svg" />
15
+ </a>
16
+ <a href="https://github.com/sheerun/prettier-standard" target="_blank">
17
+ <img alt="JavaScript Code Style" src="https://img.shields.io/badge/JavaScript_Code_Style-prettier_standard-ff69b4.svg" />
18
+ </a>
19
+ </p>
20
+ </p>
21
+
22
+ TurboReady extends [Turbo Streams](https://turbo.hotwired.dev/reference/streams) to give you full control of the
23
+ browser's [Document Object Model (DOM).](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)
24
+
25
+ **Thats right!**
26
+ You can `invoke` any DOM method on any DOM object *(including 3rd party libs)* using Turbo Streams.
27
+
28
+ ```ruby
29
+ turbo_stream.invoke "console.log", "Hello World!"
30
+ ```
31
+
32
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
33
+
34
+ ## Table of Contents
35
+
36
+ - [Why TurboReady?](#why-turboready)
37
+ - [Discord Community](#discord-community)
38
+ - [A Word of Caution ⚠️](#a-word-of-caution-)
39
+ - [Sponsor](#sponsor)
40
+ - [Dependencies](#dependencies)
41
+ - [Installation](#installation)
42
+ - [Setup](#setup)
43
+ - [Usage](#usage)
44
+ - [Endless Possibilities](#endless-possibilities)
45
+ - [Advanced Usage](#advanced-usage)
46
+ - [Public API](#public-api)
47
+ - [Releasing](#releasing)
48
+ - [License](#license)
49
+
50
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
51
+
52
+ ## Why TurboReady?
53
+
54
+ Turbo Streams [intentionally restricts](https://turbo.hotwired.dev/handbook/streams#but-what-about-running-javascript)
55
+ official actions to CRUD related activity.
56
+ The [official actions](https://turbo.hotwired.dev/reference/streams#the-seven-actions) work well for a
57
+ considerable number of use cases and you should push Streams as far as possible before reaching for TurboReady.
58
+
59
+ If you discover that CRUD isn't enough, TurboReady covers pretty much everything else.
60
+
61
+ ## Discord Community
62
+
63
+ Please join nearly 2000 of us on [Discord](https://discord.gg/stimulus-reflex) for support getting started,
64
+ as well as active discussions around Rails, Hotwire, Stimulus, Turbo (Drive, Frames, Streams), TurboReady, CableReady, and StimulusReflex.
65
+
66
+ ![](https://img.shields.io/discord/629472241427415060)
67
+
68
+ Stop by #newcomers and introduce yourselves!
69
+
70
+ ## A Word of Caution ⚠️
71
+
72
+ Manually orchestrating DOM activity gets tedious fast.
73
+ **Don't abuse this superpower!**
74
+
75
+ > With great power comes great responsibility. *-Uncle Ben*
76
+
77
+ This library is an extremely sharp tool. 🔪
78
+ Consider it a low-level building block that can be used to craft additional libraries with
79
+ great [DX](https://en.wikipedia.org/wiki/User_experience#Developer_experience)
80
+ like [CableReady](https://github.com/stimulusreflex/cable_ready)
81
+ and [StimulusReflex](https://github.com/stimulusreflex/stimulus_reflex).
82
+
83
+ Restrict your direct application usage to DOM manipulations that fall outside the purview of
84
+ [Turbo's official actions](https://turbo.hotwired.dev/reference/streams#the-seven-actions)...
85
+ *and for Pete's sake, don't overdo it and find yourself maintaining spaghetti code reminicent of the jQuery days.*
86
+
87
+ ## Sponsor
88
+
89
+ <p align="center">
90
+ <em>Proudly sponsored by</em>
91
+ </p>
92
+ <p align="center">
93
+ <a href="https://www.clickfunnels.com?utm_source=hopsoft&utm_medium=open-source&utm_campaign=turbo_ready">
94
+ <img src="https://images.clickfunnel.com/uploads/digital_asset/file/176632/clickfunnels-dark-logo.svg" width="575" />
95
+ </a>
96
+ </p>
97
+
98
+ ## Dependencies
99
+
100
+ - [rails](https://rubygems.org/gems/rails) `>=7.0`
101
+ - [turbo-rails](https://rubygems.org/gems/turbo-rails) `>=1.1`
102
+ - [@hotwired/turbo-rails](https://yarnpkg.com/package/@hotwired/turbo-rails) `>=7.2.0-beta.2`
103
+
104
+ ## Installation
105
+
106
+ ```sh
107
+ bundle add "turbo_ready --version VERSION"
108
+ yarn add "turbo_ready@VERSION --exact"
109
+ ```
110
+
111
+ **IMPORTANT:** Be sure to use the same version for each libary.
112
+
113
+ ## Setup
114
+
115
+ 1. Create a Rails intializer and patch Turbo.
116
+
117
+ ```ruby
118
+ # config/initializers/turbo_ready.rb
119
+ TurboReady.patch! # Adds TurboReady stream actions to Turbo
120
+ ```
121
+ 2. Import and intialize TurboReady in your JavaScript application.
122
+
123
+ ```js
124
+ // app/javascript/application.js
125
+ import '@hotwired/turbo-rails'
126
+ import TurboReady from 'turbo_ready'
127
+
128
+ TurboReady.initialize(Turbo.StreamActions) // Adds TurboReady stream actions to Turbo
129
+ ```
130
+
131
+ ## Usage
132
+
133
+ Manipulate the DOM from anywhere you use [official Turbo Streams](https://turbo.hotwired.dev/handbook/streams#integration-with-server-side-frameworks).
134
+ Namely, [ActiveRecord Models](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb),
135
+ [Controllers](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb),
136
+ and [View Templates](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb).
137
+
138
+ You can also **chain invocations.** ❤️
139
+
140
+ ```ruby
141
+ turbo_stream
142
+ .invoke("document.body.insertAdjacentHTML", "afterbegin", "<h1>Hello World!</h1>") # dot notation
143
+ .invoke("setAttribute", "data-turbo-ready", true, selector: ".button") # selector
144
+ .invoke("classList.add", "turbo-ready", selector: "a") # dot notation + selector
145
+ .flush # flush must be called when chaining invocations
146
+ ```
147
+
148
+ You can use [dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#dot_notation)
149
+ or a [selector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll)... or even **use them together!** 🤯
150
+
151
+ Can I dispatch events? **You bet!** ⚡️
152
+
153
+ ```ruby
154
+ turbo_stream
155
+ .invoke("dispatchEvent", "turbo-ready:demo") // fires on window
156
+ .invoke("dispatchEvent", "turbo-ready:demo", selector: "#my-element") // fires on matching element(s)
157
+ .invoke("dispatchEvent", {bubbles: true, detail: {...}}) // set event options
158
+ .flush
159
+ ```
160
+
161
+ ## Endless Possibilities
162
+
163
+ **What else can I do?**
164
+ MDN has your back... [learn about the DOM and web APIs here.](https://developer.mozilla.org/en-US/docs/Web/API.)
165
+
166
+ ## Advanced Usage
167
+
168
+ Want to extend things further with some custom functionality? **Let's do it.** 🔌
169
+
170
+ ```js
171
+ import morphdom from 'morphdom'
172
+
173
+ window.MyNamespace = {
174
+ morph: (from, to, options = {}) => {
175
+ morphdom(document.querySelector(from), to, options)
176
+ }
177
+ }
178
+ ```
179
+
180
+ ```ruby
181
+ turbo_stream.invoke "MyNamespace.morph", "#demo", "<div id='demo'><p>You've changed...</p></div>", {childrenOnly: true}
182
+ ```
183
+
184
+ **But this doesn't look like Ruby...** well then, just use symbols and
185
+ [snake case](https://en.wikipedia.org/wiki/Snake_case) when invoking DOM functionality.
186
+ It'll implicitly convert to [camel case](https://en.wikipedia.org/wiki/Camel_case).
187
+
188
+ ```ruby
189
+ turbo_stream
190
+ .invoke(:animate, [{opacity: 0}, {opacity: 1}], 2000)
191
+ .invoke(:dispatch_event, {detail: {converts_camel_case: true}})
192
+ .flush
193
+ ```
194
+
195
+ Need to opt out of camelize? No problem... just disable it.
196
+
197
+ ```ruby
198
+ turbo_stream.invoke :contrived_demo, camelize: false
199
+ ```
200
+
201
+ ## Public API
202
+
203
+ There's only one method to consider, `invoke` defined in the
204
+ [tag builder](https://github.com/hopsoft/turbo_ready/blob/main/lib/turbo_ready/tag_builder.rb).
205
+
206
+ ```ruby
207
+ turbo_stream
208
+ .invoke(method, *args, selector: nil, camelize: true, id: nil)
209
+ # | | | | |
210
+ # | | | | |- Identifies this invocation (optional)
211
+ # | | | |
212
+ # | | | |- Should we camelize the JavaScript stuff? (optional)
213
+ # | | | (allows us to write snake_case Ruby)
214
+ # | | |
215
+ # | | |- An CSS selector for the element(s) to target (optional)
216
+ # | |
217
+ # | |- The arguments to pass to the JavaScript method being invoked (optional)
218
+ # |
219
+ # |- The JavaScript method to invoke (can use dot notation)
220
+ ```
221
+
222
+ **NOTE:** The JavaScript method will be invoked on all matching elements when a `selector` is passed.
223
+
224
+ ## Releasing
225
+
226
+ 1. Run `yarn` and `bundle` to pick up the latest
227
+ 1. Bump version number at `lib/turbo_ready/version.rb`. Pre-release versions use `.preN`
228
+ 1. Run `rake build` and `yarn build`
229
+ 1. Run `bin/standardize`
230
+ 1. Commit and push changes to GitHub
231
+ 1. Run `rake release`
232
+ 1. Run `yarn publish --no-git-tag-version`
233
+ 1. Yarn will prompt you for the new version. Pre-release versions use `-preN`
234
+ 1. Commit and push changes to GitHub
235
+ 1. Create a new release on GitHub ([here](https://github.com/hopsoft/turbo_ready/releases)) and generate the changelog for the stable release for it
236
+
237
+ ## License
238
+
239
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/setup"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ function l(){let n=JSON.parse(this.templateContent.textContent),{id:h,method:a,args:i,receiver:c,selector:r}=n,t=[self];switch(r&&(t=Array.from(document.querySelectorAll(r))),c&&(t=t.map(o=>{let e=o,s=c.split(".");for(;s.length>0;)e=e[s.shift()];return e})),a){case"dispatchEvent":let o=new CustomEvent(i[0],i[1]||{});t.forEach(e=>e.dispatchEvent(o));break;default:t.forEach(e=>e[a].apply(e,i))}}var f={initialize:n=>n.invoke=l};export{f as default};
2
+ //# sourceMappingURL=turbo_ready.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../javascript/turbo_ready.js"],
4
+ "sourcesContent": ["function invoke () {\n const payload = JSON.parse(this.templateContent.textContent)\n const { id, method, args, receiver, selector } = payload\n let receivers = [self]\n if (selector) receivers = Array.from(document.querySelectorAll(selector))\n\n if (receiver) {\n receivers = receivers.map(r => {\n let context = r\n const chain = receiver.split('.')\n while (chain.length > 0) context = context[chain.shift()]\n return context\n })\n }\n\n switch (method) {\n case 'dispatchEvent':\n const evt = new CustomEvent(args[0], args[1] || {})\n receivers.forEach(r => r.dispatchEvent(evt))\n break\n default:\n receivers.forEach(r => r[method].apply(r, args))\n }\n}\n\nexport default {\n initialize: streamActions => (streamActions.invoke = invoke)\n}\n"],
5
+ "mappings": "AAAA,SAASA,GAAU,CACjB,IAAMC,EAAU,KAAK,MAAM,KAAK,gBAAgB,WAAW,EACrD,CAAE,GAAAC,EAAI,OAAAC,EAAQ,KAAAC,EAAM,SAAAC,EAAU,SAAAC,CAAS,EAAIL,EAC7CM,EAAY,CAAC,IAAI,EAYrB,OAXID,IAAUC,EAAY,MAAM,KAAK,SAAS,iBAAiBD,CAAQ,CAAC,GAEpED,IACFE,EAAYA,EAAU,IAAIC,GAAK,CAC7B,IAAIC,EAAUD,EACRE,EAAQL,EAAS,MAAM,GAAG,EAChC,KAAOK,EAAM,OAAS,GAAGD,EAAUA,EAAQC,EAAM,MAAM,GACvD,OAAOD,CACT,CAAC,GAGKN,OACD,gBACH,IAAMQ,EAAM,IAAI,YAAYP,EAAK,GAAIA,EAAK,IAAM,CAAC,CAAC,EAClDG,EAAU,QAAQC,GAAKA,EAAE,cAAcG,CAAG,CAAC,EAC3C,cAEAJ,EAAU,QAAQC,GAAKA,EAAEL,GAAQ,MAAMK,EAAGJ,CAAI,CAAC,EAErD,CAEA,IAAOQ,EAAQ,CACb,WAAYC,GAAkBA,EAAc,OAASb,CACvD",
6
+ "names": ["invoke", "payload", "id", "method", "args", "receiver", "selector", "receivers", "r", "context", "chain", "evt", "turbo_ready_default", "streamActions"]
7
+ }