From 861e7d43e320dec770d353b9aeba625ff7573fda Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sun, 28 Feb 2016 08:03:05 +0900 Subject: [PATCH] convert cable.coffee to cable.js In order to eliminate the dependecy of CoffeeScript. --- actioncable/lib/rails/generators/channel/USAGE | 2 +- .../lib/rails/generators/rails/app/app_generator.rb | 2 +- .../templates/app/assets/javascripts/cable.coffee | 9 --------- .../app/templates/app/assets/javascripts/cable.js | 13 +++++++++++++ railties/test/application/rake_test.rb | 2 +- railties/test/generators/app_generator_test.rb | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee create mode 100644 railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js diff --git a/actioncable/lib/rails/generators/channel/USAGE b/actioncable/lib/rails/generators/channel/USAGE index 27a934c689..6249553c22 100644 --- a/actioncable/lib/rails/generators/channel/USAGE +++ b/actioncable/lib/rails/generators/channel/USAGE @@ -3,7 +3,7 @@ Description: Stubs out a new cable channel for the server (in Ruby) and client (in CoffeeScript). Pass the channel name, either CamelCased or under_scored, and an optional list of channel actions as arguments. - Note: Turn on the cable connection in app/assets/javascript/cable.coffee after generating any channels. + Note: Turn on the cable connection in app/assets/javascript/cable.js after generating any channels. Example: ======== diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 7bab3fdf74..4542808306 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -332,7 +332,7 @@ module Rails def delete_action_cable_files_skipping_action_cable if options[:skip_action_cable] remove_file 'config/cable.yml' - remove_file 'app/assets/javascripts/cable.coffee' + remove_file 'app/assets/javascripts/cable.js' remove_dir 'app/channels' end end diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee deleted file mode 100644 index af08f58e34..0000000000 --- a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.coffee +++ /dev/null @@ -1,9 +0,0 @@ -# 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. -# -#= require action_cable -#= require_self -#= require_tree ./channels - -@App ||= {} -App.cable = ActionCable.createConsumer() diff --git a/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js new file mode 100644 index 0000000000..71ee1e66de --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js @@ -0,0 +1,13 @@ +// 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. +// +//= require action_cable +//= require_self +//= require_tree ./channels + +(function() { + this.App || (this.App = {}); + + App.cable = ActionCable.createConsumer(); + +}).call(this); diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index 92ae3edc08..dc3c4755c7 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -118,7 +118,7 @@ module ApplicationTests end def test_code_statistics_sanity - assert_match "Code LOC: 16 Test LOC: 0 Code to Test Ratio: 1:0.0", + assert_match "Code LOC: 18 Test LOC: 0 Code to Test Ratio: 1:0.0", Dir.chdir(app_path){ `bin/rails stats` } end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 63655044da..35be6ce03a 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -463,7 +463,7 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-action-cable"] assert_file "config/application.rb", /#\s+require\s+["']action_cable\/engine["']/ assert_no_file "config/cable.yml" - assert_no_file "app/assets/javascripts/cable.coffee" + assert_no_file "app/assets/javascripts/cable.js" assert_no_file "app/channels" assert_file "Gemfile" do |content| assert_no_match(/redis/, content)