turbo-rails 0.7.5 → 0.7.9

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: 8f47876ccf2310b44ddc2446fc87935f5284921f515412dfb42c100f53f636c7
4
- data.tar.gz: 77553bb8bed6eeb53dc723a1cab189aa37e695e7b75201d27fdf32a6836d7771
3
+ metadata.gz: 55602f24631c11bc8034e778f706fe6866caca4ff1907b7217c7d4150cf26acd
4
+ data.tar.gz: bfe2afe2a79b5659a66e44bf43d959ee17cc091e18c925207c56a3a7beb71443
5
5
  SHA512:
6
- metadata.gz: a0231dd2d133aaa53e2143ea9119b5753c4df4fcc7e61087e6218de680d42fe4f57e0f9508dcd72d2a5446ef828708754417d2dafd3e53ea72278f360eaea49f
7
- data.tar.gz: cb7099f4d21432fa0a901fd4e2e692b1ea8fac7120ce6bc906475b3b0bfb72adf6920e67b0e4a3a5439c1d20e76c6c777b1707d9aa32effd5e555569656fb3a3
6
+ metadata.gz: 2049be5687158e196102d4a89f1ca1f1e4a5c6f90987b8bc6884f5e8689ef7725853f9d562bc066e4267c06bd7b82c885494d9c35184aca752036377bcdb7fbf
7
+ data.tar.gz: 384956d8e415c8461021b9ef5d4fbec379f81f3b5e6964c08a9b502c8141060187e9838bf1e6aabe973fff1419968ea234534752373c698446da272b28e57ed8
data/README.md CHANGED
@@ -15,6 +15,15 @@ During rendering, Turbo replaces the current `<body>` element outright and merge
15
15
 
16
16
  Whereas Turbolinks previously just dealt with links, Turbo can now also process form submissions and responses. This means the entire flow in the web application is wrapped into Turbo, making all the parts fast. No more need for `data-remote=true`.
17
17
 
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
+
20
+ ```js
21
+ import { Turbo } from "@hotwired/turbo-rails"
22
+ Turbo.session.drive = false
23
+ ```
24
+
25
+ Then you can use `data-turbo="true"` to enable Drive on a per-element basis.
26
+
18
27
 
19
28
  ## Turbo Frames
20
29
 
@@ -37,6 +46,7 @@ The JavaScript for Turbo can either be run through the asset pipeline, which is
37
46
  1. Add the `turbo-rails` gem to your Gemfile: `gem 'turbo-rails'`
38
47
  2. Run `./bin/bundle install`
39
48
  3. Run `./bin/rails turbo:install`
49
+ 4. Run `./bin/rails turbo:install:redis` to change the development Action Cable adapter from Async (the default one) to Redis. The Async adapter does not support Turbo Stream broadcasting.
40
50
 
41
51
  Running `turbo:install` will install through NPM if Webpacker is installed in the application. Otherwise the asset pipeline version is used. To use the asset pipeline version, you must have `importmap-rails` installed first and listed higher in the Gemfile.
42
52
 
@@ -48,6 +58,7 @@ The `Turbo` instance is automatically assigned to `window.Turbo` upon import:
48
58
  import "@hotwired/turbo-rails"
