turbo-rails 2.0.1 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -6
- data/app/assets/javascripts/turbo.js +37 -35
- data/app/assets/javascripts/turbo.min.js +6 -6
- data/app/assets/javascripts/turbo.min.js.map +1 -1
- data/app/channels/turbo/streams/broadcasts.rb +1 -1
- data/app/controllers/turbo/frames/frame_request.rb +1 -1
- data/app/controllers/turbo/native/navigation.rb +6 -3
- data/app/helpers/turbo/drive_helper.rb +17 -18
- data/app/helpers/turbo/frames_helper.rb +4 -7
- data/app/helpers/turbo/streams/action_helper.rb +4 -1
- data/app/helpers/turbo/streams_helper.rb +0 -1
- data/app/models/concerns/turbo/broadcastable.rb +89 -15
- data/lib/turbo/broadcastable/test_helper.rb +4 -4
- data/lib/turbo/engine.rb +7 -2
- data/lib/turbo/test_assertions/integration_test_assertions.rb +2 -2
- data/lib/turbo/test_assertions.rb +2 -2
- data/lib/turbo/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69ad3d302486658277029dd4cf4a51efa1612c4263bd6ff187eca9ed8f519230
|
4
|
+
data.tar.gz: 582b4e20c0169ca996f56fca7e4721bb44d59801cc54ac7c7b350f49b2ee4dc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf580b665e65efe5749b3ea34bb9432d6c53300870e23548101529284c0946318fbf30a4def46d720a1c627c2574f43740b8d3ffc3ae558cf1b98f699060e14
|
7
|
+
data.tar.gz: 143493eae6011883df202a96be8830ad956c9f84799ca5087ce85e15d5fd995a981204927808477ebf4da4c26eaf40e452cf450b01f75abee14f5a860401373d
|
data/README.md
CHANGED
@@ -6,7 +6,6 @@ On top of accelerating web applications, Turbo was built from the ground-up to f
|
|
6
6
|
|
7
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
|
-
|
10
9
|
## Navigate with Turbo Drive
|
11
10
|
|
12
11
|
Turbo is a continuation of the ideas from the previous [Turbolinks](https://github.com/turbolinks/turbolinks) framework, and the heart of that past approach lives on as Turbo Drive. When installed, Turbo automatically intercepts all clicks on `<a href>` links to the same domain. When you click an eligible link, Turbo prevents the browser from following it. Instead, Turbo changes the browser’s URL using the History API, requests the new page using `fetch`, and then renders the HTML response.
|
@@ -122,7 +121,6 @@ The `Turbo` instance is automatically assigned to `window.Turbo` upon import:
|
|
122
121
|
import "@hotwired/turbo-rails"
|
123
122
|
```
|
124
123
|
|
125
|
-
|
126
124
|
## Usage
|
127
125
|
|
128
126
|
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).
|
@@ -130,6 +128,17 @@ You can watch [the video introduction to Hotwire](https://hotwired.dev/#screenca
|
|
130
128
|
### RubyDoc Documentation
|
131
129
|
|
132
130
|
For the API documentation covering this gem's classes and packages, [visit the RubyDoc page](https://rubydoc.info/github/hotwired/turbo-rails/main).
|
131
|
+
Note that this documentation is updated automatically from the main branch, so it may contain features that are not released yet.
|
132
|
+
|
133
|
+
- [Turbo Drive Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/DriveHelper)
|
134
|
+
- [Turbo Frames Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/FramesHelper)
|
135
|
+
- [Turbo Streams View Helpers](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/StreamsHelper)
|
136
|
+
- [Turbo Streams Broadcast Methods](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable)
|
137
|
+
- [Turbo Streams Channel](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/StreamsChannel)
|
138
|
+
- [Turbo Native Navigation](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Native/Navigation)
|
139
|
+
- [Turbo Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions)
|
140
|
+
- [Turbo Integration Test Assertions](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/TestAssertions/IntegrationTestAssertions)
|
141
|
+
- [Turbo Broadcastable Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable/TestHelper)
|
133
142
|
|
134
143
|
## Compatibility with Rails UJS
|
135
144
|
|
@@ -137,18 +146,16 @@ Turbo can coexist with Rails UJS, but you need to take a series of upgrade steps
|
|
137
146
|
|
138
147
|
## Testing
|
139
148
|
|
140
|
-
|
141
|
-
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.
|
149
|
+
The [`Turbo::TestAssertions`](./lib/turbo/test_assertions.rb) concern provides Turbo Stream test helpers that assert the presence or absence ofs s `<turbo-stream>` elements in a rendered fragment of HTML. `Turbo::TestAssertions` are automatically included in [`ActiveSaupport::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.
|
142
150
|
|
143
151
|
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).
|
144
152
|
|
145
|
-
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.
|
153
|
+
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. `Turbo::Broadcastable::TestHelper` is automatically included in [`ActiveSupport::TestCase`](https://edgeapi.rubyonrails.org/classes/ActiveSupport/TestCase.html).
|
146
154
|
|
147
155
|
## Development
|
148
156
|
|
149
157
|
Run the tests with `./bin/test`.
|
150
158
|
|
151
|
-
|
152
159
|
## License
|
153
160
|
|
154
161
|
Turbo is released under the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Turbo 8.0.
|
2
|
+
Turbo 8.0.2
|
3
3
|
Copyright © 2024 37signals LLC
|
4
4
|
*/
|
5
5
|
(function(prototype) {
|
@@ -2647,9 +2647,6 @@ class LinkPrefetchObserver {
|
|
2647
2647
|
if (turboFrameTarget && turboFrameTarget !== "_top") {
|
2648
2648
|
request.headers["Turbo-Frame"] = turboFrameTarget;
|
2649
2649
|
}
|
2650
|
-
if (link.hasAttribute("data-turbo-stream")) {
|
2651
|
-
request.acceptResponseType(StreamMessage.contentType);
|
2652
|
-
}
|
2653
2650
|
}
|
2654
2651
|
requestSucceededWithResponse() {}
|
2655
2652
|
requestStarted(fetchRequest) {}
|
@@ -2662,41 +2659,46 @@ class LinkPrefetchObserver {
|
|
2662
2659
|
}
|
2663
2660
|
#isPrefetchable(link) {
|
2664
2661
|
const href = link.getAttribute("href");
|
2665
|
-
if (!href
|
2666
|
-
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
});
|
2672
|
-
if (event.defaultPrevented) {
|
2673
|
-
return false;
|
2674
|
-
}
|
2675
|
-
if (link.origin !== document.location.origin) {
|
2676
|
-
return false;
|
2677
|
-
}
|
2678
|
-
if (![ "http:", "https:" ].includes(link.protocol)) {
|
2679
|
-
return false;
|
2680
|
-
}
|
2681
|
-
if (link.pathname + link.search === document.location.pathname + document.location.search) {
|
2682
|
-
return false;
|
2683
|
-
}
|
2684
|
-
const turboMethod = link.getAttribute("data-turbo-method");
|
2685
|
-
if (turboMethod && turboMethod !== "get") {
|
2686
|
-
return false;
|
2687
|
-
}
|
2688
|
-
if (targetsIframe(link)) {
|
2689
|
-
return false;
|
2690
|
-
}
|
2691
|
-
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
|
2692
|
-
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") {
|
2693
|
-
return false;
|
2694
|
-
}
|
2662
|
+
if (!href) return false;
|
2663
|
+
if (unfetchableLink(link)) return false;
|
2664
|
+
if (linkToTheSamePage(link)) return false;
|
2665
|
+
if (linkOptsOut(link)) return false;
|
2666
|
+
if (nonSafeLink(link)) return false;
|
2667
|
+
if (eventPrevented(link)) return false;
|
2695
2668
|
return true;
|
2696
2669
|
}
|
2697
2670
|
}
|
2698
2671
|
|
2699
|
-
const
|
2672
|
+
const unfetchableLink = link => link.origin !== document.location.origin || ![ "http:", "https:" ].includes(link.protocol) || link.hasAttribute("target");
|
2673
|
+
|
2674
|
+
const linkToTheSamePage = link => link.pathname + link.search === document.location.pathname + document.location.search || link.href.startsWith("#");
|
2675
|
+
|
2676
|
+
const linkOptsOut = link => {
|
2677
|
+
if (link.getAttribute("data-turbo-prefetch") === "false") return true;
|
2678
|
+
if (link.getAttribute("data-turbo") === "false") return true;
|
2679
|
+
const turboPrefetchParent = findClosestRecursively(link, "[data-turbo-prefetch]");
|
2680
|
+
if (turboPrefetchParent && turboPrefetchParent.getAttribute("data-turbo-prefetch") === "false") return true;
|
2681
|
+
return false;
|
2682
|
+
};
|
2683
|
+
|
2684
|
+
const nonSafeLink = link => {
|
2685
|
+
const turboMethod = link.getAttribute("data-turbo-method");
|
2686
|
+
if (turboMethod && turboMethod.toLowerCase() !== "get") return true;
|
2687
|
+
if (isUJS(link)) return true;
|
2688
|
+
if (link.hasAttribute("data-turbo-confirm")) return true;
|
2689
|
+
if (link.hasAttribute("data-turbo-stream")) return true;
|
2690
|
+
return false;
|
2691
|
+
};
|
2692
|
+
|
2693
|
+
const isUJS = link => link.hasAttribute("data-remote") || link.hasAttribute("data-behavior") || link.hasAttribute("data-confirm") || link.hasAttribute("data-method");
|
2694
|
+
|
2695
|
+
const eventPrevented = link => {
|
2696
|
+
const event = dispatch("turbo:before-prefetch", {
|
2697
|
+
target: link,
|
2698
|
+
cancelable: true
|
2699
|
+
});
|
2700
|
+
return event.defaultPrevented;
|
2701
|
+
};
|
2700
2702
|
|
2701
2703
|
class Navigator {
|
2702
2704
|
constructor(delegate) {
|