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 +4 -4
- data/README.md +1 -1
- data/app/assets/javascripts/turbo.js +24 -10
- data/lib/install/turbo_with_importmap.rb +5 -0
- data/lib/install/turbo_with_node.rb +9 -0
- data/lib/tasks/turbo_tasks.rake +26 -8
- data/lib/turbo/version.rb +1 -1
- metadata +8 -8
- data/lib/install/turbo_with_asset_pipeline.rb +0 -23
- data/lib/install/turbo_with_webpacker.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe3ad5cd094491982825ff80d21c619aab81bbcbe7e07168e467beeb3daa493
|
4
|
+
data.tar.gz: 757f2faa9d39389014fc277ef75d3c806c9864b1deb87f6efae5118c604cf89b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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.
|
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.
|
1684
|
+
this.showFormProgressBarAfterDelay();
|
1685
1685
|
}
|
1686
1686
|
formSubmissionFinished(formSubmission) {
|
1687
1687
|
this.progressBar.setValue(1);
|
1688
|
-
this.
|
1688
|
+
this.hideFormProgressBar();
|
1689
1689
|
}
|
1690
|
-
|
1691
|
-
this.
|
1690
|
+
showVisitProgressBarAfterDelay() {
|
1691
|
+
this.visitProgressBarTimeout = window.setTimeout(this.showProgressBar, this.session.progressBarDelay);
|
1692
1692
|
}
|
1693
|
-
|
1693
|
+
hideVisitProgressBar() {
|
1694
1694
|
this.progressBar.hide();
|
1695
|
-
if (this.
|
1696
|
-
window.clearTimeout(this.
|
1697
|
-
delete this.
|
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,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"
|
data/lib/tasks/turbo_tasks.rake
CHANGED
@@ -1,24 +1,42 @@
|
|
1
|
-
def run_turbo_install_template(path)
|
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
|
7
|
-
Rake::Task["turbo:install:
|
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
|
-
|
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 :
|
16
|
-
run_turbo_install_template "
|
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 :
|
21
|
-
run_turbo_install_template "
|
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
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.
|
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-
|
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/
|
61
|
-
- lib/install/
|
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"
|