Skip to content

Commit

Permalink
Merge pull request rails#78 from fullbridge-batkins/master
Browse files Browse the repository at this point in the history
Make minified versions of scripts included in production mode when asset pipeline is disabled
  • Loading branch information
indirect committed Oct 1, 2012
2 parents 3630135 + 6917459 commit 7227796
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion jquery-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 3 additions & 1 deletion lib/jquery/rails.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/jquery/rails/engine.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "jquery/assert_select" if ::Rails.env.test?

module Jquery
module Rails
class Engine < ::Rails::Engine
Expand Down
25 changes: 25 additions & 0 deletions lib/jquery/rails/railtie.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7227796

Please sign in to comment.