turbo-rails 0.7.7 → 0.7.11

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: 4f96104fa6d1282a5f3845a119e748b04a819078840d3750604ebebeac081871
4
- data.tar.gz: 0fdbf552964ff5ada90d746a32ec5575181c010471f4dcd921c2b443bfc732af
3
+ metadata.gz: 0fe3ad5cd094491982825ff80d21c619aab81bbcbe7e07168e467beeb3daa493
4
+ data.tar.gz: 757f2faa9d39389014fc277ef75d3c806c9864b1deb87f6efae5118c604cf89b
5
5
  SHA512:
6
- metadata.gz: 662af2c0c6187537aafc70747ed3f66215bc65bde320475d12d10aeb30d2aca17ed1a3fa1403033a73f51323969782e3e482d5c145a3d0382921045eff22f2cb
7
- data.tar.gz: 23a86030ac88022ba35c3b9369e1cf73bc2803e3c6106abb22ac9b179bb170b78e732fbab873eb56698f7a4c262298f2ab962f89359bd2369ac71820205df513
6
+ metadata.gz: e38bd507e3eaeeccd3e8e570e3341cdc8ae27074ba03d3e509605a13f3df4188bd54250bbbb8f6161e3d3e261e5ae6edd928d3fb2aac7fd8d9ede9e7c1810717
7
+ data.tar.gz: 77f0a351ce8ab0cca1bc69413a508d6d8b790f61e18623ae16aad7d929536baa4f8c75b6407e6752d5301d022f0b49472c4376506181d1ffd31ed91b033459a2
data/README.md CHANGED
@@ -50,7 +50,7 @@ The JavaScript for Turbo can either be run through the asset pipeline, which is
50
50
 
51
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.
52
52
 
53
- If you're using Webpack and need to use the cable consumer, you can import [`cable`](https://github.com/hotwired/turbo-rails/blob/main/app/javascript/turbo/cable.js) (`import { cable } from "@hotwired/turbo-rails"`), but ensure that your application actually *uses* the members it `import`s when using this style (see [turbo-rails#48](https://github.com/hotwired/turbo-rails/issues/48)).
53
+ If you're using node and need to use the cable consumer, you can import [`cable`](https://github.com/hotwired/turbo-rails/blob/main/app/javascript/turbo/cable.js) (`import { cable } from "@hotwired/turbo-rails"`), but ensure that your application actually *uses* the members it `import`s when using this style (see [turbo-rails#48](https://github.com/hotwired/turbo-rails/issues/48)).
54
54
 
55
55
  The `Turbo` instance is automatically assigned to `window.Turbo` upon import:
56
56
 
@@ -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
  }
@@ -0,0 +1,5 @@
1
+ say "Import Turbo"
2
+ append_to_file "app/javascript/application.js", %(import "@hotwired/turbo-rails"\n)
3
+
4
+ say "Pin Turbo"
5
+ append_to_file "config/importmap.rb", %(pin "@hotwired/turbo-rails", to: "turbo.js"\n)
@@ -0,0 +1,9 @@
1
+ if (js_entrypoint_path = Rails.root.join("app/javascript/application.js")).exist?
2
+ say "Import Turbo"
3
+ append_to_file "app/javascript/application.js", %(import "@hotwired/turbo-rails"\n)
4
+ else
5
+ say "You must import @hotwired/turbo-rails in your JavaScript entrypoint file", :red
6
+ end
7
+
8
+ say "Install Turbo"
9
+ run "yarn add @hotwired/turbo-rails"
@@ -1,24 +1,42 @@
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"
5
19
  task :install do
6
- if defined?(Webpacker::Engine)
7
- Rake::Task["turbo:install:webpacker"].invoke
20
+ if Rails.root.join("config/importmap.rb").exist?
21
+ Rake::Task["turbo:install:importmap"].invoke
22
+ elsif Rails.root.join("package.json").exist?
23
+ Rake::Task["turbo:install:node"].invoke
8
24
  else
9
- Rake::Task["turbo:install:asset_pipeline"].invoke
25
+ puts "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem."
10
26
  end
11
27
  end
12
28
 
13
29
  namespace :install do
14
30
  desc "Install Turbo into the app with asset pipeline"
15
- task :asset_pipeline do
16
- run_turbo_install_template "turbo_with_asset_pipeline"
31
+ task :importmap do
32
+ run_turbo_install_template "turbo_with_importmap"
33
+ switch_on_redis_if_available
17
34
  end
18
35
 
19
36
  desc "Install Turbo into the app with webpacker"
20
- task :webpacker do
21
- run_turbo_install_template "turbo_with_webpacker"
37
+ task :node do
38
+ run_turbo_install_template "turbo_with_node"
39
+ switch_on_redis_if_available
22
40
  end
23
41
 
24
42
  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.7"
2
+ VERSION = "0.7.11"
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.7
4
+ version: 0.7.11
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-26 00:00:00.000000000 Z
13
+ date: 2021-09-03 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: []
@@ -57,8 +57,8 @@ files:
57
57
  - app/models/turbo/streams/tag_builder.rb
58
58
  - config/routes.rb
59
59
  - lib/install/turbo_needs_redis.rb
60
- - lib/install/turbo_with_asset_pipeline.rb
61
- - lib/install/turbo_with_webpacker.rb
60
+ - lib/install/turbo_with_importmap.rb
61
+ - lib/install/turbo_with_node.rb
62
62
  - lib/tasks/turbo_tasks.rake
63
63
  - lib/turbo-rails.rb
64
64
  - lib/turbo/engine.rb
@@ -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: []
@@ -1,23 +0,0 @@
1
- if (app_js_path = Rails.root.join("app/javascript/application.js")).exist?
2
- say "Import turbo-rails in existing app/javascript/application.js"
3
- append_to_file app_js_path, %(import "@hotwired/turbo-rails"\n)
4
- else
5
- say <<~INSTRUCTIONS, :red
6
- You must import @hotwired/turbo-rails in your application.js.
7
- INSTRUCTIONS
8
- end
9
-
10
- if (importmap_path = Rails.root.join("config/importmap.rb")).exist?
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"
16
- else
17
- say <<~INSTRUCTIONS, :red
18
- You must add @hotwired/turbo-rails to your importmap to reference them via ESM.
19
- Example: pin "@hotwired/turbo-rails", to: "turbo.js"
20
- INSTRUCTIONS
21
- end
22
-
23
- say "Run turbo:install:redis to switch on Redis and use it in development for turbo streams", :red
@@ -1,7 +0,0 @@
1
- say "Appending Turbo setup code to #{Webpacker.config.source_entry_path}/application.js"
2
- append_to_file "#{Webpacker.config.source_entry_path}/application.js", %(\nimport "@hotwired/turbo-rails"\n)
3
-
4
- say "Install Turbo"
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"