aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/rails/generators/channel/templates
diff options
context:
space:
mode:
Diffstat (limited to 'actioncable/lib/rails/generators/channel/templates')
-rw-r--r--actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb5
-rw-r--r--actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb.tt4
-rw-r--r--actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb5
-rw-r--r--actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb.tt4
-rw-r--r--actioncable/lib/rails/generators/channel/templates/assets/channel.coffee14
-rw-r--r--actioncable/lib/rails/generators/channel/templates/channel.rb.tt (renamed from actioncable/lib/rails/generators/channel/templates/channel.rb)1
-rw-r--r--actioncable/lib/rails/generators/channel/templates/javascript/channel.js.tt20
-rw-r--r--actioncable/lib/rails/generators/channel/templates/javascript/consumer.js.tt6
-rw-r--r--actioncable/lib/rails/generators/channel/templates/javascript/index.js.tt5
9 files changed, 39 insertions, 25 deletions
diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb b/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb
deleted file mode 100644
index d56fa30f4d..0000000000
--- a/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
-module ApplicationCable
- class Channel < ActionCable::Channel::Base
- end
-end
diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb.tt b/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb.tt
new file mode 100644
index 0000000000..d672697283
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/application_cable/channel.rb.tt
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Channel < ActionCable::Channel::Base
+ end
+end
diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb b/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb
deleted file mode 100644
index b4f41389ad..0000000000
--- a/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
-module ApplicationCable
- class Connection < ActionCable::Connection::Base
- end
-end
diff --git a/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb.tt b/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb.tt
new file mode 100644
index 0000000000..0ff5442f47
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/application_cable/connection.rb.tt
@@ -0,0 +1,4 @@
+module ApplicationCable
+ class Connection < ActionCable::Connection::Base
+ end
+end
diff --git a/actioncable/lib/rails/generators/channel/templates/assets/channel.coffee b/actioncable/lib/rails/generators/channel/templates/assets/channel.coffee
deleted file mode 100644
index 5467811aba..0000000000
--- a/actioncable/lib/rails/generators/channel/templates/assets/channel.coffee
+++ /dev/null
@@ -1,14 +0,0 @@
-App.<%= class_name.underscore %> = App.cable.subscriptions.create "<%= class_name %>Channel",
- connected: ->
- # Called when the subscription is ready for use on the server
-
- disconnected: ->
- # Called when the subscription has been terminated by the server
-
- received: (data) ->
- # Called when there's incoming data on the websocket for this channel
-<% actions.each do |action| -%>
-
- <%= action %>: ->
- @perform '<%= action %>'
-<% end -%>
diff --git a/actioncable/lib/rails/generators/channel/templates/channel.rb b/actioncable/lib/rails/generators/channel/templates/channel.rb.tt
index 7bff3341c1..4bcfb2be4d 100644
--- a/actioncable/lib/rails/generators/channel/templates/channel.rb
+++ b/actioncable/lib/rails/generators/channel/templates/channel.rb.tt
@@ -1,4 +1,3 @@
-# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
<% module_namespacing do -%>
class <%= class_name %>Channel < ApplicationCable::Channel
def subscribed
diff --git a/actioncable/lib/rails/generators/channel/templates/javascript/channel.js.tt b/actioncable/lib/rails/generators/channel/templates/javascript/channel.js.tt
new file mode 100644
index 0000000000..ddf6b2d79b
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/javascript/channel.js.tt
@@ -0,0 +1,20 @@
+import consumer from "./consumer"
+
+consumer.subscriptions.create("<%= class_name %>Channel", {
+ connected() {
+ // Called when the subscription is ready for use on the server
+ },
+
+ disconnected() {
+ // Called when the subscription has been terminated by the server
+ },
+
+ received(data) {
+ // Called when there's incoming data on the websocket for this channel
+ }<%= actions.any? ? ",\n" : '' %>
+<% actions.each do |action| -%>
+ <%=action %>: function() {
+ return this.perform('<%= action %>');
+ }<%= action == actions[-1] ? '' : ",\n" %>
+<% end -%>
+});
diff --git a/actioncable/lib/rails/generators/channel/templates/javascript/consumer.js.tt b/actioncable/lib/rails/generators/channel/templates/javascript/consumer.js.tt
new file mode 100644
index 0000000000..0eceb59b18
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/javascript/consumer.js.tt
@@ -0,0 +1,6 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the `rails generate channel` command.
+
+import { createConsumer } from "@rails/actioncable"
+
+export default createConsumer()
diff --git a/actioncable/lib/rails/generators/channel/templates/javascript/index.js.tt b/actioncable/lib/rails/generators/channel/templates/javascript/index.js.tt
new file mode 100644
index 0000000000..0cfcf74919
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/javascript/index.js.tt
@@ -0,0 +1,5 @@
+// Load all the channels within this directory and all subdirectories.
+// Channel files must be named *_channel.js.
+
+const channels = require.context('.', true, /_channel\.js$/)
+channels.keys().forEach(channels)