lib/sprockets/encoding_utils.rb in sprockets-3.0.0.beta.6 vs lib/sprockets/encoding_utils.rb in sprockets-3.0.0.beta.7

- old
+ new

@@ -1,10 +1,12 @@ require 'base64' require 'stringio' require 'zlib' module Sprockets + # Internal: HTTP transport encoding and charset detecting related functions. + # Mixed into Environment. module EncodingUtils extend self ## Binary encodings ## @@ -22,13 +24,10 @@ ) deflater << str deflater.finish end - # Public: Alias for CodingUtils.deflate - DEFLATE = method(:deflate) - # Internal: Unmarshal optionally deflated data. # # Checks leading marshal header to see if the bytes are uncompressed # otherwise inflate the data an unmarshal. # @@ -63,28 +62,25 @@ gz << str gz.finish io.string end - # Public: Alias for CodingUtils.gzip - GZIP = method(:gzip) - # Public: Use base64 to encode data. # # str - String data # # Returns a encoded String def base64(str) Base64.strict_encode64(str) end - # Public: Alias for CodingUtils.base64 - BASE64 = method(:base64) - ## Charset encodings ## + # Internal: Shorthand aliases for detecter functions. + CHARSET_DETECT = {} + # Internal: Mapping unicode encodings to byte order markers. BOM = { Encoding::UTF_32LE => [0xFF, 0xFE, 0x00, 0x00], Encoding::UTF_32BE => [0x00, 0x00, 0xFE, 0xFF], Encoding::UTF_8 => [0xEF, 0xBB, 0xBF], @@ -113,14 +109,12 @@ str.force_encoding(Encoding.default_external) end str end + CHARSET_DETECT[:default] = method(:detect) - # Public: Alias for EncodingUtils.detect_unicode - DETECT = method(:detect) - # Internal: Use Charlock Holmes to detect encoding. # # To enable this code path, require 'charlock_holmes' # # Returns encoded String. @@ -149,14 +143,12 @@ str.force_encoding(Encoding::UTF_8) end str end + CHARSET_DETECT[:unicode] = method(:detect_unicode) - # Public: Alias for EncodingUtils.detect_unicode - DETECT_UNICODE = method(:detect_unicode) - # Public: Detect and strip BOM from possible unicode string. # # str - ASCII-8BIT encoded String # # Returns UTF 8/16/32 encoded String without BOM or the original String if @@ -199,14 +191,12 @@ str.force_encoding(Encoding::UTF_8) end str end + CHARSET_DETECT[:css] = method(:detect_css) - # Public: Alias for EncodingUtils.detect_css - DETECT_CSS = method(:detect_css) - # Internal: @charset bytes CHARSET_START = [0x40, 0x63, 0x68, 0x61, 0x72, 0x73, 0x65, 0x74, 0x20, 0x22] CHARSET_SIZE = CHARSET_START.size # Internal: Scan binary CSS string for @charset encoding name. @@ -261,10 +251,8 @@ str.force_encoding(Encoding::ISO_8859_1) end str end - - # Public: Alias for EncodingUtils.detect_html - DETECT_HTML = method(:detect_html) + CHARSET_DETECT[:html] = method(:detect_html) end end