turbo-rails 0.5.9 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/Rakefile +4 -0
- data/app/assets/javascripts/turbo.js +1427 -1112
- data/app/channels/turbo/streams/broadcasts.rb +24 -0
- data/app/helpers/turbo/frames_helper.rb +4 -0
- data/app/helpers/turbo/streams/action_helper.rb +12 -3
- data/app/helpers/turbo/streams_helper.rb +5 -3
- data/app/javascript/turbo/cable.js +6 -3
- data/app/jobs/turbo/streams/action_broadcast_job.rb +2 -0
- data/app/jobs/turbo/streams/broadcast_job.rb +2 -0
- data/app/models/concerns/turbo/broadcastable.rb +72 -9
- data/app/models/turbo/streams/tag_builder.rb +140 -11
- data/lib/install/turbo_with_asset_pipeline.rb +10 -10
- data/lib/install/turbo_with_webpacker.rb +14 -8
- data/lib/turbo/engine.rb +5 -1
- data/lib/turbo/test_assertions.rb +2 -3
- data/lib/turbo/version.rb +1 -1
- metadata +7 -7
@@ -1,5 +1,6 @@
|
|
1
1
|
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
|
2
2
|
IMPORTMAP_PATH = Rails.root.join("app/assets/javascripts/importmap.json.erb")
|
3
|
+
CABLE_CONFIG_PATH = Rails.root.join("config/cable.yml")
|
3
4
|
|
4
5
|
if APPLICATION_LAYOUT_PATH.exist?
|
5
6
|
say "Yield head in application layout for cache helper"
|
@@ -19,18 +20,17 @@ if APPLICATION_LAYOUT_PATH.exist?
|
|
19
20
|
end
|
20
21
|
else
|
21
22
|
say "Default application.html.erb is missing!", :red
|
22
|
-
|
23
|
-
if APPLICATION_LAYOUT_PATH.read =~ /stimulus/
|
24
|
-
say %( Add <%= javascript_include_tag("turbo", type: "module-shim") %> and <%= yield :head %> within the <head> tag after Stimulus includes in your custom layout.)
|
25
|
-
else
|
26
|
-
say %( Add <%= javascript_include_tag("turbo", type: "module") %> and <%= yield :head %> within the <head> tag in your custom layout.)
|
27
|
-
end
|
23
|
+
say %( Add <%= javascript_include_tag("turbo", type: "module-shim") %> and <%= yield :head %> within the <head> tag after Stimulus includes in your custom layout.)
|
28
24
|
end
|
29
25
|
|
30
|
-
|
31
|
-
|
26
|
+
if CABLE_CONFIG_PATH.exist?
|
27
|
+
say "Enable redis in bundle"
|
28
|
+
uncomment_lines "Gemfile", %(gem 'redis')
|
32
29
|
|
33
|
-
say "Switch development cable to use redis"
|
34
|
-
gsub_file
|
30
|
+
say "Switch development cable to use redis"
|
31
|
+
gsub_file CABLE_CONFIG_PATH.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
32
|
+
else
|
33
|
+
say 'ActionCable config file (config/cable.yml) is missing. Uncomment "gem \'redis\'" in your Gemfile and create config/cable.yml to use the Turbo Streams broadcast feature.'
|
34
|
+
end
|
35
35
|
|
36
36
|
say "Turbo successfully installed ⚡️", :green
|
@@ -1,23 +1,29 @@
|
|
1
1
|
# Some Rails versions use commonJS(require) others use ESM(import).
|
2
2
|
TURBOLINKS_REGEX = /(import .* from "turbolinks".*\n|require\("turbolinks"\).*\n)/.freeze
|
3
|
+
ACTIVE_STORAGE_REGEX = /(import.*ActiveStorage|require.*@rails\/activestorage.*)/.freeze
|
4
|
+
CABLE_CONFIG_PATH = Rails.root.join("config/cable.yml")
|
3
5
|
|
4
6
|
abort "❌ Webpacker not found. Exiting." unless defined?(Webpacker::Engine)
|
5
7
|
|
6
8
|
say "Install Turbo"
|
7
9
|
run "yarn add @hotwired/turbo-rails"
|
8
|
-
insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "import \"@hotwired/turbo-rails\"\n", before:
|
10
|
+
insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "import \"@hotwired/turbo-rails\"\n", before: ACTIVE_STORAGE_REGEX
|
9
11
|
|
10
12
|
say "Remove Turbolinks"
|
11
|
-
|
12
|
-
run "bin/bundle", capture: true
|
13
|
-
run "bin/yarn remove turbolinks"
|
13
|
+
run "#{RbConfig.ruby} bin/bundle remove turbolinks"
|
14
|
+
run "#{RbConfig.ruby} bin/bundle", capture: true
|
15
|
+
run "#{RbConfig.ruby} bin/yarn remove turbolinks"
|
14
16
|
gsub_file "#{Webpacker.config.source_entry_path}/application.js", TURBOLINKS_REGEX, ''
|
15
17
|
gsub_file "#{Webpacker.config.source_entry_path}/application.js", /Turbolinks.start.*\n/, ''
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
if CABLE_CONFIG_PATH.exist?
|
20
|
+
say "Enable redis in bundle"
|
21
|
+
uncomment_lines "Gemfile", %(gem 'redis')
|
19
22
|
|
20
|
-
say "Switch development cable to use redis"
|
21
|
-
gsub_file
|
23
|
+
say "Switch development cable to use redis"
|
24
|
+
gsub_file CABLE_CONFIG_PATH.to_s, /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
25
|
+
else
|
26
|
+
say 'ActionCable config file (config/cable.yml) is missing. Uncomment "gem \'redis\'" in your Gemfile and create config/cable.yml to use the Turbo Streams broadcast feature.'
|
27
|
+
end
|
22
28
|
|
23
29
|
say "Turbo successfully installed ⚡️", :green
|
data/lib/turbo/engine.rb
CHANGED
@@ -16,13 +16,17 @@ module Turbo
|
|
16
16
|
#{root}/app/jobs
|
17
17
|
)
|
18
18
|
|
19
|
+
initializer "turbo.no_action_cable" do
|
20
|
+
Rails.autoloaders.once.do_not_eager_load(Dir["#{root}/app/channels/turbo/*_channel.rb"]) unless defined?(ActionCable)
|
21
|
+
end
|
22
|
+
|
19
23
|
initializer "turbo.assets" do
|
20
24
|
if Rails.application.config.respond_to?(:assets)
|
21
25
|
Rails.application.config.assets.precompile += %w( turbo )
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
|
-
initializer "turbo.helpers" do
|
29
|
+
initializer "turbo.helpers", before: :load_config_initializers do
|
26
30
|
ActiveSupport.on_load(:action_controller_base) do
|
27
31
|
include Turbo::Streams::TurboStreamsTagBuilder, Turbo::Frames::FrameRequest, Turbo::Native::Navigation
|
28
32
|
helper Turbo::Engine.helpers
|
@@ -7,14 +7,13 @@ module Turbo
|
|
7
7
|
delegate :dom_id, :dom_class, to: ActionView::RecordIdentifier
|
8
8
|
end
|
9
9
|
|
10
|
-
def assert_turbo_stream(action:, target: nil, &block)
|
11
|
-
assert_response
|
10
|
+
def assert_turbo_stream(action:, target: nil, status: :ok, &block)
|
11
|
+
assert_response status
|
12
12
|
assert_equal Mime[:turbo_stream], response.media_type
|
13
13
|
assert_select %(turbo-stream[action="#{action}"][target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]), count: 1, &block
|
14
14
|
end
|
15
15
|
|
16
16
|
def assert_no_turbo_stream(action:, target: nil)
|
17
|
-
assert_response :ok
|
18
17
|
assert_equal Mime[:turbo_stream], response.media_type
|
19
18
|
assert_select %(turbo-stream[action="#{action}"][target="#{target.respond_to?(:to_key) ? dom_id(target) : target}"]), count: 0
|
20
19
|
end
|
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.
|
4
|
+
version: 0.6.0
|
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-07-21 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: []
|
@@ -67,7 +67,7 @@ homepage: https://github.com/hotwired/turbo-rails
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
69
|
metadata: {}
|
70
|
-
post_install_message:
|
70
|
+
post_install_message:
|
71
71
|
rdoc_options: []
|
72
72
|
require_paths:
|
73
73
|
- lib
|
@@ -82,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
|
-
rubygems_version: 3.1.
|
86
|
-
signing_key:
|
85
|
+
rubygems_version: 3.1.4
|
86
|
+
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: The speed of a single-page web application without having to write any JavaScript.
|
89
89
|
test_files: []
|