Permalink
Browse files

Merge pull request #2636 from dasch/document-sprockets-compressors

Document the Sprockets compressors
  • Loading branch information...
2 parents 5aa86f7 + 725617a commit 9af7828d5ad780adb702292c5153f71d3a19be47 @tenderlove tenderlove committed Aug 30, 2011
Showing with 23 additions and 7 deletions.
  1. +23 −7 actionpack/lib/sprockets/compressors.rb
View
30 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
+end

0 comments on commit 9af7828

Please sign in to comment.