pax_global_header00006660000000000000000000000064121203757070014516gustar00rootroot0000000000000052 comment=c7393bf7f33bca2203026df5ef2c016ddf66f719 cssmin-1.0.3/000077500000000000000000000000001212037570700130135ustar00rootroot00000000000000cssmin-1.0.3/HISTORY.md000066400000000000000000000010361212037570700144760ustar00rootroot00000000000000CSSMin History ============== ## 1.0.3 (2013-03-14) * Fixed a bug that broke media queries. [Rob] * Fixed a bug that caused the input string to be modified when modifications should only have been made to a copy. ## 1.0.2 (2008-08-23) * Fixed a bug that could have resulted in a necessary space being removed if it preceded a compressible color value, such as in the property "border:1px solid #cccccc". ## 1.0.1 (2008-07-25) * Fixed a rare bug that could result in redundant semicolons. ## 1.0.0 (2008-03-22) * First release. cssmin-1.0.3/LICENSE000066400000000000000000000027451212037570700140300ustar00rootroot00000000000000Copyright (c) 2008 Ryan Grove All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of this project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cssmin-1.0.3/Rakefile.rb000066400000000000000000000047331212037570700150710ustar00rootroot00000000000000#-- # Copyright (c) 2008 Ryan Grove # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of this project nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #++ require 'rubygems' require 'rubygems/package_task' require 'rdoc/task' require 'rake/testtask' gemspec = Gem::Specification.new do |s| s.name = 'cssmin' s.version = '1.0.3' s.author = 'Ryan Grove' s.email = 'ryan@wonko.com' s.homepage = 'https://github.com/rgrove/cssmin/' s.platform = Gem::Platform::RUBY s.summary = 'Ruby library for minifying CSS.' s.description = 'Ruby library for minifying CSS. Inspired by cssmin.js and YUI Compressor.' s.files = FileList['{lib}/**/*', 'HISTORY.md', 'LICENSE'].to_a s.require_path = 'lib' s.has_rdoc = true s.required_ruby_version = '>= 1.8.6' end Gem::PackageTask.new(gemspec) do |p| p.need_tar_gz = true end RDoc::Task.new do |rd| rd.main = 'CSSMin' rd.title = 'CSSMin' rd.rdoc_dir = 'doc' rd.rdoc_files.include('lib/**/*.rb') end Rake::TestTask.new do |t| t.libs.push 'lib' t.test_files = FileList['test/*_test.rb'] t.verbose = true end cssmin-1.0.3/lib/000077500000000000000000000000001212037570700135615ustar00rootroot00000000000000cssmin-1.0.3/lib/cssmin.rb000066400000000000000000000101521212037570700154010ustar00rootroot00000000000000#-- # Copyright (c) 2008 Ryan Grove # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # * Neither the name of this project nor the names of its contributors may be # used to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #++ # = CSSMin # # Minifies CSS using a fast, safe routine adapted from Julien Lecomte's YUI # Compressor, which was in turn adapted from Isaac Schlueter's cssmin PHP # script. # # Author:: Ryan Grove (mailto:ryan@wonko.com) # Version:: 1.0.3 (2013-03-14) # Copyright:: Copyright (c) 2008 Ryan Grove. All rights reserved. # License:: New BSD License (http://opensource.org/licenses/bsd-license.php) # Website:: http://github.com/rgrove/cssmin/ # # == Example # # require 'rubygems' # require 'cssmin' # # File.open('example.css', 'r') {|file| puts CSSMin.minify(file) } # module CSSMin # Reads CSS from +input+ (which can be a String or an IO object) and # returns a String containing minified CSS. def self.minify(input) css = input.is_a?(IO) ? input.read : input.dup.to_s # Remove comments. css.gsub!(/\/\*[\s\S]*?\*\//, '') # Compress all runs of whitespace to a single space to make things easier # to work with. css.gsub!(/\s+/, ' ') # Replace box model hacks with placeholders. css.gsub!(/"\\"\}\\""/, '___BMH___') # Remove unnecessary spaces, but be careful not to turn "p :link {...}" # into "p:link{...}". css.gsub!(/(?:^|\})[^\{:]+\s+:+[^\{]*\{/) do |match| match.gsub(':', '___PSEUDOCLASSCOLON___') end css.gsub!(/\s+([!\{\};:>+\(\)\],])/, '\1') css.gsub!('___PSEUDOCLASSCOLON___', ':') css.gsub!(/([!\{\}:;>+\(\[,])\s+/, '\1') # Add missing semicolons. css.gsub!(/([^;\}])\}/, '\1;}') # Replace 0(%, em, ex, px, in, cm, mm, pt, pc) with just 0. css.gsub!(/([\s:])([+-]?0)(?:%|em|ex|px|in|cm|mm|pt|pc)/i, '\1\2') # Replace 0 0 0 0; with 0. css.gsub!(/:(?:0 )+0;/, ':0;') # Replace background-position:0; with background-position:0 0; css.gsub!('background-position:0;', 'background-position:0 0;') # Replace 0.6 with .6, but only when preceded by : or a space. css.gsub!(/(:|\s)0+\.(\d+)/, '\1.\2') # Convert rgb color values to hex values. css.gsub!(/rgb\s*\(\s*([0-9,\s]+)\s*\)/) do |match| '#' << $1.scan(/\d+/).map{|n| n.to_i.to_s(16).rjust(2, '0') }.join end # Compress color hex values, making sure not to touch values used in IE # filters, since they would break. css.gsub!(/([^"'=\s])(\s?)\s*#([0-9a-f])\3([0-9a-f])\4([0-9a-f])\5/i, '\1\2#\3\4\5') # Remove empty rules. css.gsub!(/[^\}]+\{;\}\n/, '') # Re-insert box model hacks. css.gsub!('___BMH___', '"\"}\""') # Put the space back in for media queries css.gsub!(/\band\(/, 'and (') # Prevent redundant semicolons. css.gsub!(/;+\}/, '}') css.strip end end cssmin-1.0.3/test/000077500000000000000000000000001212037570700137725ustar00rootroot00000000000000cssmin-1.0.3/test/cssmin_test.rb000066400000000000000000000012531212037570700166530ustar00rootroot00000000000000require 'rubygems' require 'cssmin' gem 'minitest' require 'minitest/autorun' describe CSSMin do subject { CSSMin.minify(css) } describe 'stripping comments and whitespace that are not required' do let(:css) { IO.read('test/fixtures/comments.css') } let(:expected_minified_css) { IO.read('test/fixtures/comments.css.min').strip } it { subject.must_equal expected_minified_css } end describe 'preserving media queries significant whitespace' do let(:css) { IO.read('test/fixtures/media_queries.css') } let(:expected_minified_css) { IO.read('test/fixtures/media_queries.css.min').strip } it { subject.must_equal expected_minified_css } end end cssmin-1.0.3/test/fixtures/000077500000000000000000000000001212037570700156435ustar00rootroot00000000000000cssmin-1.0.3/test/fixtures/comments.css000066400000000000000000000002141212037570700201770ustar00rootroot00000000000000/***** Multi-line comment before a new class name *****/ .classname { /* comment in declaration block */ font-weight: normal; } cssmin-1.0.3/test/fixtures/comments.css.min000066400000000000000000000000371212037570700207640ustar00rootroot00000000000000.classname{font-weight:normal} cssmin-1.0.3/test/fixtures/media_queries.css000066400000000000000000000001131212037570700211640ustar00rootroot00000000000000@media screen and (-webkit-min-device-pixel-ratio:0) { some-css : here } cssmin-1.0.3/test/fixtures/media_queries.css.min000066400000000000000000000001041212037570700217460ustar00rootroot00000000000000@media screen and (-webkit-min-device-pixel-ratio:0){some-css:here}