rainpress 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +1 -0
- data/Manifest +11 -0
- data/README.rdoc +52 -0
- data/Rakefile +18 -0
- data/bin/csspress +30 -0
- data/lib/autotest/discover.rb +1 -0
- data/lib/autotest/spec.rb +60 -0
- data/lib/rainpress.rb +168 -0
- data/rainpress.gemspec +37 -0
- data/spec/build_safe.rb +20 -0
- data/spec/rainpress_spec.rb +154 -0
- metadata +89 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v1.0 Initial release
|
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
== About
|
2
|
+
|
3
|
+
Rainpress is a compressor for CSS. It's written in ruby, but should not be
|
4
|
+
limited to ruby projects.
|
5
|
+
|
6
|
+
Rainpress does not apply common compression algorithms like gzip, it removes
|
7
|
+
unnecessary characters and replaces some attributes with a shorter equivalent
|
8
|
+
name.
|
9
|
+
|
10
|
+
== Simple Usage
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'rainpress'
|
14
|
+
compressed_style_text = Rainpress.compress style_text
|
15
|
+
|
16
|
+
== License
|
17
|
+
|
18
|
+
Copyright (c) 2007-2008 Uwe L. Korn
|
19
|
+
|
20
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
21
|
+
of this software and associated documentation files (the "Software"), to deal
|
22
|
+
in the Software without restriction, including without limitation the rights
|
23
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
24
|
+
copies of the Software, and to permit persons to whom the Software is
|
25
|
+
furnished to do so, subject to the following conditions:
|
26
|
+
|
27
|
+
The above copyright notice and this permission notice shall be included in
|
28
|
+
all copies or substantial portions of the Software.
|
29
|
+
|
30
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
31
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
32
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
33
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
34
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
35
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
36
|
+
THE SOFTWARE.
|
37
|
+
|
38
|
+
Remark(not part of the license text): This is a MIT-style license
|
39
|
+
|
40
|
+
== Links
|
41
|
+
|
42
|
+
* {Rainpress Website}[http://rainpress.xhochy.com/]
|
43
|
+
* {SVN repository}[http://code.google.com/p/rainpress/source]
|
44
|
+
* {Bugtracker}[https://bugs.launchpad.net/rainpress/]
|
45
|
+
* {Wiki}[http://code.google.com/p/rainpress/w/list]
|
46
|
+
* {Translations}[https://translations.launchpad.net/rainpress/]
|
47
|
+
* {XhochY Weblog (for Announcements about Rainpress)}[http://xhochy.org/en/]
|
48
|
+
* {Mailinglist}[http://groups.google.com/group/xy-oss-projects-discussion]
|
49
|
+
* {Continous Integration Builds and Tests}[http://cruisecontrol-rb.xhochy.com/builds/rainpress]
|
50
|
+
* {Freshmeat Record}[http://freshmeat.net/projects/rainpress]
|
51
|
+
* {Ohloh listing}[http://www.ohloh.net/projects/12620/]
|
52
|
+
* {GitHub}[http://github.com/sprsquish/rainpress/tree/master]
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'echoe'
|
2
|
+
require 'hanna/rdoctask'
|
3
|
+
|
4
|
+
Echoe.new('rainpress') do |p|
|
5
|
+
p.author = ['Uwe L. Korn', 'Jeff Smick']
|
6
|
+
p.email = 'sprsquish@gmail.com'
|
7
|
+
p.url = 'http://github.com/sprsquish/rainpress/tree/master'
|
8
|
+
|
9
|
+
p.project = 'squishtech'
|
10
|
+
p.summary = 'A CSS compressor'
|
11
|
+
|
12
|
+
p.rdoc_options += %w[-S -T hanna --main README.rdoc --exclude autotest]
|
13
|
+
|
14
|
+
p.test_pattern = 'spec/*_spec.rb'
|
15
|
+
p.rcov_options = ['--exclude \/Library\/Ruby\/Gems,spec\/', '--xrefs']
|
16
|
+
|
17
|
+
p.retain_gemspec = true
|
18
|
+
end
|
data/bin/csspress
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib rainpress])
|
4
|
+
|
5
|
+
STDOUT.sync = true
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
opts = OptionParser.new do |opts|
|
12
|
+
opts.banner = <<-EOF
|
13
|
+
Usage:
|
14
|
+
csspress [options] <inputfile>
|
15
|
+
EOF
|
16
|
+
|
17
|
+
opts.on('-c', "--comments", "Keep comments") { options[:comments] = false }
|
18
|
+
|
19
|
+
opts.on('-n', "--newlines", "Keep newlines") { options[:newlines] = false }
|
20
|
+
|
21
|
+
opts.on('-s', "--spaces", "Do NOT compress spaces") { options[:spaces] = false }
|
22
|
+
|
23
|
+
opts.on('-k', "--colors", "Do NOT compress colors") { options[:colors] = false }
|
24
|
+
|
25
|
+
opts.on('-m', "--misc", "Do NOT do misc compression") { options[:misc] = false }
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.parse!
|
29
|
+
|
30
|
+
puts Rainpress.new(File.read(ARGV[0]), options).compress!
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { 'spec' if File.directory?('spec') && ENV['MINISPEC'] }
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'autotest'
|
2
|
+
|
3
|
+
Autotest.add_hook :initialize do |at|
|
4
|
+
at.clear_mappings
|
5
|
+
# watch out: Ruby bug (1.8.6):
|
6
|
+
# %r(/) != /\//
|
7
|
+
at.add_mapping(%r%^spec/.*_spec.rb$%) { |filename, _|
|
8
|
+
filename
|
9
|
+
}
|
10
|
+
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
|
11
|
+
["spec/#{m[1]}_spec.rb"]
|
12
|
+
}
|
13
|
+
at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
|
14
|
+
at.files_matching %r%^spec/.*_spec\.rb$%
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
BAR = "=" * 78
|
19
|
+
REDCODE = 31
|
20
|
+
GREENCODE = 32
|
21
|
+
|
22
|
+
Autotest.add_hook :ran_command do |at|
|
23
|
+
at.results.last =~ /^.* (\d+) failures, (\d+) errors/
|
24
|
+
|
25
|
+
code = ($1 == "0" and $2 == "0") ? GREENCODE : REDCODE
|
26
|
+
puts "\e[#{ code }m#{ BAR }\e[0m\n\n"
|
27
|
+
end
|
28
|
+
|
29
|
+
class Autotest::Spec < Autotest
|
30
|
+
def path_to_classname(s)
|
31
|
+
sep = File::SEPARATOR
|
32
|
+
f = s.sub(/spec#{sep}/, '').sub(/(spec)?\.rb$/, '').split(sep)
|
33
|
+
f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
|
34
|
+
f = f.delete_if { |path| path == 'Core' }
|
35
|
+
f.join
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Returns a hash mapping a file name to the known failures for that
|
40
|
+
# file.
|
41
|
+
|
42
|
+
def consolidate_failures(failed)
|
43
|
+
filters = new_hash_of_arrays
|
44
|
+
|
45
|
+
class_map = Hash[*self.find_order.grep(/^spec/).map { |f| # TODO: ugly
|
46
|
+
[path_to_classname(f), f]
|
47
|
+
}.flatten]
|
48
|
+
class_map.merge!(self.extra_class_map)
|
49
|
+
|
50
|
+
failed.each do |method, klass|
|
51
|
+
if class_map.has_key? klass then
|
52
|
+
filters[class_map[klass]] << method
|
53
|
+
else
|
54
|
+
output.puts "Unable to map class #{klass} to a file"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
return filters
|
59
|
+
end
|
60
|
+
end
|
data/lib/rainpress.rb
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
# == Information
|
2
|
+
#
|
3
|
+
# This is the main class of Rainpress, create an instance of it to compress
|
4
|
+
# your CSS-styles.
|
5
|
+
#
|
6
|
+
# Author:: Uwe L. Korn <uwelk@xhochy.org>
|
7
|
+
#
|
8
|
+
# <b>Options:</b>
|
9
|
+
#
|
10
|
+
# * <tt>:comments</tt> - if set to false, comments will not be removed
|
11
|
+
# * <tt>:newlines</tt> - if set to false, newlines will not be removed
|
12
|
+
# * <tt>:spaces</tt> - if set to false, spaces will not be removed
|
13
|
+
# * <tt>:colors</tt> - if set to false, colors will not be modified
|
14
|
+
# * <tt>:misc</tt> - if set to false, miscellaneous compression parts will be skipped
|
15
|
+
class Rainpress
|
16
|
+
# Quick-compress the styles.
|
17
|
+
# This eliminates the need to create an instance of the class
|
18
|
+
def self.compress(style, options = {})
|
19
|
+
self.new(style, options).compress!
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(style, opts = {})
|
23
|
+
@style = style
|
24
|
+
@opts = {
|
25
|
+
:comments => true,
|
26
|
+
:newlines => true,
|
27
|
+
:spaces => true,
|
28
|
+
:colors => true,
|
29
|
+
:misc => true
|
30
|
+
}
|
31
|
+
@opts.merge! opts
|
32
|
+
end
|
33
|
+
|
34
|
+
# Run the compressions and return the newly compressed text
|
35
|
+
def compress!
|
36
|
+
remove_comments! if @opts[:comments]
|
37
|
+
remove_newlines! if @opts[:newlines]
|
38
|
+
remove_spaces! if @opts[:spaces]
|
39
|
+
shorten_colors! if @opts[:colors]
|
40
|
+
do_misc! if @opts[:misc]
|
41
|
+
@style
|
42
|
+
end
|
43
|
+
|
44
|
+
# Remove all comments out of the CSS-Document
|
45
|
+
#
|
46
|
+
# Only /* text */ comments are supported.
|
47
|
+
# Attention: If you are doing css hacks for IE using the comment tricks,
|
48
|
+
# they will be removed using this function. Please consider for IE css style
|
49
|
+
# corrections the usage of conditionals comments in your (X)HTML document.
|
50
|
+
def remove_comments!
|
51
|
+
input = @style
|
52
|
+
@style = ''
|
53
|
+
|
54
|
+
while input.length > 0 do
|
55
|
+
pos = input.index("/*");
|
56
|
+
|
57
|
+
# No more comments
|
58
|
+
if pos == nil
|
59
|
+
@style += input
|
60
|
+
input = '';
|
61
|
+
else # Comment beginning at pos
|
62
|
+
@style += input[0..(pos-1)] if pos > 0 # only append text if there is some
|
63
|
+
input = input[(pos+2)..-1]
|
64
|
+
# Comment ending at pos
|
65
|
+
pos = input.index("*/")
|
66
|
+
input = input[(pos+2)..-1]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Remove all newline characters
|
72
|
+
#
|
73
|
+
# We take care of Windows(\r\n), Unix(\n) and Mac(\r) newlines.
|
74
|
+
def remove_newlines!
|
75
|
+
@style.gsub! /\n|\r/, ''
|
76
|
+
end
|
77
|
+
|
78
|
+
# Remove unneeded spaces
|
79
|
+
#
|
80
|
+
# 1. Turn mutiple spaces into a single
|
81
|
+
# 2. Remove spaces around ;:{},
|
82
|
+
# 3. Remove tabs
|
83
|
+
def remove_spaces!
|
84
|
+
@style.gsub! /\s*(\s|;|:|\}|\{|,)\s*/, '\1'
|
85
|
+
@style.gsub! "\t", ''
|
86
|
+
end
|
87
|
+
|
88
|
+
# Replace color values with their shorter equivalent
|
89
|
+
#
|
90
|
+
# 1. Turn rgb(,,)-colors into #-values
|
91
|
+
# 2. Shorten #AABBCC down to #ABC
|
92
|
+
# 3. Replace names with their shorter hex-equivalent
|
93
|
+
# * white -> #fff
|
94
|
+
# * black -> #000
|
95
|
+
# 4. Replace #-values with their shorter name
|
96
|
+
# * #f00 -> red
|
97
|
+
def shorten_colors!
|
98
|
+
# rgb(50,101,152) to #326598
|
99
|
+
@style.gsub! /rgb\s*\(\s*([0-9,\s]+)\s*\)/ do |match|
|
100
|
+
out = '#'
|
101
|
+
$1.split(',').each do |num|
|
102
|
+
out += '0' if num.to_i < 16
|
103
|
+
out += num.to_i.to_s(16) # convert to hex
|
104
|
+
end
|
105
|
+
out
|
106
|
+
end
|
107
|
+
# Convert #AABBCC to #ABC, keep if preceed by a '='
|
108
|
+
@style.gsub! /([^\"'=\s])(\s*)#([\da-f])\3([\da-f])\4([\da-f])\5/i, '\1#\3\4\5'
|
109
|
+
|
110
|
+
# At the moment we assume that colours only appear before ';' or '}' and
|
111
|
+
# after a ':', if there could be an occurence of a color before or after
|
112
|
+
# an other character, submit either a bug report or, better, a patch that
|
113
|
+
# enables Rainpress to take care of this.
|
114
|
+
|
115
|
+
# shorten several names to numbers
|
116
|
+
## shorten white -> #fff
|
117
|
+
@style.gsub! /:\s*white\s*(;|\})/, ':#fff\1'
|
118
|
+
|
119
|
+
## shorten black -> #000
|
120
|
+
@style.gsub! /:\s*black\s*(;|\})/, ':#000\1'
|
121
|
+
|
122
|
+
# shotern several numbers to names
|
123
|
+
## shorten #f00 or #ff0000 -> red
|
124
|
+
@style.gsub! /:\s*#f{1,2}0{2,4}(;|\})/i, ':red\1'
|
125
|
+
end
|
126
|
+
|
127
|
+
# Do miscellaneous compression methods on the style.
|
128
|
+
def do_misc!
|
129
|
+
# Replace 0(pt,px,em,%) with 0 but only when preceded by : or a white-space
|
130
|
+
@style.gsub! /([\s:]+)(0)(px|em|%|in|cm|mm|pc|pt|ex)/i, '\1\2'
|
131
|
+
|
132
|
+
# Replace :0 0 0 0(;|}) with :0(;|})
|
133
|
+
@style.gsub! /:0 0 0 0(;|\})/, ':0\1'
|
134
|
+
|
135
|
+
# Replace :0 0 0(;|}) with :0(;|})
|
136
|
+
@style.gsub! /:0 0 0(;|\})/, ':0\1'
|
137
|
+
|
138
|
+
# Replace :0 0(;|}) with :0(;|})
|
139
|
+
@style.gsub! /:0 0(;|\})/, ':0\1'
|
140
|
+
|
141
|
+
# Replace background-position:0; with background-position:0 0;
|
142
|
+
@style.gsub! 'background-position:0;', 'background-position:0 0;'
|
143
|
+
|
144
|
+
# Replace 0.6 to .6, but only when preceded by : or a white-space
|
145
|
+
@style.gsub! /[:\s]0+\.(\d+)/ do |match|
|
146
|
+
match.sub '0', '' # only first '0' !!
|
147
|
+
end
|
148
|
+
|
149
|
+
# Replace multiple ';' with a single ';'
|
150
|
+
@style.gsub! /[;]+/, ';'
|
151
|
+
|
152
|
+
# Replace ;} with }
|
153
|
+
@style.gsub! ';}', '}'
|
154
|
+
|
155
|
+
# Replace font-weight:normal; with 400
|
156
|
+
@style.gsub! /font-weight[\s]*:[\s]*normal[\s]*(;|\})/i,'font-weight:400\1'
|
157
|
+
@style.gsub! /font[\s]*:[\s]*normal[\s;\}]*/ do |match|
|
158
|
+
match.sub 'normal', '400'
|
159
|
+
end
|
160
|
+
|
161
|
+
# Replace font-weight:bold; with 700
|
162
|
+
@style.gsub! /font-weight[\s]*:[\s]*bold[\s]*(;|\})/,'font-weight:700\1'
|
163
|
+
@style.gsub! /font[\s]*:[\s]*bold[\s;\}]*/ do |match|
|
164
|
+
match.sub 'bold', '700'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
data/rainpress.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rainpress}
|
5
|
+
s.version = "1.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Uwe L. Korn, Jeff Smick"]
|
9
|
+
s.date = %q{2009-01-14}
|
10
|
+
s.default_executable = %q{csspress}
|
11
|
+
s.description = %q{A CSS compressor}
|
12
|
+
s.email = %q{sprsquish@gmail.com}
|
13
|
+
s.executables = ["csspress"]
|
14
|
+
s.extra_rdoc_files = ["bin/csspress", "CHANGELOG", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/rainpress.rb", "README.rdoc"]
|
15
|
+
s.files = ["bin/csspress", "CHANGELOG", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/rainpress.rb", "Manifest", "rainpress.gemspec", "Rakefile", "README.rdoc", "spec/build_safe.rb", "spec/rainpress_spec.rb"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://github.com/sprsquish/rainpress/tree/master}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rainpress", "--main", "README.rdoc", "-S", "-T", "hanna", "--main", "README.rdoc", "--exclude", "autotest"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{squishtech}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{A CSS compressor}
|
23
|
+
s.test_files = ["spec/rainpress_spec.rb"]
|
24
|
+
|
25
|
+
if s.respond_to? :specification_version then
|
26
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
27
|
+
s.specification_version = 2
|
28
|
+
|
29
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
30
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
33
|
+
end
|
34
|
+
else
|
35
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
36
|
+
end
|
37
|
+
end
|
data/spec/build_safe.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
if ARGV.size < 1
|
5
|
+
puts "Usage: build_save.rb my-project.gemspec"
|
6
|
+
exit
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rubygems/specification'
|
10
|
+
data = File.read(ARGV[0])
|
11
|
+
spec = nil
|
12
|
+
|
13
|
+
if data !~ %r{!ruby/object:Gem::Specification}
|
14
|
+
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
15
|
+
else
|
16
|
+
spec = YAML.load(data)
|
17
|
+
end
|
18
|
+
|
19
|
+
puts spec
|
20
|
+
puts "OK"
|
@@ -0,0 +1,154 @@
|
|
1
|
+
ENV['MINISPEC'] = 'true'
|
2
|
+
|
3
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib rainpress])
|
4
|
+
require 'rubygems'
|
5
|
+
require 'minitest/spec'
|
6
|
+
|
7
|
+
include MiniTest
|
8
|
+
|
9
|
+
Unit.autorun
|
10
|
+
|
11
|
+
describe 'Rainpress module' do
|
12
|
+
it 'removes comments' do
|
13
|
+
options = {
|
14
|
+
:comments => true,
|
15
|
+
:newlines => false,
|
16
|
+
:spaces => false,
|
17
|
+
:colors => false,
|
18
|
+
:misc => false
|
19
|
+
}
|
20
|
+
|
21
|
+
# plain comment -> ''
|
22
|
+
Rainpress.compress('/* sss */', options).must_equal ''
|
23
|
+
|
24
|
+
# no comment -> no change
|
25
|
+
Rainpress.compress('sss', options).must_equal 'sss'
|
26
|
+
|
27
|
+
# comment floating in text
|
28
|
+
Rainpress.compress('s/*ss*/ss', options).must_equal 'sss'
|
29
|
+
|
30
|
+
# multiple comments floating in text
|
31
|
+
Rainpress.compress('s/*ss*/ss/*ss*/s', options).must_equal 'ssss'
|
32
|
+
|
33
|
+
# empty string
|
34
|
+
Rainpress.compress('', options).must_equal ''
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'removes newlines' do
|
38
|
+
options = {
|
39
|
+
:comments => false,
|
40
|
+
:newlines => true,
|
41
|
+
:spaces => false,
|
42
|
+
:colors => false,
|
43
|
+
:misc => false
|
44
|
+
}
|
45
|
+
|
46
|
+
# plain unix-newline
|
47
|
+
Rainpress.compress("\n", options).must_equal ''
|
48
|
+
|
49
|
+
# plain mac newline
|
50
|
+
Rainpress.compress("\r", options).must_equal ''
|
51
|
+
|
52
|
+
# plain windows newline
|
53
|
+
Rainpress.compress("\r\n", options).must_equal ''
|
54
|
+
|
55
|
+
# no newline
|
56
|
+
Rainpress.compress('rn', options).must_equal 'rn'
|
57
|
+
|
58
|
+
# newlines floatin in text
|
59
|
+
Rainpress.compress("sss\n||\r\nsss", options).must_equal 'sss||sss'
|
60
|
+
|
61
|
+
# empty string
|
62
|
+
Rainpress.compress('', options).must_equal ''
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'removes spaces' do
|
66
|
+
options = {
|
67
|
+
:comments => false,
|
68
|
+
:newlines => false,
|
69
|
+
:spaces => true,
|
70
|
+
:colors => false,
|
71
|
+
:misc => false
|
72
|
+
}
|
73
|
+
|
74
|
+
# (a) Turn mutiple Spaces into a single, but not less
|
75
|
+
Rainpress.compress(' ', options).must_equal ' ' # 2 spaces
|
76
|
+
Rainpress.compress(' ', options).must_equal ' ' # 3 spaces
|
77
|
+
|
78
|
+
# (b) remove spaces around ;:{},
|
79
|
+
Rainpress.compress(' ; ', options).must_equal ';'
|
80
|
+
Rainpress.compress(' : ', options).must_equal ':'
|
81
|
+
Rainpress.compress(' { ', options).must_equal '{'
|
82
|
+
Rainpress.compress(' } ', options).must_equal '}'
|
83
|
+
Rainpress.compress(',', options).must_equal ','
|
84
|
+
|
85
|
+
# (c) remove tabs
|
86
|
+
Rainpress.compress("\t", options).must_equal ''
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'shortens colors' do
|
90
|
+
options = {
|
91
|
+
:comments => false,
|
92
|
+
:newlines => false,
|
93
|
+
:spaces => false,
|
94
|
+
:colors => true,
|
95
|
+
:misc => false
|
96
|
+
}
|
97
|
+
# rgb(50,101,152) to #326598
|
98
|
+
Rainpress.compress('color:rgb(12,101,152)', options).must_equal 'color:#0c6598'
|
99
|
+
|
100
|
+
# #AABBCC to #ABC
|
101
|
+
Rainpress.compress('color:#AAbBCC', options).must_equal 'color:#AbC'
|
102
|
+
|
103
|
+
# Keep chroma(color="#FFFFFF"); ... due to IE
|
104
|
+
Rainpress.compress('chroma(color="#FFFFFF");', options).must_equal 'chroma(color="#FFFFFF");'
|
105
|
+
|
106
|
+
# shorten several names to numbers
|
107
|
+
Rainpress.compress('color:white;', options).must_equal 'color:#fff;'
|
108
|
+
Rainpress.compress('color: white}', options).must_equal 'color:#fff}'
|
109
|
+
|
110
|
+
# shotern several numbers to names
|
111
|
+
Rainpress.compress('color:#ff0000;', options).must_equal 'color:red;'
|
112
|
+
Rainpress.compress('color:#F00;', options).must_equal 'color:red;'
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'does misc' do
|
116
|
+
options = {
|
117
|
+
:comments => false,
|
118
|
+
:newlines => false,
|
119
|
+
:spaces => false,
|
120
|
+
:colors => false,
|
121
|
+
:misc => true
|
122
|
+
}
|
123
|
+
# Replace 0(pt,px,em,%) with 0
|
124
|
+
%w[px em pt % in cm mm pc ex].each { |x| Rainpress.compress(" 0#{x}", options).must_equal ' 0' }
|
125
|
+
Rainpress.compress(':0mm', options).must_equal ':0'
|
126
|
+
Rainpress.compress(' 0ex', options).must_equal ' 0'
|
127
|
+
Rainpress.compress(' 10ex', options).must_equal ' 10ex'
|
128
|
+
|
129
|
+
# Replace 0 0 0 0; with 0.
|
130
|
+
Rainpress.compress(':0 0;', options).must_equal ':0;'
|
131
|
+
Rainpress.compress(':0 0 0;', options).must_equal ':0;'
|
132
|
+
Rainpress.compress(':0 0 0 0;', options).must_equal ':0;'
|
133
|
+
Rainpress.compress(':0 0 0 0}', options).must_equal ':0}'
|
134
|
+
|
135
|
+
# Keep 'background-position:0 0;' !!
|
136
|
+
Rainpress.compress('background-position:0 0;', options).must_equal 'background-position:0 0;'
|
137
|
+
|
138
|
+
# Replace 0.6 to .6, but only when preceded by : or a white-space
|
139
|
+
Rainpress.compress(' 0.6', options).must_equal ' .6'
|
140
|
+
Rainpress.compress(':0.06', options).must_equal ':.06'
|
141
|
+
Rainpress.compress('10.6', options).must_equal '10.6'
|
142
|
+
|
143
|
+
# Replace ;;;; with ;
|
144
|
+
Rainpress.compress('ss;;;ss', options).must_equal 'ss;ss'
|
145
|
+
|
146
|
+
# Replace ;} with }
|
147
|
+
Rainpress.compress('ss;sss;}ss', options).must_equal 'ss;sss}ss'
|
148
|
+
|
149
|
+
# Replace font-weight:normal; with 400, bold with 700
|
150
|
+
Rainpress.compress('font-weight: normal;', options).must_equal 'font-weight:400;'
|
151
|
+
Rainpress.compress('font: normal;', options).must_equal 'font: 400;'
|
152
|
+
Rainpress.compress('font: bold 1px;', options).must_equal 'font: 700 1px;'
|
153
|
+
end
|
154
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rainpress
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "1.0"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Uwe L. Korn, Jeff Smick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-14 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: echoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description: A CSS compressor
|
26
|
+
email: sprsquish@gmail.com
|
27
|
+
executables:
|
28
|
+
- csspress
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- bin/csspress
|
33
|
+
- CHANGELOG
|
34
|
+
- lib/autotest/discover.rb
|
35
|
+
- lib/autotest/spec.rb
|
36
|
+
- lib/rainpress.rb
|
37
|
+
- README.rdoc
|
38
|
+
files:
|
39
|
+
- bin/csspress
|
40
|
+
- CHANGELOG
|
41
|
+
- lib/autotest/discover.rb
|
42
|
+
- lib/autotest/spec.rb
|
43
|
+
- lib/rainpress.rb
|
44
|
+
- Manifest
|
45
|
+
- rainpress.gemspec
|
46
|
+
- Rakefile
|
47
|
+
- README.rdoc
|
48
|
+
- spec/build_safe.rb
|
49
|
+
- spec/rainpress_spec.rb
|
50
|
+
has_rdoc: true
|
51
|
+
homepage: http://github.com/sprsquish/rainpress/tree/master
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options:
|
54
|
+
- --line-numbers
|
55
|
+
- --inline-source
|
56
|
+
- --title
|
57
|
+
- Rainpress
|
58
|
+
- --main
|
59
|
+
- README.rdoc
|
60
|
+
- -S
|
61
|
+
- -T
|
62
|
+
- hanna
|
63
|
+
- --main
|
64
|
+
- README.rdoc
|
65
|
+
- --exclude
|
66
|
+
- autotest
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "1.2"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: squishtech
|
84
|
+
rubygems_version: 1.3.1
|
85
|
+
signing_key:
|
86
|
+
specification_version: 2
|
87
|
+
summary: A CSS compressor
|
88
|
+
test_files:
|
89
|
+
- spec/rainpress_spec.rb
|