aboutsummaryrefslogtreecommitdiffstats
path: root/actioncable/lib/rails/generators/channel
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2016-05-21 08:52:43 -0300
committerRafael França <rafaelmfranca@gmail.com>2016-05-21 08:52:43 -0300
commitdb312a9fb04097e7d584d24dd446aac7dea7e11f (patch)
treeeba6c8973aa6046188b2c38e7ac811d833501138 /actioncable/lib/rails/generators/channel
parent7087ff99071cd29f1d07e5298dbc204bede6ca86 (diff)
parent63ac6255ba3553b529f4b23846ec756b7a7a746d (diff)
downloadrails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.gz
rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.tar.bz2
rails-db312a9fb04097e7d584d24dd446aac7dea7e11f.zip
Merge pull request #24918 from prathamesh-sonpatki/cable-assets
Cable: Generate .js or .coffee files while generating channel as per the javascript engine of the application
Diffstat (limited to 'actioncable/lib/rails/generators/channel')
-rw-r--r--actioncable/lib/rails/generators/channel/channel_generator.rb3
-rw-r--r--actioncable/lib/rails/generators/channel/templates/assets/channel.js18
2 files changed, 20 insertions, 1 deletions
diff --git a/actioncable/lib/rails/generators/channel/channel_generator.rb b/actioncable/lib/rails/generators/channel/channel_generator.rb
index 05fd21a954..47232252e3 100644
--- a/actioncable/lib/rails/generators/channel/channel_generator.rb
+++ b/actioncable/lib/rails/generators/channel/channel_generator.rb
@@ -16,7 +16,8 @@ module Rails
if self.behavior == :invoke
template "assets/cable.js", "app/assets/javascripts/cable.js"
end
- template "assets/channel.coffee", File.join('app/assets/javascripts/channels', class_path, "#{file_name}.coffee")
+
+ js_template "assets/channel", File.join('app/assets/javascripts/channels', class_path, "#{file_name}")
end
generate_application_cable_files
diff --git a/actioncable/lib/rails/generators/channel/templates/assets/channel.js b/actioncable/lib/rails/generators/channel/templates/assets/channel.js
new file mode 100644
index 0000000000..ab0e68b11a
--- /dev/null
+++ b/actioncable/lib/rails/generators/channel/templates/assets/channel.js
@@ -0,0 +1,18 @@
+App.<%= class_name.underscore %> = App.cable.subscriptions.create("<%= class_name %>Channel", {
+ connected: function() {
+ // Called when the subscription is ready for use on the server
+ },
+
+ disconnected: function() {
+ // Called when the subscription has been terminated by the server
+ },
+
+ received: function(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 -%>
+});