turbo-rails 0.5.4 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/turbo.js +660 -585
- data/app/helpers/turbo/includes_helper.rb +2 -0
- data/app/helpers/turbo/streams/action_helper.rb +2 -7
- data/app/models/concerns/turbo/broadcastable.rb +8 -3
- data/app/models/turbo/streams/tag_builder.rb +3 -2
- data/lib/install/turbo_with_asset_pipeline.rb +19 -3
- data/lib/tasks/turbo_tasks.rake +3 -3
- data/lib/turbo/version.rb +1 -1
- metadata +2 -2
@@ -1,4 +1,6 @@
|
|
1
1
|
module Turbo::IncludesHelper
|
2
|
+
# DEPRECATED: Just use <tt>javascript_include_tag "turbo", type: "module"</tt> directly if using Turbo alone, or
|
3
|
+
# javascript_include_tag "turbo", type: "module-shim" if together with Stimulus and importmaps.
|
2
4
|
def turbo_include_tags
|
3
5
|
javascript_include_tag("turbo", type: "module")
|
4
6
|
end
|
@@ -14,12 +14,7 @@ module Turbo::Streams::ActionHelper
|
|
14
14
|
end
|
15
15
|
|
16
16
|
private
|
17
|
-
def convert_to_turbo_stream_dom_id(
|
18
|
-
|
19
|
-
element = element_or_dom_id
|
20
|
-
ActionView::RecordIdentifier.dom_id(element)
|
21
|
-
else
|
22
|
-
dom_id = element_or_dom_id
|
23
|
-
end
|
17
|
+
def convert_to_turbo_stream_dom_id(target)
|
18
|
+
target.respond_to?(:to_key) ? ActionView::RecordIdentifier.dom_id(target) : target
|
24
19
|
end
|
25
20
|
end
|
@@ -51,18 +51,23 @@ module Turbo::Broadcastable
|
|
51
51
|
# belongs_to :board
|
52
52
|
# broadcasts_to ->(message) { [ message.board, :messages ] }, inserts_by: :prepend, target: "board_messages"
|
53
53
|
# end
|
54
|
-
def broadcasts_to(stream, inserts_by: :append, target:
|
54
|
+
def broadcasts_to(stream, inserts_by: :append, target: broadcast_target_default)
|
55
55
|
after_create_commit -> { broadcast_action_later_to stream.try(:call, self) || send(stream), action: inserts_by, target: target }
|
56
56
|
after_update_commit -> { broadcast_replace_later_to stream.try(:call, self) || send(stream) }
|
57
57
|
after_destroy_commit -> { broadcast_remove_to stream.try(:call, self) || send(stream) }
|
58
58
|
end
|
59
59
|
|
60
60
|
# Same as <tt>#broadcasts_to</tt>, but the designated stream is automatically set to the current model.
|
61
|
-
def broadcasts(inserts_by: :append, target:
|
61
|
+
def broadcasts(inserts_by: :append, target: broadcast_target_default)
|
62
62
|
after_create_commit -> { broadcast_action_later action: inserts_by, target: target }
|
63
63
|
after_update_commit -> { broadcast_replace_later }
|
64
64
|
after_destroy_commit -> { broadcast_remove }
|
65
65
|
end
|
66
|
+
|
67
|
+
# All default targets will use the return of this method. Overwrite if you want something else than <tt>model_name.plural</tt>.
|
68
|
+
def broadcast_target_default
|
69
|
+
model_name.plural
|
70
|
+
end
|
66
71
|
end
|
67
72
|
|
68
73
|
# Remove this broadcastable model from the dom for subscribers of the stream name identified by the passed streamables.
|
@@ -223,7 +228,7 @@ module Turbo::Broadcastable
|
|
223
228
|
|
224
229
|
private
|
225
230
|
def broadcast_target_default
|
226
|
-
|
231
|
+
self.class.broadcast_target_default
|
227
232
|
end
|
228
233
|
|
229
234
|
def broadcast_rendering_with_defaults(options)
|
@@ -14,7 +14,7 @@
|
|
14
14
|
# <%= turbo_stream.append "entries" do %>
|
15
15
|
# <% # format is automatically switched, such that _entry.html.erb partial is rendered, not _entry.turbo_stream.erb %>
|
16
16
|
# <%= render partial: "entries/entry", locals: { entry: entry } %>
|
17
|
-
#
|
17
|
+
# <% end %>
|
18
18
|
#
|
19
19
|
# Or you can render the HTML that should be part of the update inline:
|
20
20
|
#
|
@@ -27,6 +27,7 @@ class Turbo::Streams::TagBuilder
|
|
27
27
|
|
28
28
|
def initialize(view_context)
|
29
29
|
@view_context = view_context
|
30
|
+
@view_context.formats |= [:html]
|
30
31
|
end
|
31
32
|
|
32
33
|
# Removes the <tt>target</tt> from the dom. The target can either be a dom id string or an object that responds to
|
@@ -121,7 +122,7 @@ class Turbo::Streams::TagBuilder
|
|
121
122
|
def render_record(possible_record)
|
122
123
|
if possible_record.respond_to?(:to_partial_path)
|
123
124
|
record = possible_record
|
124
|
-
@view_context.render(partial: record
|
125
|
+
@view_context.render(partial: record, formats: :html)
|
125
126
|
end
|
126
127
|
end
|
127
128
|
end
|
@@ -1,14 +1,30 @@
|
|
1
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")
|
2
3
|
|
3
4
|
if APPLICATION_LAYOUT_PATH.exist?
|
4
5
|
say "Yield head in application layout for cache helper"
|
5
6
|
insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n <%= yield :head %>", before: /\s*<\/head>/
|
6
7
|
|
7
|
-
|
8
|
-
|
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
|
9
20
|
else
|
10
21
|
say "Default application.html.erb is missing!", :red
|
11
|
-
|
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
|
12
28
|
end
|
13
29
|
|
14
30
|
say "Enable redis in bundle"
|
data/lib/tasks/turbo_tasks.rake
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
def
|
1
|
+
def run_turbo_install_template(path) system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}" end
|
2
2
|
|
3
3
|
namespace :turbo do
|
4
4
|
desc "Install Turbo into the app"
|
@@ -13,12 +13,12 @@ namespace :turbo do
|
|
13
13
|
namespace :install do
|
14
14
|
desc "Install Turbo into the app with asset pipeline"
|
15
15
|
task :asset_pipeline do
|
16
|
-
|
16
|
+
run_turbo_install_template "turbo_with_asset_pipeline"
|
17
17
|
end
|
18
18
|
|
19
19
|
desc "Install Turbo into the app with webpacker"
|
20
20
|
task :webpacker do
|
21
|
-
|
21
|
+
run_turbo_install_template "turbo_with_webpacker"
|
22
22
|
end
|
23
23
|
end
|
24
24
|
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.5.
|
4
|
+
version: 0.5.9
|
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-01-
|
13
|
+
date: 2021-01-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|