From: Tom Hughes Date: Thu, 7 Aug 2008 17:59:27 +0000 (+0000) Subject: Import the output_compression plugin as the SVN external never works. X-Git-Tag: live~7678 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/4bc8fcf5b499a490db044fba936e01384d01d803 Import the output_compression plugin as the SVN external never works. --- diff --git a/vendor/plugins/output_compression/LICENSE b/vendor/plugins/output_compression/LICENSE new file mode 100644 index 000000000..1139144f6 --- /dev/null +++ b/vendor/plugins/output_compression/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2004-2007 Jeremy Evans + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/plugins/output_compression/README b/vendor/plugins/output_compression/README new file mode 100644 index 000000000..54030bf89 --- /dev/null +++ b/vendor/plugins/output_compression/README @@ -0,0 +1,10 @@ +OutputCompression +================= + +Allows gzip output compression to clients that support it. Simple to use, just +put after_filter :compress_output in your controller. Pulled out of the Google +cache and packaged into plugin form, code originally hosted at +http://www.tuxsoft.se/oss/rails/download/output_compression.rb. + + svn: svn://code.jeremyevans.net/rails/plugins/output_compression + file: http://code.jeremyevans.net/code/output_compression.tar.gz diff --git a/vendor/plugins/output_compression/Rakefile b/vendor/plugins/output_compression/Rakefile new file mode 100644 index 000000000..0ffac2d70 --- /dev/null +++ b/vendor/plugins/output_compression/Rakefile @@ -0,0 +1,22 @@ +require 'rake' +require 'rake/testtask' +require 'rake/rdoctask' + +desc 'Default: run unit tests.' +task :default => :test + +desc 'Test the output_compression plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end + +desc 'Generate documentation for the output_compression plugin.' +Rake::RDocTask.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'OutputCompression' + rdoc.options << '--line-numbers --inline-source' + rdoc.rdoc_files.include('README') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/vendor/plugins/output_compression/init.rb b/vendor/plugins/output_compression/init.rb new file mode 100644 index 000000000..52bdcc3f2 --- /dev/null +++ b/vendor/plugins/output_compression/init.rb @@ -0,0 +1,2 @@ +# Include hook code here +require 'output_compression' diff --git a/vendor/plugins/output_compression/lib/output_compression.rb b/vendor/plugins/output_compression/lib/output_compression.rb new file mode 100644 index 000000000..c7652ae1d --- /dev/null +++ b/vendor/plugins/output_compression/lib/output_compression.rb @@ -0,0 +1,66 @@ +# OutputCompression +# Rails output compression filters +# +# Adds two classmethods to ActionController that can be used as after-filters: +# strip_whitespace and compress_output. +# If you use page-caching, you MUST specify the compress_output filter AFTER +# caches_page, otherwise the compressed data will be cached instead of the HTML +# +# class MyController < ApplicationController +# after_filter :strip_whitespace +# caches_page :index +# after_filter :compress_output +# end + +begin + require 'zlib' + require 'stringio' + GZIP_SUPPORTED = true +rescue + GZIP_SUPPORTED = false +end + +module CompressionSystem + def compress_output + return unless accepts_gzip? + output = StringIO.new + def output.close + # Zlib does a close. Bad Zlib... + rewind + end + gz = Zlib::GzipWriter.new(output) + gz.write(response.body) + gz.close + if output.length < response.body.length + @old_response_body = response.body + response.body = output.string + response.headers['Content-encoding'] = @compression_encoding + end + end + + def accepts_gzip? + return false unless GZIP_SUPPORTED + accepts = request.env['HTTP_ACCEPT_ENCODING'] + return false unless accepts && accepts =~ /(x-gzip|gzip)/ + @compression_encoding = $1 + true + end + + def strip_whitespace + response.body.gsub!(/()|(.*?<\/script>)|()|()|\s+/m) do |m| + if m =~ /^()(.*?)<\/script>$/m + $1 + $2.strip.gsub(/\s+/, ' ').gsub('',"\n-->") + '' + elsif m =~ /^$/m + '' + elsif m =~ /^<(textarea|pre)/ + m + else ' ' + end + end + response.body.gsub! /\s+\s+/, '>' + end +end + +class ActionController::Base + include CompressionSystem +end \ No newline at end of file diff --git a/vendor/plugins/output_compression/tasks/output_compression_tasks.rake b/vendor/plugins/output_compression/tasks/output_compression_tasks.rake new file mode 100644 index 000000000..0382661bd --- /dev/null +++ b/vendor/plugins/output_compression/tasks/output_compression_tasks.rake @@ -0,0 +1,4 @@ +# desc "Explaining what the task does" +# task :output_compression do +# # Task goes here +# end \ No newline at end of file diff --git a/vendor/plugins/output_compression/test/output_compression_test.rb b/vendor/plugins/output_compression/test/output_compression_test.rb new file mode 100644 index 000000000..9b94fa187 --- /dev/null +++ b/vendor/plugins/output_compression/test/output_compression_test.rb @@ -0,0 +1,8 @@ +require 'test/unit' + +class OutputCompressionTest < Test::Unit::TestCase + # Replace this with your real tests. + def test_this_plugin + flunk + end +end