mirror of
https://github.com/rails/jquery-rails.git
synced 2026-01-10 07:07:54 -05:00
Fixing the gem so that if the rails version is 3.0.x, or if the asset pipeline is disabled (for rails >= 3.1), it will load a railtie that causes the minified version(s) of the javascript files to be included into the :defaults javascript group when the app is run in 'production' or 'test' mode. Modifying the README to be more informative as to it's functionality. Also decreasing minimum version of railties back to 3.0 since this change will support the old Rails >= 3.0.
This commit is contained in:
@@ -59,7 +59,7 @@ In order to use the themed parts of jQuery UI, you will also need to supply [you
|
||||
|
||||
This gem adds a single generator: `jquery:install`. Running the generator will remove any Prototype JS files you may happen to have, and copy jQuery and the jQuery-ujs driver for Rails (and optionally, jQuery UI) to the `public/javascripts` directory.
|
||||
|
||||
This gem will also hook into the Rails configuration process, removing Prototype and adding jQuery to the javascript files included by the `javascript_include_tag(:defaults)` call. While this gem contains the minified and un-minified versions of jQuery and jQuery UI, only the minified versions are included in `:defaults`.
|
||||
This gem will also hook into the Rails configuration process, removing Prototype and adding jQuery to the javascript files included by the `javascript_include_tag(:defaults)` call. While this gem contains the minified and un-minified versions of jQuery and jQuery UI, only the minified versions will be included in the `:defaults` when Rails is run in `production` or `test` mode (un-minified versions will be included when Rails is run in `development` mode).
|
||||
|
||||
To invoke the generator, run:
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
||||
s.required_rubygems_version = ">= 1.3.6"
|
||||
s.rubyforge_project = "jquery-rails"
|
||||
|
||||
s.add_dependency "railties", ">= 3.1.0", "< 5.0"
|
||||
s.add_dependency "railties", ">= 3.0", "< 5.0"
|
||||
s.add_dependency "thor", "~> 0.14"
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
require 'jquery/rails/engine'
|
||||
require 'jquery/assert_select' if ::Rails.env.test?
|
||||
require 'jquery/rails/engine' if ::Rails.version >= '3.1'
|
||||
require 'jquery/rails/railtie'
|
||||
require 'jquery/rails/version'
|
||||
|
||||
module Jquery
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
require "jquery/assert_select" if ::Rails.env.test?
|
||||
|
||||
module Jquery
|
||||
module Rails
|
||||
class Engine < ::Rails::Engine
|
||||
|
||||
25
lib/jquery/rails/railtie.rb
Normal file
25
lib/jquery/rails/railtie.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
# Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
|
||||
# get the minified version of the scripts included into the layout in production.
|
||||
module Jquery
|
||||
module Rails
|
||||
|
||||
class Railtie < ::Rails::Railtie
|
||||
config.before_configuration do
|
||||
|
||||
if ::Rails.root.join("public/javascripts/jquery-ui.min.js").exist?
|
||||
jq_defaults = %w(jquery jquery-ui)
|
||||
jq_defaults.map!{|a| a + ".min" } if ::Rails.env.production? || ::Rails.env.test?
|
||||
else
|
||||
jq_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.min) : %w(jquery)
|
||||
end
|
||||
|
||||
# Merge the jQuery scripts, remove the Prototype defaults and finally add 'jquery_ujs'
|
||||
# at the end, because load order is important
|
||||
config.action_view.javascript_expansions[:defaults] -= PROTOTYPE_JS + ['rails']
|
||||
config.action_view.javascript_expansions[:defaults] |= jq_defaults
|
||||
config.action_view.javascript_expansions[:defaults] << 'jquery_ujs'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user