turbo_ready 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md.orig DELETED
@@ -1,292 +0,0 @@
1
- <p align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://ik.imagekit.io/hopsoft/turbo-ready-logo-light_df4jcvbDL.webp?ik-sdk-version=javascript-1.4.3&updatedAt=1661615678275">
4
- <img height="200" src="https://ik.imagekit.io/hopsoft/turbo-ready-logo-dark_VN4hA2ctc.webp?ik-sdk-version=javascript-1.4.3&updatedAt=1661615678278" />
5
- </picture>
6
- <h3 align="center">
7
- Turbo Stream's Swiss Army Knife
8
- </h3>
9
- <h1 align="center">
10
- Welcome to TurboReady 👋
11
- </h1>
12
- <p align="center">
13
- <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
14
- <img alt="Lines of Code" src="https://img.shields.io/badge/loc-278-47d299.svg" />
15
- <<<<<<< HEAD
16
- </a>
17
- <a href="https://codeclimate.com/github/hopsoft/turbo_ready/maintainability" target="_blank">
18
- <img src="https://api.codeclimate.com/v1/badges/a69b6f73abc3ccd49261/maintainability" />
19
- </a>
20
- <a href="https://rubygems.org/gems/turbo_ready" target="_blank">
21
- <img alt="GEM" src="https://img.shields.io/gem/v/turbo_ready?color=168AFE&include_prereleases&logo=ruby&logoColor=FE1616">
22
- </a>
23
- <a href="https://www.npmjs.com/package/turbo_ready" target="_blank">
24
- <img alt="NPM" src="https://img.shields.io/npm/v/turbo_ready?color=168AFE&logo=npm">
25
- =======
26
- </a>
27
- <a href="https://codeclimate.com/github/hopsoft/turbo_ready/maintainability">
28
- <img src="https://api.codeclimate.com/v1/badges/a69b6f73abc3ccd49261/maintainability" />
29
- </a>
30
-
31
- <a href="https://rubygems.org/gems/turbo_ready" target="_blank">
32
- <img alt="Gem (including prereleases)" src="https://img.shields.io/gem/v/turbo_ready?color=168AFE&include_prereleases&logo=ruby&logoColor=FE1616">
33
- </a>
34
- <a href="https://github.com/testdouble/standard" target="_blank">
35
- <img alt="Ruby Style" src="https://img.shields.io/badge/style-standard-999?logo=ruby&logoColor=FE1616" />
36
- </a>
37
-
38
- <br>
39
-
40
- <a href="https://www.npmjs.com/package/turbo_ready" target="_blank">
41
- <img alt="npm" src="https://img.shields.io/npm/v/turbo_ready?color=168AFE&logo=npm">
42
- >>>>>>> 2ca627a (Badge updates)
43
- </a>
44
- <a href="https://bundlephobia.com/package/turbo_ready@" target="_blank">
45
- <img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/turbo_ready?label=bundle%20size&logo=javascript&color=47d299">
46
- </a>
47
- <<<<<<< HEAD
48
- <a href="https://github.com/testdouble/standard" target="_blank">
49
- <img alt="Ruby Style" src="https://img.shields.io/badge/style-standard-168AFE?logo=ruby&logoColor=FE1616" />
50
- </a>
51
- <a href="https://github.com/sheerun/prettier-standard" target="_blank">
52
- <img alt="JavaScript Style" src="https://img.shields.io/badge/style-prettier--standard-168AFE?logo=javascript&logoColor=f4e137" />
53
- =======
54
- <a href="https://github.com/sheerun/prettier-standard" target="_blank">
55
- <img alt="JavaScript Style" src="https://img.shields.io/badge/style-prettier--standard-999?logo=javascript&logoColor=f4e137" />
56
- >>>>>>> 2ca627a (Badge updates)
57
- </a>
58
- </p>
59
- </p>
60
-
61
- TurboReady extends [Turbo Streams](https://turbo.hotwired.dev/reference/streams) to give you full control of the
62
- browser's [Document Object Model (DOM).](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)
63
-
64
- **Thats right!**
65
- You can `invoke` any DOM method on any DOM object *(including 3rd party libs)* using Turbo Streams.
66
-
67
- ```ruby
68
- turbo_stream.invoke "console.log", "Hello World!"
69
- ```
70
-
71
- <!-- Tocer[start]: Auto-generated, don't remove. -->
72
-
73
- ## Table of Contents
74
-
75
- - [Why TurboReady?](#why-turboready)
76
- - [Community](#community)
77
- - [Sponsors](#sponsors)
78
- - [Dependencies](#dependencies)
79
- - [Installation](#installation)
80
- - [Setup](#setup)
81
- - [Usage](#usage)
82
- - [Advanced Usage](#advanced-usage)
83
- - [What Else Can I Do?](#what-else-can-i-do)
84
- - [Extending Behavior](#extending-behavior)
85
- - [Public API](#public-api)
86
- - [A Word of Caution](#a-word-of-caution)
87
- - [Releasing](#releasing)
88
- - [License](#license)
89
-
90
- <!-- Tocer[finish]: Auto-generated, don't remove. -->
91
-
92
- ## Why TurboReady?
93
-
94
- Turbo Streams [intentionally restricts](https://turbo.hotwired.dev/handbook/streams#but-what-about-running-javascript%3F)
95
- official actions to CRUD related activity.
96
- The [official actions](https://turbo.hotwired.dev/reference/streams#the-seven-actions) work well for a
97
- considerable number of use cases and you should push Streams as far as possible before reaching for TurboReady.
98
-
99
- If you discover that CRUD isn't enough, TurboReady covers pretty much everything else.
100
-
101
- ## Community
102
-
103
- Please join nearly 2000 of us on [Discord](https://discord.gg/stimulus-reflex) for support getting started,
104
- as well as active discussions around Rails, Hotwire, Stimulus, Turbo (Drive, Frames, Streams), TurboReady, CableReady, StimulusReflex, ViewComponent, Phlex, and more.
105
-
106
- ![](https://img.shields.io/discord/629472241427415060)
107
-
108
- Stop by #newcomers and introduce yourselves!
109
-
110
- ## Sponsors
111
-
112
- <p align="center">
113
- <em>Proudly sponsored by</em>
114
- </p>
115
- <p align="center">
116
- <a href="https://www.clickfunnels.com?utm_source=hopsoft&utm_medium=open-source&utm_campaign=turbo_ready">
117
- <img src="https://images.clickfunnel.com/uploads/digital_asset/file/176632/clickfunnels-dark-logo.svg" width="575" />
118
- </a>
119
- </p>
120
-
121
- ## Dependencies
122
-
123
- - [rails](https://rubygems.org/gems/rails) `>=6.1`
124
- - [turbo-rails](https://rubygems.org/gems/turbo-rails) `>=1.1`
125
- - [@hotwired/turbo-rails](https://yarnpkg.com/package/@hotwired/turbo-rails) `>=7.2.0-beta.2`
126
-
127
- ## Installation
128
-
129
- ```sh
130
- bundle add "turbo_ready --version VERSION"
131
- yarn add "turbo_ready@VERSION --exact"
132
- ```
133
-
134
- **IMPORTANT:** Be sure to use the same version for each libary.
135
-
136
- ## Setup
137
-
138
- 1. Import and intialize TurboReady in your application.
139
-
140
- ```diff
141
- # Gemfile
142
- +gem "turbo_ready", "~> 0.0.5"
143
- ```
144
-
145
- ```diff
146
- # package.json
147
- "dependencies": {
148
- + "@hotwired/turbo-rails": ">=7.2.0-beta.2",
149
- + "turbo_ready": "^0.0.5"
150
- ```
151
-
152
- ```diff
153
- # app/javascript/application.js
154
- import '@hotwired/turbo-rails'
155
- +import TurboReady from 'turbo_ready'
156
-
157
- +TurboReady.initialize(Turbo.StreamActions) // Adds TurboReady stream actions to Turbo
158
- ```
159
-
160
- ## Usage
161
-
162
- Manipulate the DOM from anywhere you use [official Turbo Streams](https://turbo.hotwired.dev/handbook/streams#integration-with-server-side-frameworks).
163
- Namely, [**M**odels](https://guides.rubyonrails.org/active_model_basics.html),
164
- [**V**iews](https://guides.rubyonrails.org/action_view_overview.html),
165
- [**C**ontrollers](https://guides.rubyonrails.org/action_controller_overview.html)
166
- and [Jobs](https://guides.rubyonrails.org/active_job_basics.html).
167
-
168
- You can **chain invocations.** ❤️
169
-
170
- ```ruby
171
- turbo_stream
172
- .invoke("document.body.insertAdjacentHTML", "afterbegin", "<h1>Hello World!</h1>") # dot notation
173
- .invoke("setAttribute", "data-turbo-ready", true, selector: ".button") # selector
174
- .invoke("classList.add", "turbo-ready", selector: "a") # dot notation + selector
175
- .flush # flush must be called when chaining invocations
176
- ```
177
-
178
- You can use [dot notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors#dot_notation)
179
- or [selectors](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll)... **and can even combine them!** 🤯
180
-
181
- Can I dispatch events? **You bet!** ⚡️
182
-
183
- ```ruby
184
- turbo_stream
185
- .invoke("dispatchEvent", "turbo-ready:demo") # fires on window
186
- .invoke("document.dispatchEvent", "turbo-ready:demo") # fires on document
187
- .invoke("dispatchEvent", "turbo-ready:demo", selector: "#my-element") # fires on matching element(s)
188
- .invoke("dispatchEvent", {bubbles: true, detail: {...}}) # set event options
189
- .flush
190
- ```
191
-
192
- ## Advanced Usage
193
-
194
- You can use symbols and [snake case](https://en.wikipedia.org/wiki/Snake_case) when invoking DOM functionality.
195
- It'll implicitly convert to [camel case](https://en.wikipedia.org/wiki/Camel_case). 💎
196
-
197
- ```ruby
198
- turbo_stream
199
- .invoke(:animate, [{opacity: 0}, {opacity: 1}], 2000, selector: "#example")
200
- .invoke(:dispatch_event, {detail: {converts_to_camel_case: true}}, selector: "#example")
201
- .flush
202
- ```
203
-
204
- Need to opt out of camelize? No problem... just disable it.
205
-
206
- ```ruby
207
- turbo_stream.invoke :contrived_demo, camelize: false
208
- ```
209
-
210
- ## What Else Can I Do?
211
-
212
- **The possibilities are endless**
213
- and MDN has your back... [learn about the DOM and web APIs here.](https://developer.mozilla.org/en-US/docs/Web/API.)
214
-
215
- ### Extending Behavior
216
-
217
- Want to extend things with custom functionality? **Let's do it.** 🔌
218
-
219
- ```js
220
- // JavaScript
221
- import morphdom from 'morphdom'
222
-
223
- window.MyNamespace = {
224
- morph: (from, to, options = {}) => {
225
- morphdom(document.querySelector(from), to, options)
226
- }
227
- }
228
- ```
229
-
230
- ```ruby
231
- # Ruby
232
- turbo_stream
233
- .invoke "MyNamespace.morph", "#demo", "<div id='demo'><p>You've changed...</p></div>", {childrenOnly: true}
234
- ```
235
-
236
- ## Public API
237
-
238
- There's only one method to consider, `invoke` defined in the
239
- [tag builder](https://github.com/hopsoft/turbo_ready/blob/main/lib/turbo_ready/tag_builder.rb).
240
-
241
- ```ruby
242
- # Ruby
243
- turbo_stream
244
- .invoke(method, *args, selector: nil, camelize: true, id: nil)
245
- # | | | | |
246
- # | | | | |- Identifies this invocation (optional)
247
- # | | | |
248
- # | | | |- Should we camelize the JavaScript stuff? (optional)
249
- # | | | (allows us to write snake_case Ruby)
250
- # | | |
251
- # | | |- An CSS selector for the element(s) to target (optional)
252
- # | |
253
- # | |- The arguments to pass to the JavaScript method being invoked (optional)
254
- # |
255
- # |- The JavaScript method to invoke (can use dot notation)
256
- ```
257
-
258
- **NOTE:** The JavaScript method will be invoked on all matching elements when a `selector` is passed.
259
-
260
- ## A Word of Caution
261
-
262
- Manually orchestrating DOM activity gets tedious fast.
263
- **⚠️ Don't abuse this superpower!**
264
-
265
- > With great power comes great responsibility. *-Uncle Ben*
266
-
267
- This library is an extremely sharp tool. 🔪
268
- Consider it a low-level building block that can be used to craft additional libraries with
269
- great [DX](https://en.wikipedia.org/wiki/User_experience#Developer_experience)
270
- like [CableReady](https://github.com/stimulusreflex/cable_ready)
271
- and [StimulusReflex](https://github.com/stimulusreflex/stimulus_reflex).
272
-
273
- Restrict your direct application usage to DOM manipulation that falls outside the purview of
274
- [Turbo's official actions](https://turbo.hotwired.dev/reference/streams#the-seven-actions)...
275
- *don't overdo it and find yourself maintaining spaghetti code reminiscent of the jQuery days.*
276
-
277
- ## Releasing
278
-
279
- 1. Run `yarn` and `bundle` to pick up the latest
280
- 1. Bump version number at `lib/turbo_ready/version.rb`. Pre-release versions use `.preN`
281
- 1. Run `rake build` and `yarn build`
282
- 1. Run `bin/standardize`
283
- 1. Commit and push changes to GitHub
284
- 1. Run `rake release`
285
- 1. Run `yarn publish --no-git-tag-version`
286
- 1. Yarn will prompt you for the new version. Pre-release versions use `-preN`
287
- 1. Commit and push changes to GitHub
288
- 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
289
-
290
- ## License
291
-
292
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).