49
59
  ```
50
60
 
61
+
51
62
  ## Usage
52
63
 
53
64
  You can watch [the video introduction to Hotwire](https://hotwired.dev/#screencast), which focuses extensively on demonstration 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).
@@ -1650,7 +1650,7 @@ class BrowserAdapter {
1650
1650
  visitRequestStarted(visit) {
1651
1651
  this.progressBar.setValue(0);
1652
1652
  if (visit.hasCachedSnapshot() || visit.action != "restore") {
1653
- this.showProgressBarAfterDelay();
1653
+ this.showVisitProgressBarAfterDelay();
1654
1654
  } else {
1655
1655
  this.showProgressBar();
1656
1656
  }
@@ -1671,7 +1671,7 @@ class BrowserAdapter {
1671
1671
  }
1672
1672
  visitRequestFinished(visit) {
1673
1673
  this.progressBar.setValue(1);
1674
- this.hideProgressBar();
1674
+ this.hideVisitProgressBar();
1675
1675
  }
1676
1676
  visitCompleted(visit) {}
1677
1677
  pageInvalidated() {
@@ -1681,20 +1681,32 @@ class BrowserAdapter {
1681
1681
  visitRendered(visit) {}
1682
1682
  formSubmissionStarted(formSubmission) {
1683
1683
  this.progressBar.setValue(0);
1684
- this.showProgressBarAfterDelay();
1684
+ this.showFormProgressBarAfterDelay();
1685
1685
  }
1686
1686
  formSubmissionFinished(formSubmission) {
1687
1687
  this.progressBar.setValue(1);
1688
- this.hideProgressBar();
1688
+ this.hideFormProgressBar();
1689
1689
  }
1690
- showProgressBarAfterDelay() {
1691
- this.progressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
1690
+ showVisitProgressBarAfterDelay() {
1691
+ this.visitProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
1692
1692
  }
1693
- hideProgressBar() {
1693
+ hideVisitProgressBar() {
1694
1694
  this.progressBar.hide();
1695
- if (this.progressBarTimeout != null) {
1696
- window.clearTimeout(this.progressBarTimeout);
1697
- delete this.progressBarTimeout;
1695
+ if (this.visitProgressBarTimeout != null) {
1696
+ window.clearTimeout(this.visitProgressBarTimeout);
1697
+ delete this.visitProgressBarTimeout;
1698
+ }
1699
+ }
1700
+ showFormProgressBarAfterDelay() {
1701
+ if (this.formProgressBarTimeout == null) {
1702
+ this.formProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
1703
+ }
1704
+ }
1705
+ hideFormProgressBar() {
1706
+ this.progressBar.hide();
1707
+ if (this.formProgressBarTimeout != null) {
1708
+ window.clearTimeout(this.formProgressBarTimeout);
1709
+ delete this.formProgressBarTimeout;
1698
1710
  }
1699
1711
  }
1700
1712
  reload() {
@@ -1785,6 +1797,7 @@ class FrameRedirector {
1785
1797
  linkClickIntercepted(element, url) {
1786
1798
  const frame = this.findFrameElement(element);
1787
1799
  if (frame) {
1800
+ frame.setAttribute("reloadable", "");
1788
1801
  frame.src = url;
1789
1802
  }
1790
1803
  }
@@ -1794,6 +1807,7 @@ class FrameRedirector {
1794
1807
  formSubmissionIntercepted(element, submitter) {
1795
1808
  const frame = this.findFrameElement(element);
1796
1809
  if (frame) {
1810
+ frame.removeAttribute("reloadable");
1797
1811
  frame.delegate.formSubmissionIntercepted(element, submitter);
1798
1812
  }
1799
1813
  }
@@ -5,71 +5,69 @@
5
5
  module Turbo::Streams::Broadcasts
6
6
  include Turbo::Streams::ActionHelper
7
7
 
8
- def broadcast_remove_to(*streamables, target:)
9
- broadcast_action_to *streamables, action: :remove, target: target
8
+ def broadcast_remove_to(*streamables, **opts)
9
+ broadcast_action_to *streamables, action: :remove, **opts
10
10
  end
11
11
 
12
- def broadcast_replace_to(*streamables, target:, **rendering)
13
- broadcast_action_to *streamables, action: :replace, target: target, **rendering
12
+ def broadcast_replace_to(*streamables, **opts)
13
+ broadcast_action_to *streamables, action: :replace, **opts
14
14
  end
15
15
 
16
- def broadcast_update_to(*streamables, target:, **rendering)
17
- broadcast_action_to *streamables, action: :update, target: target, **rendering
16
+ def broadcast_update_to(*streamables, **opts)
17
+ broadcast_action_to *streamables, action: :update, **opts
18
18
  end
19
19
 
20
- def broadcast_before_to(*streamables, target:, **rendering)
21
- broadcast_action_to *streamables, action: :before, target: target, **rendering
20
+ def broadcast_before_to(*streamables, **opts)
21
+ broadcast_action_to *streamables, action: :before, **opts
22
22
  end
23
23
 
24
- def broadcast_after_to(*streamables, target:, **rendering)
25
- broadcast_action_to *streamables, action: :after, target: target, **rendering
24
+ def broadcast_after_to(*streamables, **opts)
25
+ broadcast_action_to *streamables, action: :after, **opts
26
26
  end
27
27
 
28
- def broadcast_append_to(*streamables, target:, **rendering)
29
- broadcast_action_to *streamables, action: :append, target: target, **rendering
28
+ def broadcast_append_to(*streamables, **opts)
29
+ broadcast_action_to *streamables, action: :append, **opts
30
30
  end
31
31
 
32
- def broadcast_prepend_to(*streamables, target:, **rendering)
33
- broadcast_action_to *streamables, action: :prepend, target: target, **rendering
32
+ def broadcast_prepend_to(*streamables, **opts)
33
+ broadcast_action_to *streamables, action: :prepend, **opts
34
34
  end
35
35
 
36
- def broadcast_action_to(*streamables, action:, target:, **rendering)
37
- broadcast_stream_to *streamables, content: turbo_stream_action_tag(action, target: target, template:
36
+ def broadcast_action_to(*streamables, action:, target: nil, targets: nil, **rendering)
37
+ broadcast_stream_to *streamables, content: turbo_stream_action_tag(action, target: target, targets: targets, template:
38
38
  rendering.delete(:content) || (rendering.any? ? render_format(:html, **rendering) : nil)
39
39
  )
40
40
  end
41
41
 
42
-
43
- def broadcast_replace_later_to(*streamables, target:, **rendering)
44
- broadcast_action_later_to *streamables, action: :replace, target: target, **rendering
42
+ def broadcast_replace_later_to(*streamables, **opts)
43
+ broadcast_action_later_to *streamables, action: :replace, **opts
45
44
  end
46
45
 
47
- def broadcast_update_later_to(*streamables, target:, **rendering)
48
- broadcast_action_later_to *streamables, action: :update, target: target, **rendering
46
+ def broadcast_update_later_to(*streamables, **opts)
47
+ broadcast_action_later_to *streamables, action: :update, **opts
49
48
  end
50
49
 
51
- def broadcast_before_later_to(*streamables, target:, **rendering)
52
- broadcast_action_later_to *streamables, action: :before, target: target, **rendering
50
+ def broadcast_before_later_to(*streamables, **opts)
51
+ broadcast_action_later_to *streamables, action: :before, **opts
53
52
  end
54
53
 
55
- def broadcast_after_later_to(*streamables, target:, **rendering)
56
- broadcast_action_later_to *streamables, action: :after, target: target, **rendering
54
+ def broadcast_after_later_to(*streamables, **opts)
55
+ broadcast_action_later_to *streamables, action: :after, **opts
57
56
  end
58
57
 
59
- def broadcast_append_later_to(*streamables, target:, **rendering)
60
- broadcast_action_later_to *streamables, action: :append, target: target, **rendering
58
+ def broadcast_append_later_to(*streamables, **opts)
59
+ broadcast_action_later_to *streamables, action: :append, **opts
61
60
  end
62
61
 
63
- def broadcast_prepend_later_to(*streamables, target:, **rendering)
64
- broadcast_action_later_to *streamables, action: :prepend, target: target, **rendering
62
+ def broadcast_prepend_later_to(*streamables, **opts)
63
+ broadcast_action_later_to *streamables, action: :prepend, **opts
65
64
  end
66
65
 
67
- def broadcast_action_later_to(*streamables, action:, target:, **rendering)
66
+ def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, **rendering)
68
67
  Turbo::Streams::ActionBroadcastJob.perform_later \
69
- stream_name_from(streamables), action: action, target: target, **rendering
68
+ stream_name_from(streamables), action: action, target: target, targets: targets, **rendering
70
69
  end
71
70
 
72
-
73
71
  def broadcast_render_to(*streamables, **rendering)
74
72
  broadcast_stream_to *streamables, content: render_format(:turbo_stream, **rendering)
75
73
  end
@@ -9,10 +9,7 @@ end
9
9
 
10
10
  if (importmap_path = Rails.root.join("config/importmap.rb")).exist?
11
11
  say "Pin @hotwired/turbo-rails in config/importmap.rb"
12
- insert_into_file \
13
- importmap_path.to_s,
14
- %( pin "@hotwired/turbo-rails", to: "turbo.js"\n\n),
15
- after: "Rails.application.config.importmap.draw do\n"
12
+ append_to_file importmap_path.to_s, %(pin "@hotwired/turbo-rails", to: "turbo.js"\n)
16
13
  else
17
14
  say <<~INSTRUCTIONS, :red
18
15
  You must add @hotwired/turbo-rails to your importmap to reference them via ESM.
@@ -20,4 +17,4 @@ else
20
17
  INSTRUCTIONS
21
18
  end
22
19
 
23
- say "Run turbo:install:redis to switch on Redis and use it in development for turbo streams"
20
+ say "Run turbo:install:redis to switch on Redis and use it in development for turbo streams", :red
data/lib/turbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Turbo
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.9"
3
3
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
8
8
  - Javan Mahkmali
9
9
  - David Heinemeier Hansson
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-08-25 00:00:00.000000000 Z
13
+ date: 2021-08-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -26,7 +26,7 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 6.0.0
29
- description:
29
+ description:
30
30
  email: david@loudthinking.com
31
31
  executables: []
32
32
  extensions: []
@@ -68,7 +68,7 @@ homepage: https://github.com/hotwired/turbo-rails
68
68
  licenses:
69
69
  - MIT
70
70
  metadata: {}
71
- post_install_message:
71
+ post_install_message:
72
72
  rdoc_options: []
73
73
  require_paths:
74
74
  - lib
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  requirements: []
86
86
  rubygems_version: 3.1.4
87
- signing_key:
87
+ signing_key:
88
88
  specification_version: 4
89
89
  summary: The speed of a single-page web application without having to write any JavaScript.
90
90
  test_files: []