turbo-rails 0.5.9 → 0.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -14
- data/Rakefile +4 -0
- data/app/assets/javascripts/turbo.js +1230 -807
- data/app/channels/turbo/streams/broadcasts.rb +43 -21
- data/app/helpers/turbo/frames_helper.rb +4 -0
- data/app/helpers/turbo/streams/action_helper.rb +17 -5
- 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 +79 -16
- data/app/models/turbo/streams/tag_builder.rb +136 -17
- data/lib/install/turbo_needs_redis.rb +9 -0
- data/lib/install/turbo_with_importmap.rb +5 -0
- data/lib/install/turbo_with_node.rb +9 -0
- data/lib/tasks/turbo_tasks.rake +31 -8
- data/lib/turbo/engine.rb +6 -2
- data/lib/turbo/test_assertions.rb +2 -3
- data/lib/turbo/version.rb +1 -1
- metadata +6 -5
- data/lib/install/turbo_with_asset_pipeline.rb +0 -36
- data/lib/install/turbo_with_webpacker.rb +0 -23
data/lib/tasks/turbo_tasks.rake
CHANGED
@@ -1,24 +1,47 @@
|
|
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
|
40
|
+
end
|
41
|
+
|
42
|
+
desc "Switch on Redis and use it in development"
|
43
|
+
task :redis do
|
44
|
+
run_turbo_install_template "turbo_needs_redis"
|
22
45
|
end
|
23
46
|
end
|
24
47
|
end
|
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
|
-
Rails.application.config.assets.precompile += %w( turbo )
|
25
|
+
Rails.application.config.assets.precompile += %w( turbo.js )
|
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,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-
|
13
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -56,8 +56,9 @@ files:
|
|
56
56
|
- app/models/concerns/turbo/broadcastable.rb
|
57
57
|
- app/models/turbo/streams/tag_builder.rb
|
58
58
|
- config/routes.rb
|
59
|
-
- lib/install/
|
60
|
-
- lib/install/
|
59
|
+
- lib/install/turbo_needs_redis.rb
|
60
|
+
- lib/install/turbo_with_importmap.rb
|
61
|
+
- lib/install/turbo_with_node.rb
|
61
62
|
- lib/tasks/turbo_tasks.rake
|
62
63
|
- lib/turbo-rails.rb
|
63
64
|
- lib/turbo/engine.rb
|
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
requirements: []
|
85
|
-
rubygems_version: 3.1.
|
86
|
+
rubygems_version: 3.1.4
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: The speed of a single-page web application without having to write any JavaScript.
|
@@ -1,36 +0,0 @@
|
|
1
|
-
APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
|
2
|
-
IMPORTMAP_PATH = Rails.root.join("app/assets/javascripts/importmap.json.erb")
|
3
|
-
|
4
|
-
if APPLICATION_LAYOUT_PATH.exist?
|
5
|
-
say "Yield head in application layout for cache helper"
|
6
|
-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n <%= yield :head %>", before: /\s*<\/head>/
|
7
|
-
|
8
|
-
if APPLICATION_LAYOUT_PATH.read =~ /stimulus/
|
9
|
-
say "Add Turbo include tags in application layout"
|
10
|
-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n <%= javascript_include_tag "turbo", type: "module-shim" %>), after: /<%= stimulus_include_tags %>/
|
11
|
-
|
12
|
-
if IMPORTMAP_PATH.exist?
|
13
|
-
say "Add Turbo to importmap"
|
14
|
-
insert_into_file IMPORTMAP_PATH, %( "turbo": "<%= asset_path "turbo" %>",\n), after: / "imports": {\s*\n/
|
15
|
-
end
|
16
|
-
else
|
17
|
-
say "Add Turbo include tags in application layout"
|
18
|
-
insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n <%= javascript_include_tag "turbo", type: "module" %>), before: /\s*<\/head>/
|
19
|
-
end
|
20
|
-
else
|
21
|
-
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
|
28
|
-
end
|
29
|
-
|
30
|
-
say "Enable redis in bundle"
|
31
|
-
uncomment_lines "Gemfile", %(gem 'redis')
|
32
|
-
|
33
|
-
say "Switch development cable to use redis"
|
34
|
-
gsub_file "config/cable.yml", /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
35
|
-
|
36
|
-
say "Turbo successfully installed ⚡️", :green
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# Some Rails versions use commonJS(require) others use ESM(import).
|
2
|
-
TURBOLINKS_REGEX = /(import .* from "turbolinks".*\n|require\("turbolinks"\).*\n)/.freeze
|
3
|
-
|
4
|
-
abort "❌ Webpacker not found. Exiting." unless defined?(Webpacker::Engine)
|
5
|
-
|
6
|
-
say "Install Turbo"
|
7
|
-
run "yarn add @hotwired/turbo-rails"
|
8
|
-
insert_into_file "#{Webpacker.config.source_entry_path}/application.js", "import \"@hotwired/turbo-rails\"\n", before: /import.*ActiveStorage/
|
9
|
-
|
10
|
-
say "Remove Turbolinks"
|
11
|
-
gsub_file 'Gemfile', /gem 'turbolinks'.*/, ''
|
12
|
-
run "bin/bundle", capture: true
|
13
|
-
run "bin/yarn remove turbolinks"
|
14
|
-
gsub_file "#{Webpacker.config.source_entry_path}/application.js", TURBOLINKS_REGEX, ''
|
15
|
-
gsub_file "#{Webpacker.config.source_entry_path}/application.js", /Turbolinks.start.*\n/, ''
|
16
|
-
|
17
|
-
say "Enable redis in bundle"
|
18
|
-
uncomment_lines "Gemfile", %(gem 'redis')
|
19
|
-
|
20
|
-
say "Switch development cable to use redis"
|
21
|
-
gsub_file "config/cable.yml", /development:\n\s+adapter: async/, "development:\n adapter: redis\n url: redis://localhost:6379/1"
|
22
|
-
|
23
|
-
say "Turbo successfully installed ⚡️", :green
|