turbo-rails 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ecf40714a59522c484900685826a53c6c5396d7f4cbe02583278e657db5d999
4
- data.tar.gz: 418e450bb22bb03b92605b47f2181ba9ebdceae4e9cf4337c124cf4c6598e5fc
3
+ metadata.gz: 94c9c9d12f7b7318bb4e2eede2cb11e8c7f8ca2eb623d21d7c71c27005422f7a
4
+ data.tar.gz: e2df4c5dc7d36d4c960dfeff36318e1ed36f0b94e386ce151bda33ecf8826131
5
5
  SHA512:
6
- metadata.gz: de89fcedf66a77fc03c984ce128cf088194c13969417e978e95755b94cb8a04b852269ff39196abf2ca7d2da91738cbf4d5f06f958d150eebc2fe53c38865664
7
- data.tar.gz: 0223bc0f45e495659673f7c5bdbf03cefa8645f8a5781e372753a034007524a06828d5db37dd0eeaad99a9b6036598e983abdf453f168513f4d2237595bb009d
6
+ metadata.gz: 40dac08e7447ab44a6d6924d60e8bc8c6d5fff7f88bc8f7ba00c54f957b9559e0d0202cb5ece9165fa571c81b9edd49cd83afc0d75f274c16fb44b193ade9578
7
+ data.tar.gz: bf61cb90835e8aee3aca8c13728a91b488dae4cb903f3bede52f5991279c3587f9c3dd1eee8b04b450721d65f37d9687e69ad07a690a28d0e5d412932095ccbd
@@ -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
@@ -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: model_name.plural)
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: model_name.plural)
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
- model_name.plural
231
+ self.class.broadcast_target_default
227
232
  end
228
233
 
229
234
  def broadcast_rendering_with_defaults(options)
@@ -4,11 +4,21 @@ if APPLICATION_LAYOUT_PATH.exist?
4
4
  say "Yield head in application layout for cache helper"
5
5
  insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n <%= yield :head %>", before: /\s*<\/head>/
6
6
 
7
- say "Add Turbo include tags in application layout"
8
- insert_into_file APPLICATION_LAYOUT_PATH.to_s, "\n <%= turbo_include_tags %>", before: /\s*<\/head>/
7
+ if APPLICATION_LAYOUT_PATH.read =~ /stimulus/
8
+ say "Add Turbo include tags in application layout"
9
+ insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n <%= javascript_include_tag "turbo", type: "module-shim" %>), after: /<%= stimulus_include_tags %>/
10
+ else
11
+ say "Add Turbo include tags in application layout"
12
+ insert_into_file APPLICATION_LAYOUT_PATH.to_s, %(\n <%= javascript_include_tag "turbo", type: "module" %>), before: /\s*<\/head>/
13
+ end
9
14
  else
10
15
  say "Default application.html.erb is missing!", :red
11
- say " Add <%= turbo_include_tags %> and <%= yield :head %> within the <head> tag in your custom layout."
16
+
17
+ if APPLICATION_LAYOUT_PATH.read =~ /stimulus/
18
+ say %( Add <%= javascript_include_tag("turbo", type: "module-shim") %> and <%= yield :head %> within the <head> tag after Stimulus includes in your custom layout.)
19
+ else
20
+ say %( Add <%= javascript_include_tag("turbo", type: "module") %> and <%= yield :head %> within the <head> tag in your custom layout.)
21
+ end
12
22
  end
13
23
 
14
24
  say "Enable redis in bundle"
@@ -1,3 +1,3 @@
1
1
  module Turbo
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
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
4
+ version: 0.5.5
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 00:00:00.000000000 Z
13
+ date: 2021-01-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails