turbo-rails 1.3.2 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -3
- data/Rakefile +15 -2
- data/app/assets/javascripts/turbo.js +280 -127
- data/app/assets/javascripts/turbo.min.js +5 -5
- data/app/assets/javascripts/turbo.min.js.map +1 -1
- data/app/controllers/turbo/frames/frame_request.rb +17 -7
- data/app/controllers/turbo/native/navigation.rb +19 -9
- data/app/helpers/turbo/frames_helper.rb +1 -1
- data/app/helpers/turbo/streams/action_helper.rb +17 -5
- data/app/javascript/turbo/cable_stream_source_element.js +17 -2
- data/app/javascript/turbo/fetch_requests.js +43 -3
- data/app/models/concerns/turbo/broadcastable.rb +42 -10
- data/app/models/turbo/streams/tag_builder.rb +2 -0
- data/app/views/layouts/turbo_rails/frame.html.erb +8 -0
- data/config/routes.rb +1 -1
- data/lib/install/turbo_with_bun.rb +9 -0
- data/lib/tasks/turbo_tasks.rake +35 -18
- data/lib/turbo/broadcastable/test_helper.rb +172 -0
- data/lib/turbo/engine.rb +15 -1
- data/lib/turbo/test_assertions/integration_test_assertions.rb +76 -0
- data/lib/turbo/test_assertions.rb +61 -5
- data/lib/turbo/version.rb +1 -1
- data/lib/turbo-rails.rb +2 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 216ef0fb1d4b07f9231e52702506e6888495d7c15f07a0778eee156692c84d74
|
4
|
+
data.tar.gz: 964ea9a3f3111be08955e9c707a591941dfe7b5f943566716bcd26fbd3d9b19b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f42f0e27dcb80e83b3bae71416b1c9c0cdd82ef462dfa96c57bc3fa2d2c88b548785d9e7b10945575ab53538cfc0cf99c49c3c7f5d6f4fdd0608f251ae38bad
|
7
|
+
data.tar.gz: 21bd467eed15705e4c46f3da62ae84d8466adc85dcd770abc837c1fbcb517ccca2d7a004f9c856bd2af1f6aed9f83df51825929de463428699a35a58c4b89846
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
On top of accelerating web applications, Turbo was built from the ground-up to form the foundation of hybrid native applications. Write the navigational shell of your [Android](https://github.com/hotwired/turbo-android) or [iOS](https://github.com/hotwired/turbo-ios) app using the standard platform tooling, then seamlessly fill in features from the web, following native navigation patterns. Not every mobile screen needs to be written in Swift or Kotlin to feel native. With Turbo, you spend less time wrangling JSON, waiting on app stores to approve updates, or reimplementing features you've already created in HTML.
|
6
6
|
|
7
|
-
Turbo is a language-agnostic framework written in
|
7
|
+
Turbo is a language-agnostic framework written in JavaScript, but this gem builds on top of those basics to make the integration with Rails as smooth as possible. You can deliver turbo updates via model callbacks over Action Cable, respond to controller actions with native navigation or standard redirects, and render turbo frames with helpers and layout-free responses.
|
8
8
|
|
9
9
|
|
10
10
|
## Navigate with Turbo Drive
|
@@ -18,7 +18,7 @@ Whereas Turbolinks previously just dealt with links, Turbo can now also process
|
|
18
18
|
Turbo Drive can be disabled on a per-element basis by annotating the element or any of its ancestors with `data-turbo="false"`. If you want Turbo Drive to be disabled by default, then you can adjust your import like this:
|
19
19
|
|
20
20
|
```js
|
21
|
-
import
|
21
|
+
import "@hotwired/turbo-rails"
|
22
22
|
Turbo.session.drive = false
|
23
23
|
```
|
24
24
|
|
@@ -32,7 +32,7 @@ Turbo reinvents the old HTML technique of frames without any of the drawbacks th
|
|
32
32
|
|
33
33
|
It also makes it dead easy to carve a single page into smaller pieces that can all live on their own cache timeline. While the bulk of the page might easily be cached between users, a small personalized toolbar perhaps cannot. With Turbo::Frames, you can designate the toolbar as a frame, which will be **lazy-loaded automatically** by the publicly-cached root page. This means simpler pages, easier caching schemes with fewer dependent keys, and all without needing to write a lick of custom JavaScript.
|
34
34
|
|
35
|
-
This gem provides a `turbo_frame_tag` helper to create those
|
35
|
+
This gem provides a `turbo_frame_tag` helper to create those frames.
|
36
36
|
|
37
37
|
For instance:
|
38
38
|
```erb
|
@@ -55,6 +55,37 @@ When the user will click on the `Edit this todo` link, as direct response to thi
|
|
55
55
|
|
56
56
|
[See documentation](https://turbo.hotwired.dev/handbook/frames).
|
57
57
|
|
58
|
+
### A note on custom layouts
|
59
|
+
|
60
|
+
In order to render turbo frame requests without the application layout, Turbo registers a custom [layout method](https://api.rubyonrails.org/classes/ActionView/Layouts/ClassMethods.html#method-i-layout).
|
61
|
+
If your application uses custom layout resolution, you have to make sure to return `"turbo_rails/frame"` (or `false` for TurboRails < 1.4.0) for turbo frame requests:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
layout :custom_layout
|
65
|
+
|
66
|
+
def custom_layout
|
67
|
+
return "turbo_rails/frame" if turbo_frame_request?
|
68
|
+
|
69
|
+
# ... your custom layout logic
|
70
|
+
```
|
71
|
+
|
72
|
+
If you are using a custom, but "static" layout,
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
layout "some_static_layout"
|
76
|
+
```
|
77
|
+
|
78
|
+
you **have** to change it to a layout method in order to conditionally return `false` for turbo frame requests:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
layout :custom_layout
|
82
|
+
|
83
|
+
def custom_layout
|
84
|
+
return "turbo_rails/frame" if turbo_frame_request?
|
85
|
+
|
86
|
+
"some_static_layout"
|
87
|
+
```
|
88
|
+
|
58
89
|
## Come Alive with Turbo Streams
|
59
90
|
|
60
91
|
Partial page updates that are **delivered asynchronously over a web socket connection** is the hallmark of modern, reactive web applications. With Turbo Streams, you can get all of that modern goodness using the existing server-side HTML you're already rendering to deliver the first page load. With a set of simple CRUD container tags, you can send HTML fragments over the web socket (or in response to direct interactions), and see the page change in response to new data. Again, **no need to construct an entirely separate API**, **no need to wrangle JSON**, **no need to reimplement the HTML construction in JavaScript**. Take the HTML you're already making, wrap it in an update tag, and, voila, your page comes alive.
|
@@ -96,11 +127,25 @@ import "@hotwired/turbo-rails"
|
|
96
127
|
|
97
128
|
You can watch [the video introduction to Hotwire](https://hotwired.dev/#screencast), which focuses extensively on demonstrating Turbo in a Rails demo. Then you should familiarize yourself with [Turbo handbook](https://turbo.hotwired.dev/handbook/introduction) to understand Drive, Frames, and Streams in-depth. Finally, dive into the code documentation by starting with [`Turbo::FramesHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/frames_helper.rb), [`Turbo::StreamsHelper`](https://github.com/hotwired/turbo-rails/blob/main/app/helpers/turbo/streams_helper.rb), [`Turbo::Streams::TagBuilder`](https://github.com/hotwired/turbo-rails/blob/main/app/models/turbo/streams/tag_builder.rb), and [`Turbo::Broadcastable`](https://github.com/hotwired/turbo-rails/blob/main/app/models/concerns/turbo/broadcastable.rb).
|
98
129
|
|
130
|
+
### RubyDoc Documentation
|
131
|
+
|
132
|
+
For the API documentation covering this gem's classes and packages, [visit the
|
133
|
+
RubyDoc page][].
|
134
|
+
|
135
|
+
[visit the RubyDoc page](https://rubydoc.info/github/hotwired/turbo-rails/main)
|
99
136
|
|
100
137
|
## Compatibility with Rails UJS
|
101
138
|
|
102
139
|
Turbo can coexist with Rails UJS, but you need to take a series of upgrade steps to make it happen. See [the upgrading guide](https://github.com/hotwired/turbo-rails/blob/main/UPGRADING.md).
|
103
140
|
|
141
|
+
## Testing
|
142
|
+
|
143
|
+
|
144
|
+
The [`Turbo::TestAssertions`](./lib/turbo/test_assertions.rb) concern provides Turbo Stream test helpers that assert the presence or absence of `<turbo-stream>` elements in a rendered fragment of HTML. `Turbo::TestAssertions` are automatically included in [`ActiveSupport::TestCase`](https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html) and depend on the presence of [`rails-dom-testing`](https://github.com/rails/rails-dom-testing/) assertions.
|
145
|
+
|
146
|
+
The [`Turbo::TestAssertions::IntegrationTestAssertions`](./lib/turbo/test_assertions/integration_test_assertions.rb) are built on top of `Turbo::TestAssertions`, and add support for passing a `status:` keyword. They are automatically included in [`ActionDispatch::IntegrationTest`](https://edgeguides.rubyonrails.org/testing.html#integration-testing).
|
147
|
+
|
148
|
+
The [`Turbo::Broadcastable::TestHelper`](./lib/turbo/broadcastable/test_helper.rb) concern provides Action Cable-aware test helpers that assert that `<turbo-stream>` elements were or were not broadcast over Action Cable. They are not automatically included. To use them in your tests, make sure to `include Turbo::Broadcastable::TestHelper`.
|
104
149
|
|
105
150
|
## Development
|
106
151
|
|
data/Rakefile
CHANGED
@@ -9,7 +9,20 @@ load "rails/tasks/statistics.rake"
|
|
9
9
|
Rake::TestTask.new do |test|
|
10
10
|
test.libs << "test"
|
11
11
|
test.test_files = FileList["test/**/*_test.rb"]
|
12
|
-
test.warning = false
|
13
12
|
end
|
14
13
|
|
15
|
-
task
|
14
|
+
task :test_prereq do
|
15
|
+
puts "Installing Ruby dependencies"
|
16
|
+
`bundle install`
|
17
|
+
|
18
|
+
puts "Installing JavaScript dependencies"
|
19
|
+
`yarn install`
|
20
|
+
|
21
|
+
puts "Building JavaScript"
|
22
|
+
`yarn build`
|
23
|
+
|
24
|
+
puts "Preparing test database"
|
25
|
+
`cd test/dummy; ./bin/rails db:test:prepare; cd ../..`
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: [:test_prereq, :test]
|