Skip to content

Commit 53dd03d

Browse files
committed
Added instruction in Rails 3.1. install generator
1 parent 12e3ced commit 53dd03d

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed
Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,56 @@
11
require 'rails'
22

3-
module Jquery
4-
module Generators
5-
class InstallGenerator < ::Rails::Generators::Base
3+
if ::Rails.version < "3.1"
4+
module Jquery
5+
module Generators
6+
class InstallGenerator < ::Rails::Generators::Base
67

7-
desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
8-
class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
9-
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
8+
desc "This generator installs jQuery #{Jquery::Rails::JQUERY_VERSION}, jQuery-ujs, and (optionally) jQuery UI #{Jquery::Rails::JQUERY_UI_VERSION}"
9+
class_option :ui, :type => :boolean, :default => false, :desc => "Include jQueryUI"
10+
source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
1011

11-
def remove_prototype
12-
Rails::PROTOTYPE_JS.each do |name|
13-
remove_file "public/javascripts/#{name}.js"
12+
def remove_prototype
13+
Rails::PROTOTYPE_JS.each do |name|
14+
remove_file "public/javascripts/#{name}.js"
15+
end
1416
end
15-
end
1617

17-
def copy_jquery
18-
say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
19-
copy_file "jquery.js", "public/javascripts/jquery.js"
20-
copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
21-
end
18+
def copy_jquery
19+
say_status("copying", "jQuery (#{Jquery::Rails::JQUERY_VERSION})", :green)
20+
copy_file "jquery.js", "public/javascripts/jquery.js"
21+
copy_file "jquery.min.js", "public/javascripts/jquery.min.js"
22+
end
2223

23-
def copy_jquery_ui
24-
if options.ui?
25-
say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
26-
copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
27-
copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
24+
def copy_jquery_ui
25+
if options.ui?
26+
say_status("copying", "jQuery UI (#{Jquery::Rails::JQUERY_UI_VERSION})", :green)
27+
copy_file "jquery-ui.js", "public/javascripts/jquery-ui.js"
28+
copy_file "jquery-ui.min.js", "public/javascripts/jquery-ui.min.js"
29+
end
30+
end
31+
32+
def copy_ujs_driver
33+
say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
34+
remove_file "public/javascripts/rails.js"
35+
copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
2836
end
29-
end
3037

31-
def copy_ujs_driver
32-
say_status("copying", "jQuery UJS adapter (#{Jquery::Rails::JQUERY_UJS_VERSION[0..5]})", :green)
33-
remove_file "public/javascripts/rails.js"
34-
copy_file "jquery_ujs.js", "public/javascripts/jquery_ujs.js"
3538
end
39+
end
40+
end
41+
else
42+
module Jquery
43+
module Generators
44+
class InstallGenerator < ::Rails::Generators::Base
45+
desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
3646

47+
def do_nothing
48+
say_status("deprecated", "You are using Rails 3.1, so this generator is no longer needed. The necessary files are already in your asset pipeline.")
49+
say_status("", "Just add `//= require jquery` and `//= require jquery_ujs` to your app/assets/javascripts/application.js")
50+
say_status("", "If you upgraded your app from Rails 3.0 and still have jquery.js, rails.js, or jquery_ujs.js in your javascripts, be sure to remove them.")
51+
# ok, nothing
52+
end
53+
end
3754
end
3855
end
39-
end if ::Rails.version < "3.1"
56+
end

0 commit comments

Comments
 (0)