turbo-rails 0.8.0 → 0.9.0
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 +1 -1
- data/app/assets/javascripts/turbo.js +281 -97
- data/app/assets/javascripts/turbo.min.js +25 -0
- data/app/assets/javascripts/turbo.min.js.map +1 -0
- data/app/channels/turbo/streams/stream_name.rb +7 -0
- data/app/channels/turbo/streams_channel.rb +30 -2
- data/app/controllers/turbo/frames/frame_request.rb +5 -1
- data/app/helpers/turbo/streams_helper.rb +7 -1
- data/app/models/concerns/turbo/broadcastable.rb +18 -1
- data/lib/install/turbo_needs_redis.rb +2 -1
- data/lib/install/turbo_with_importmap.rb +1 -1
- data/lib/turbo/engine.rb +9 -1
- data/lib/turbo/version.rb +1 -1
- metadata +9 -7
@@ -39,9 +39,15 @@ module Turbo::StreamsHelper
|
|
39
39
|
# The example above will process all turbo streams sent to a stream name like <tt>account:5:entries</tt>
|
40
40
|
# (when Current.account.id = 5). Updates to this stream can be sent like
|
41
41
|
# <tt>entry.broadcast_append_to entry.account, :entries, target: "entries"</tt>.
|
42
|
+
#
|
43
|
+
# Custom channel class name can be passed using <tt>:channel</tt> option (either as a String
|
44
|
+
# or a class name):
|
45
|
+
#
|
46
|
+
# <%= turbo_stream_from "room", channel: RoomChannel %>
|
42
47
|
def turbo_stream_from(*streamables, **attributes)
|
43
|
-
attributes[:channel] = "Turbo::StreamsChannel"
|
48
|
+
attributes[:channel] = attributes[:channel]&.to_s || "Turbo::StreamsChannel"
|
44
49
|
attributes[:"signed-stream-name"] = Turbo::StreamsChannel.signed_stream_name(streamables)
|
50
|
+
|
45
51
|
tag.turbo_cable_stream_source(**attributes)
|
46
52
|
end
|
47
53
|
end
|
@@ -26,6 +26,20 @@
|
|
26
26
|
# and finally prepend the result of that partial rendering to the target identified with the dom id "clearances"
|
27
27
|
# (which is derived by default from the plural model name of the model, but can be overwritten).
|
28
28
|
#
|
29
|
+
# You can also choose to render html instead of a partial inside of a broadcast
|
30
|
+
# you do this by passing the html: option to any broadcast method that accepts the **rendering argument
|
31
|
+
#
|
32
|
+
# class Message < ApplicationRecord
|
33
|
+
# belongs_to :user
|
34
|
+
#
|
35
|
+
# after_create_commit :update_message_count
|
36
|
+
#
|
37
|
+
# private
|
38
|
+
# def update_message_count
|
39
|
+
# broadcast_update_to(user, :messages, target: "message-count", html: "<p> #{user.messages.count} </p>")
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
#
|
29
43
|
# There are four basic actions you can broadcast: <tt>remove</tt>, <tt>replace</tt>, <tt>append</tt>, and
|
30
44
|
# <tt>prepend</tt>. As a rule, you should use the <tt>_later</tt> versions of everything except for remove when broadcasting
|
31
45
|
# within a real-time path, like a controller or model, since all those updates require a rendering step, which can slow down
|
@@ -297,7 +311,10 @@ module Turbo::Broadcastable
|
|
297
311
|
# Add the current instance into the locals with the element name (which is the un-namespaced name)
|
298
312
|
# as the key. This parallels how the ActionView::ObjectRenderer would create a local variable.
|
299
313
|
o[:locals] = (o[:locals] || {}).reverse_merge!(model_name.element.to_sym => self)
|
300
|
-
|
314
|
+
# if the html option is passed in it will skip setting a partial from #to_partial_path
|
315
|
+
unless o.include?(:html)
|
316
|
+
o[:partial] ||= to_partial_path
|
317
|
+
end
|
301
318
|
end
|
302
319
|
end
|
303
320
|
end
|
@@ -7,7 +7,8 @@ if (cable_config_path = Rails.root.join("config/cable.yml")).exist?
|
|
7
7
|
if gemfile_content.match?(pattern)
|
8
8
|
uncomment_lines "Gemfile", pattern
|
9
9
|
else
|
10
|
-
|
10
|
+
append_file "Gemfile", "\n# Use Redis for Action Cable"
|
11
|
+
gem 'redis', '~> 4.0'
|
11
12
|
end
|
12
13
|
|
13
14
|
run_bundle
|
@@ -2,4 +2,4 @@ say "Import Turbo"
|
|
2
2
|
append_to_file "app/javascript/application.js", %(import "@hotwired/turbo-rails"\n)
|
3
3
|
|
4
4
|
say "Pin Turbo"
|
5
|
-
append_to_file "config/importmap.rb", %(pin "@hotwired/turbo-rails", to: "turbo.js"\n)
|
5
|
+
append_to_file "config/importmap.rb", %(pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true\n)
|
data/lib/turbo/engine.rb
CHANGED
@@ -20,9 +20,17 @@ module Turbo
|
|
20
20
|
Rails.autoloaders.once.do_not_eager_load(Dir["#{root}/app/channels/turbo/*_channel.rb"]) unless defined?(ActionCable)
|
21
21
|
end
|
22
22
|
|
23
|
+
# If you don't want to precompile Turbo's assets (eg. because you're using webpack),
|
24
|
+
# you can do this in an intiailzer:
|
25
|
+
#
|
26
|
+
# config.after_initialize do
|
27
|
+
# config.assets.precompile -= Turbo::Engine::PRECOMPILE_ASSETS
|
28
|
+
# end
|
29
|
+
PRECOMPILE_ASSETS = %w( turbo.js turbo.min.js turbo.min.js.map )
|
30
|
+
|
23
31
|
initializer "turbo.assets" do
|
24
32
|
if Rails.application.config.respond_to?(:assets)
|
25
|
-
Rails.application.config.assets.precompile +=
|
33
|
+
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
|
26
34
|
end
|
27
35
|
end
|
28
36
|
|
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.9.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-11-24 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: []
|
@@ -36,6 +36,8 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- app/assets/javascripts/turbo.js
|
39
|
+
- app/assets/javascripts/turbo.min.js
|
40
|
+
- app/assets/javascripts/turbo.min.js.map
|
39
41
|
- app/channels/turbo/streams/broadcasts.rb
|
40
42
|
- app/channels/turbo/streams/stream_name.rb
|
41
43
|
- app/channels/turbo/streams_channel.rb
|
@@ -68,7 +70,7 @@ homepage: https://github.com/hotwired/turbo-rails
|
|
68
70
|
licenses:
|
69
71
|
- MIT
|
70
72
|
metadata: {}
|
71
|
-
post_install_message:
|
73
|
+
post_install_message:
|
72
74
|
rdoc_options: []
|
73
75
|
require_paths:
|
74
76
|
- lib
|
@@ -83,8 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
85
|
- !ruby/object:Gem::Version
|
84
86
|
version: '0'
|
85
87
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
88
|
+
rubygems_version: 3.2.22
|
89
|
+
signing_key:
|
88
90
|
specification_version: 4
|
89
91
|
summary: The speed of a single-page web application without having to write any JavaScript.
|
90
92
|
test_files: []
|