Sha256: 5d0dc244303bacfa715d4926e3770e487705609a11b11fd94a60925dbeb942b2
Contents?: true
Size: 1.46 KB
Versions: 9
Compression:
Stored size: 1.46 KB
Contents
module Hanami module Assets class Bundler # Compresses a JS or CSS file # # @since 0.3.0 # @api private class Compressor # @since 0.3.0 # @api private JAVASCRIPT_EXT = '.js'.freeze # @since 0.3.0 # @api private STYLESHEET_EXT = '.css'.freeze # Return a new instance # # @since 0.3.0 # @api private def initialize(path, configuration) @path = path @configuration = configuration end # @return [String, nil] the compressed contents of the file OR nil if it's not compressable # # @since 0.3.0 # @api private def compress case File.extname(@path) when JAVASCRIPT_EXT then _compress(compressor(:js)) when STYLESHEET_EXT then _compress(compressor(:css)) end end private # @since 0.3.0 # @api private def compressor(type) @configuration.__send__(:"#{ type }_compressor") end # @since 0.3.0 # @api private def _compress(compressor) compressor.compress(@path) rescue => e # rubocop:disable Style/RescueStandardError warn( [ "Skipping compression of: `#{@path}'", "Reason: #{e}\n", "\t#{e.backtrace.join("\n\t")}\n\n" ].join("\n") ) end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems