# File lib/padrino-contrib/helpers/assets_compressor.rb, line 71
          def assets_compressor(kind, sources)
            options = sources.extract_options!.symbolize_keys
            bundle  = options.delete(:cache)
            return sources if bundle.nil?

            began_at = Time.now
            asset_folder = case kind
              when :css then 'stylesheets'
              when :js  then 'javascripts'
              else raise "YUI Compressor didn't support yet #{kind} compression"
            end

            bundle  = settings.app_name.downcase if bundle.is_a?(TrueClass)
            path    = Padrino.root("public", uri_root_path(asset_folder, bundle.to_s))

            # Detect changes
            stamps = sources.inject(0) do |memo, source|
              asset_path_without_compression(kind, source) =~ /\?(\d{10})$/
              memo += $1.to_i
              memo
            end

            bundle  = "#{bundle}.#{stamps}" if stamps > 0
            path    = Padrino.root("public", uri_root_path(asset_folder, bundle.to_s))
            path   += ".#{kind}" unless path =~ /\.#{kind}/

            # Back if no changes happens
            return bundle if File.exist?(path)

            # Clean old cached files
            Dir[path.gsub(/\.\d{10}\.#{kind}/, "*")].each { |file| FileUtils.rm_f(file) }

            # Get source code
            errors = []
            code = sources.map do |source|
              source = asset_path(kind, source).sub(/\?\d{10}$/, '') # Removes Timestamp
              begin
                source = source =~ /^http/ ? open(source) : File.read(Padrino.root("public", source))
              rescue Exception => e
                logger.error e.message
                errors << source
                next
              end
              # Removes extra comments
              if cs = source =~ /\/\*\!/
                cr = source.slice(cs, source.length)
                ce = cr =~ /\*\//
                cr = source.slice(cs, ce+2)
                source.sub!(cr,'')
              end
              source.each_line.reject { |l| l.strip == "" }.join
            end

            # Write the new bundled file
            Dir.mkdir(File.dirname(path)) unless File.exist?(File.dirname(path))
            File.open(path, "w") { |f| f.write(settings.compressor[kind].compress(code.join("\n"))) }
            logger.debug "Compressed (%0.2fms) %s" % [Time.now-began_at, path] if defined?(logger)

            # Return the updated bundle
            errors.unshift bundle
          end