aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-07-06 21:38:54 -0300
committerJosé Valim <jose.valim@gmail.com>2011-07-06 21:41:13 -0300
commit2f6e3895a8ea2a39e43525aba91a6dbca977ef6a (patch)
tree6ff56dde61784acf20356e2336331ef82578530f /actionpack
parent86390c3bf30dd61f3bac047e0887b74ff422c02f (diff)
downloadrails-2f6e3895a8ea2a39e43525aba91a6dbca977ef6a.tar.gz
rails-2f6e3895a8ea2a39e43525aba91a6dbca977ef6a.tar.bz2
rails-2f6e3895a8ea2a39e43525aba91a6dbca977ef6a.zip
Make compressors lazily load.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/sprockets/compressors.rb21
-rw-r--r--actionpack/lib/sprockets/railtie.rb6
2 files changed, 25 insertions, 2 deletions
diff --git a/actionpack/lib/sprockets/compressors.rb b/actionpack/lib/sprockets/compressors.rb
new file mode 100644
index 0000000000..6544953df4
--- /dev/null
+++ b/actionpack/lib/sprockets/compressors.rb
@@ -0,0 +1,21 @@
+module Sprockets
+ class NullCompressor
+ def compress(content)
+ content
+ end
+ end
+
+ class LazyCompressor
+ def initialize(&block)
+ @block = block
+ end
+
+ def compressor
+ @compressor ||= @block.call || NullCompressor.new
+ end
+
+ def compress(content)
+ compressor.compress(content)
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/lib/sprockets/railtie.rb b/actionpack/lib/sprockets/railtie.rb
index d1e97c594e..970773c6a4 100644
--- a/actionpack/lib/sprockets/railtie.rb
+++ b/actionpack/lib/sprockets/railtie.rb
@@ -1,5 +1,7 @@
module Sprockets
autoload :Helpers, "sprockets/helpers"
+ autoload :LazyCompressor, "sprockets/compressors"
+ autoload :NullCompressor, "sprockets/compressors"
# TODO: Get rid of config.assets.enabled
class Railtie < ::Rails::Railtie
@@ -66,8 +68,8 @@ module Sprockets
if assets.compress
# temporarily hardcode default JS compressor to uglify. Soon, it will work
# the same as SCSS, where a default plugin sets the default.
- env.js_compressor = expand_js_compressor(assets.js_compressor || :uglifier)
- env.css_compressor = expand_css_compressor(assets.css_compressor)
+ env.js_compressor = LazyCompressor.new { expand_js_compressor(assets.js_compressor || :uglifier) }
+ env.css_compressor = LazyCompressor.new { expand_css_compressor(assets.css_compressor) }
end
env