recipes/jquery.rb in rails3_devise_wizard-0.2.8 vs recipes/jquery.rb in rails3_devise_wizard-0.3.1
- old
+ new
@@ -1,44 +1,60 @@
# Application template recipe for the rails3_devise_wizard. Check for a newer version here:
# https://github.com/fortuity/rails3_devise_wizard/blob/master/recipes/jquery.rb
if config['jquery']
- say_wizard "REMINDER: When creating a Rails app using jQuery..."
- say_wizard "you should add the '-J' flag to 'rails new'"
- after_bundler do
- say_wizard "jQuery recipe running 'after bundler'"
- # remove the Prototype adapter file
- remove_file 'public/javascripts/rails.js'
- # remove the Prototype files (if they exist)
- remove_file 'public/javascripts/controls.js'
- remove_file 'public/javascripts/dragdrop.js'
- remove_file 'public/javascripts/effects.js'
- remove_file 'public/javascripts/prototype.js'
- # add jQuery files
- inside "public/javascripts" do
- get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "rails.js"
- get "http://code.jquery.com/jquery-1.6.min.js", "jquery.js"
+ if recipes.include? 'rails 3.0'
+ say_wizard "Replacing Prototype framework with jQuery for Rails 3.0."
+ after_bundler do
+ say_wizard "jQuery recipe running 'after bundler'"
+ # remove the Prototype adapter file
+ remove_file 'public/javascripts/rails.js'
+ # remove the Prototype files (if they exist)
+ remove_file 'public/javascripts/controls.js'
+ remove_file 'public/javascripts/dragdrop.js'
+ remove_file 'public/javascripts/effects.js'
+ remove_file 'public/javascripts/prototype.js'
+ # add jQuery files
+ inside "public/javascripts" do
+ get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "rails.js"
+ get "http://code.jquery.com/jquery-1.6.min.js", "jquery.js"
+ if config['ui']
+ get "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js", "jqueryui.js"
+ end
+ end
+ # adjust the Javascript defaults
+ # first uncomment "config.action_view.javascript_expansions"
+ gsub_file "config/application.rb", /# config.action_view.javascript_expansions/, "config.action_view.javascript_expansions"
+ # then add "jquery rails" if necessary
+ gsub_file "config/application.rb", /= \%w\(\)/, "%w(jquery rails)"
+ # finally change to "jquery jqueryui rails" if necessary
if config['ui']
- get "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js", "jqueryui.js"
+ gsub_file "config/application.rb", /jquery rails/, "jquery jqueryui rails"
end
end
- # adjust the Javascript defaults
+ elsif recipes.include? 'rails 3.1'
if config['ui']
- inject_into_file 'config/application.rb', "config.action_view.javascript_expansions[:defaults] = %w(jquery jqueryui rails)\n", :after => "config.action_view.javascript_expansions[:defaults] = %w()\n", :verbose => false
+ inside "app/assets/javascripts" do
+ get "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js", "jqueryui.js"
+ end
else
- inject_into_file 'config/application.rb', "config.action_view.javascript_expansions[:defaults] = %w(jquery rails)\n", :after => "config.action_view.javascript_expansions[:defaults] = %w()\n", :verbose => false
- end
- gsub_file "config/application.rb", /config.action_view.javascript_expansions\[:defaults\] = \%w\(\)\n/, ""
+ say_wizard "jQuery installed by default in Rails 3.1."
+ end
+ else
+ say_wizard "Don't know what to do for Rails version #{Rails::VERSION::STRING}. jQuery recipe skipped."
end
else
+ if config['ui']
+ say_wizard "You said you didn't want jQuery. Can't install jQuery UI without jQuery."
+ end
recipes.delete('jquery')
end
__END__
name: jQuery
-description: "Use jQuery instead of Prototype."
+description: "Install jQuery (with jQuery UI option) for Rails 3.0 or 3.1."
author: fortuity
exclusive: javascript_framework
category: assets
tags: [javascript, framework]
@@ -46,9 +62,9 @@
args: ["-J"]
config:
- jquery:
type: boolean
- prompt: Would you like to use jQuery instead of Prototype?
+ prompt: Would you like to use jQuery?
- ui:
type: boolean
prompt: Would you like to use jQuery UI?