turbo-rails 0.7.6 → 0.7.10

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: d9a5c5d9d67d381421fba7c92a4a3bc2428d8cdeea8bd6787aed126ba8192f0b
4
- data.tar.gz: 6f4633e3908cad563c384fb2a8418ddcf651f0700ea4ffdb284ab3070e946140
3
+ metadata.gz: 41cfe42f850783258d151d4d6ed872633cbb2a7f2ba3c20ad434af326c65dd15
4
+ data.tar.gz: cff176c51977f6c1ba19c31eb36d97ea1958394e7fcde6a489f0d53ec9a74b3b
5
5
  SHA512:
6
- metadata.gz: 348b92c88b2f8dfd28b6c5628ef83619f40f9cde05cc177020a8808226507b0542651254600dab8d1739ce398805d96696d8b59ecc0615ffffa18b86a2834f09
7
- data.tar.gz: 02ba6add278e326446c843f6341f119b85c85d3c9153eed10b28c21d7c7df188f25052b9a155f84dc07a84dcffad90f46726e2559c89ad4be6a6424c87f11b9c
6
+ metadata.gz: 6a8c79d8a32ce7a36aa3f289cd222600d3040bdd5cebaca4836c2fb659ac6e6d847ab02299290429b434a530b7397d9580628edaaba13b088e59c641174ab994
7
+ data.tar.gz: 58eea1099a495e6987a8197630b9c9e6386af8e2016d0cceb92555ca2ce5fba19e6f32eba2244a14751ef9879b92c6793fdc1e1dd6e0b639678ed4c757680a47
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,15 +9,10 @@ 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.
19
16
  Example: pin "@hotwired/turbo-rails", to: "turbo.js"
20
17
  INSTRUCTIONS
21
18
  end
22
-
23
- say "Run turbo:install:redis to switch on Redis and use it in development for turbo streams", :red
@@ -3,5 +3,3 @@ append_to_file "#{Webpacker.config.source_entry_path}/application.js", %(\nimpor
3
3
 
4
4
  say "Install Turbo"
5
5
  run "yarn add @hotwired/turbo-rails"
6
-
7
- say "Run turbo:install:redis to switch on Redis and use it in development for turbo streams"
@@ -1,4 +1,18 @@
1
- def run_turbo_install_template(path) system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}" end
1
+ def run_turbo_install_template(path)
2
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
3
+ end
4
+
5
+ def redis_installed?
6
+ system('which redis-server')
7
+ end
8
+
9
+ def switch_on_redis_if_available
10
+ if redis_installed?
11
+ Rake::Task["turbo:install:redis"].invoke
12
+ else
13
+ puts "Run turbo:install:redis to switch on Redis and use it in development for turbo streams"
14
+ end
15
+ end
2
16
 
3
17
  namespace :turbo do
4
18
  desc "Install Turbo into the app"
@@ -14,11 +28,13 @@ namespace :turbo do
14
28
  desc "Install Turbo into the app with asset pipeline"
15
29
  task :asset_pipeline do
16
30
  run_turbo_install_template "turbo_with_asset_pipeline"
31
+ switch_on_redis_if_available
17
32
  end
18
33
 
19
34
  desc "Install Turbo into the app with webpacker"
20
35
  task :webpacker do
21
36
  run_turbo_install_template "turbo_with_webpacker"
37
+ switch_on_redis_if_available
22
38
  end
23
39
 
24
40
  desc "Switch on Redis and use it in development"
data/lib/turbo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Turbo
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.10"
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.6
4
+ version: 0.7.10
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-09-01 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: []