aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/sprockets
diff options
context:
space:
mode:
authorDaniel Schierbeck <daniel.schierbeck@gmail.com>2011-08-22 19:21:35 +0200
committerDaniel Schierbeck <daniel.schierbeck@gmail.com>2011-08-30 11:06:53 +0200
commit725617a6475703270a9afd59f1cf91ac3297720a (patch)
tree522e15b9caafd6a3e904b7d1e541dbe96e9ba719 /actionpack/lib/sprockets
parent5aa86f793f4df75f8a5780626269abc3511c61a0 (diff)
downloadrails-725617a6475703270a9afd59f1cf91ac3297720a.tar.gz
rails-725617a6475703270a9afd59f1cf91ac3297720a.tar.bz2
rails-725617a6475703270a9afd59f1cf91ac3297720a.zip
Document the Sprockets compressors
Add documentation to Sprockets::NullCompressor and Sprockets::LazyCompressor. Also, make LazyCompressor#compressor private, as it isn't part of the public API.
Diffstat (limited to 'actionpack/lib/sprockets')
-rw-r--r--actionpack/lib/sprockets/compressors.rb30
1 files changed, 23 insertions, 7 deletions
diff --git a/actionpack/lib/sprockets/compressors.rb b/actionpack/lib/sprockets/compressors.rb
index 6544953df4..351eff1085 100644
--- a/actionpack/lib/sprockets/compressors.rb
+++ b/actionpack/lib/sprockets/compressors.rb
@@ -1,21 +1,37 @@
module Sprockets
- class NullCompressor
+ # An asset compressor which does nothing.
+ #
+ # This compressor simply returns the asset as-is, without any compression
+ # whatsoever. It is useful in development mode, when compression isn't
+ # needed but using the same asset pipeline as production is desired.
+ class NullCompressor #:nodoc:
def compress(content)
content
end
end
- class LazyCompressor
+ # An asset compressor which only initializes the underlying compression
+ # engine when needed.
+ #
+ # This postpones the initialization of the compressor until
+ # <code>#compress</code> is called the first time.
+ class LazyCompressor #:nodoc:
+ # Initializes a new LazyCompressor.
+ #
+ # The block should return a compressor when called, i.e. an object
+ # which responds to <code>#compress</code>.
def initialize(&block)
@block = block
end
- def compressor
- @compressor ||= @block.call || NullCompressor.new
- end
-
def compress(content)
compressor.compress(content)
end
+
+ private
+
+ def compressor
+ @compressor ||= (@block.call || NullCompressor.new)
+ end
end
-end \ No newline at end of file
+end