deadweight 0.1.1 → 0.1.2

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.
Files changed (31) hide show
  1. data/README.rdoc +17 -5
  2. data/Rakefile +0 -1
  3. data/VERSION +1 -1
  4. data/deadweight.gemspec +29 -9
  5. data/lib/deadweight.rb +51 -15
  6. data/lib/deadweight/cli.rb +8 -2
  7. data/test/cli_test.rb +9 -6
  8. data/test/test_helper.rb +2 -2
  9. data/vendor/gems/css_parser-0.9.1/CHANGELOG +13 -0
  10. data/vendor/gems/css_parser-0.9.1/LICENSE +21 -0
  11. data/vendor/gems/css_parser-0.9.1/README +58 -0
  12. data/vendor/gems/css_parser-0.9.1/lib/css_parser.rb +149 -0
  13. data/vendor/gems/css_parser-0.9.1/lib/css_parser/parser.rb +345 -0
  14. data/vendor/gems/css_parser-0.9.1/lib/css_parser/regexps.rb +46 -0
  15. data/vendor/gems/css_parser-0.9.1/lib/css_parser/rule_set.rb +380 -0
  16. data/vendor/gems/css_parser-0.9.1/test/fixtures/import-circular-reference.css +4 -0
  17. data/vendor/gems/css_parser-0.9.1/test/fixtures/import-with-media-types.css +3 -0
  18. data/vendor/gems/css_parser-0.9.1/test/fixtures/import1.css +3 -0
  19. data/vendor/gems/css_parser-0.9.1/test/fixtures/simple.css +6 -0
  20. data/vendor/gems/css_parser-0.9.1/test/fixtures/subdir/import2.css +3 -0
  21. data/vendor/gems/css_parser-0.9.1/test/test_css_parser_basic.rb +56 -0
  22. data/vendor/gems/css_parser-0.9.1/test/test_css_parser_downloading.rb +81 -0
  23. data/vendor/gems/css_parser-0.9.1/test/test_css_parser_media_types.rb +71 -0
  24. data/vendor/gems/css_parser-0.9.1/test/test_css_parser_misc.rb +143 -0
  25. data/vendor/gems/css_parser-0.9.1/test/test_css_parser_regexps.rb +68 -0
  26. data/vendor/gems/css_parser-0.9.1/test/test_helper.rb +8 -0
  27. data/vendor/gems/css_parser-0.9.1/test/test_merging.rb +88 -0
  28. data/vendor/gems/css_parser-0.9.1/test/test_rule_set.rb +74 -0
  29. data/vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb +90 -0
  30. data/vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb +178 -0
  31. metadata +25 -13
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # Test cases for parsing CSS blocks
4
+ class RuleSetTests < Test::Unit::TestCase
5
+ include CssParser
6
+
7
+ def setup
8
+ @cp = Parser.new
9
+ end
10
+
11
+ def test_setting_property_values
12
+ rs = RuleSet.new(nil, nil)
13
+
14
+ rs['background-color'] = 'red'
15
+ assert_equal('red;', rs['background-color'])
16
+
17
+ rs['background-color'] = 'blue !important;'
18
+ assert_equal('blue !important;', rs['background-color'])
19
+ end
20
+
21
+ def test_getting_property_values
22
+ rs = RuleSet.new('#content p, a', 'color: #fff;')
23
+ assert_equal('#fff;', rs['color'])
24
+ end
25
+
26
+ def test_getting_property_value_ignoring_case
27
+ rs = RuleSet.new('#content p, a', 'color: #fff;')
28
+ assert_equal('#fff;', rs[' ColoR '])
29
+ end
30
+
31
+ def test_each_selector
32
+ expected = [
33
+ {:selector => "#content p", :declarations => "color: #fff;", :specificity => 101},
34
+ {:selector => "a", :declarations => "color: #fff;", :specificity => 1}
35
+ ]
36
+
37
+ actual = []
38
+ rs = RuleSet.new('#content p, a', 'color: #fff;')
39
+ rs.each_selector do |sel, decs, spec|
40
+ actual << {:selector => sel, :declarations => decs, :specificity => spec}
41
+ end
42
+
43
+ assert_equal(expected, actual)
44
+ end
45
+
46
+ def test_each_declaration
47
+ expected = [
48
+ {:property => 'margin', :value => '1px -0.25em', :is_important => false},
49
+ {:property => 'background', :value => 'white none no-repeat', :is_important => true},
50
+ {:property => 'color', :value => '#fff', :is_important => false}
51
+ ]
52
+
53
+ actual = []
54
+ rs = RuleSet.new(nil, 'color: #fff; Background: white none no-repeat !important; margin: 1px -0.25em;')
55
+ rs.each_declaration do |prop, val, imp|
56
+ actual << {:property => prop, :value => val, :is_important => imp}
57
+ end
58
+
59
+ assert_equal(expected, actual)
60
+ end
61
+
62
+ def test_declarations_to_s
63
+ declarations = 'color: #fff; font-weight: bold;'
64
+ rs = RuleSet.new('#content p, a', declarations)
65
+ assert_equal(declarations.split(' ').sort, rs.declarations_to_s.split(' ').sort)
66
+ end
67
+
68
+ def test_overriding_specificity
69
+ rs = RuleSet.new('#content p, a', 'color: white', 1000)
70
+ rs.each_selector do |sel, decs, spec|
71
+ assert_equal 1000, spec
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,90 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ # Test cases for reading and generating CSS shorthand properties
4
+ class RuleSetCreatingShorthandTests < Test::Unit::TestCase
5
+ include CssParser
6
+
7
+ def setup
8
+ @cp = CssParser::Parser.new
9
+ end
10
+
11
+ # ==== Dimensions shorthand
12
+ def test_combining_dimensions_into_shorthand
13
+ properties = {'margin-right' => 'auto', 'margin-bottom' => '0px', 'margin-left' => 'auto', 'margin-top' => '0px',
14
+ 'padding-right' => '1.25em', 'padding-bottom' => '11%', 'padding-left' => '3pc', 'padding-top' => '11.25ex'}
15
+
16
+ combined = create_shorthand(properties)
17
+
18
+ assert_equal('0px auto;', combined['margin'])
19
+ assert_equal('11.25ex 1.25em 11% 3pc;', combined['padding'])
20
+
21
+ # after creating shorthand, all long-hand properties should be deleted
22
+ assert_properties_are_deleted(combined, properties)
23
+
24
+ # should not combine if any properties are missing
25
+ properties.delete('margin-right')
26
+ properties.delete('padding-right')
27
+
28
+ combined = create_shorthand(properties)
29
+
30
+ assert_equal '', combined['margin']
31
+ assert_equal '', combined['padding']
32
+ end
33
+
34
+ # ==== Font shorthand
35
+ def test_combining_font_into_shorthand
36
+ # should combine if all font properties are present
37
+ properties = {"font-weight" => "300", "font-size" => "12pt",
38
+ "font-family" => "sans-serif", "line-height" => "18px",
39
+ "font-style" => "oblique", "font-variant" => "small-caps"}
40
+
41
+ combined = create_shorthand(properties)
42
+ assert_equal('oblique small-caps 300 12pt/18px sans-serif;', combined['font'])
43
+
44
+ # after creating shorthand, all long-hand properties should be deleted
45
+ assert_properties_are_deleted(combined, properties)
46
+
47
+ # should not combine if any properties are missing
48
+ properties.delete('font-weight')
49
+ combined = create_shorthand(properties)
50
+ assert_equal '', combined['font']
51
+ end
52
+
53
+ # ==== Background shorthand
54
+ def test_combining_background_into_shorthand
55
+ properties = {'background-image' => 'url(\'chess.png\')', 'background-color' => 'gray',
56
+ 'background-position' => 'center -10.2%', 'background-attachment' => 'fixed',
57
+ 'background-repeat' => 'no-repeat'}
58
+
59
+ combined = create_shorthand(properties)
60
+
61
+ assert_equal('gray url(\'chess.png\') no-repeat center -10.2% fixed;', combined['background'])
62
+
63
+ # after creating shorthand, all long-hand properties should be deleted
64
+ assert_properties_are_deleted(combined, properties)
65
+ end
66
+
67
+ def test_property_values_in_url
68
+ rs = RuleSet.new('#header', "background:url(http://example.com/1528/www/top-logo.jpg) no-repeat top right; padding: 79px 0 10px 0; text-align:left;")
69
+ rs.expand_shorthand!
70
+ assert_equal('top right;', rs['background-position'])
71
+ rs.create_shorthand!
72
+ assert_equal('url(http://example.com/1528/www/top-logo.jpg) no-repeat top right;', rs['background'])
73
+ end
74
+
75
+ protected
76
+ def assert_properties_are_deleted(ruleset, properties)
77
+ properties.each do |property, value|
78
+ assert_equal '', ruleset[property]
79
+ end
80
+ end
81
+
82
+ def create_shorthand(properties)
83
+ ruleset = RuleSet.new(nil, nil)
84
+ properties.each do |property, value|
85
+ ruleset[property] = value
86
+ end
87
+ ruleset.create_shorthand!
88
+ ruleset
89
+ end
90
+ end
@@ -0,0 +1,178 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class RuleSetExpandingShorthandTests < Test::Unit::TestCase
4
+ include CssParser
5
+
6
+ def setup
7
+ @cp = CssParser::Parser.new
8
+ end
9
+
10
+ # ==== Dimensions shorthand
11
+ def test_getting_dimensions_from_shorthand
12
+ # test various shorthand forms
13
+ ['margin: 0px auto', 'margin: 0px auto 0px', 'margin: 0px auto 0px'].each do |shorthand|
14
+ declarations = expand_declarations(shorthand)
15
+ assert_equal({"margin-right" => "auto", "margin-bottom" => "0px", "margin-left" => "auto", "margin-top" => "0px"}, declarations)
16
+ end
17
+
18
+ # test various units
19
+ ['em', 'ex', 'in', 'px', 'pt', 'pc', '%'].each do |unit|
20
+ shorthand = "margin: 0% -0.123#{unit} 9px -.9pc"
21
+ declarations = expand_declarations(shorthand)
22
+ assert_equal({"margin-right" => "-0.123#{unit}", "margin-bottom" => "9px", "margin-left" => "-.9pc", "margin-top" => "0%"}, declarations)
23
+ end
24
+ end
25
+
26
+
27
+ # ==== Font shorthand
28
+ def test_getting_font_size_from_shorthand
29
+ ['em', 'ex', 'in', 'px', 'pt', 'pc', '%'].each do |unit|
30
+ shorthand = "font: 300 italic 11.25#{unit}/14px verdana, helvetica, sans-serif;"
31
+ declarations = expand_declarations(shorthand)
32
+ assert_equal("11.25#{unit}", declarations['font-size'])
33
+ end
34
+
35
+ ['smaller', 'small', 'medium', 'large', 'x-large', 'auto'].each do |unit|
36
+ shorthand = "font: 300 italic #{unit}/14px verdana, helvetica, sans-serif;"
37
+ declarations = expand_declarations(shorthand)
38
+ assert_equal(unit, declarations['font-size'])
39
+ end
40
+ end
41
+
42
+ def test_getting_font_families_from_shorthand
43
+ shorthand = "font: 300 italic 12px/14px \"Helvetica-Neue-Light 45\", 'verdana', helvetica, sans-serif;"
44
+ declarations = expand_declarations(shorthand)
45
+ assert_equal("\"Helvetica-Neue-Light 45\", 'verdana', helvetica, sans-serif", declarations['font-family'])
46
+ end
47
+
48
+ def test_getting_font_weight_from_shorthand
49
+ ['300', 'bold', 'bolder', 'lighter', 'normal'].each do |unit|
50
+ shorthand = "font: #{unit} italic 12px sans-serif;"
51
+ declarations = expand_declarations(shorthand)
52
+ assert_equal(unit, declarations['font-weight'])
53
+ end
54
+
55
+ # ensure normal is the default state
56
+ ['font: normal italic 12px sans-serif;', 'font: italic 12px sans-serif;',
57
+ 'font: small-caps normal 12px sans-serif;', 'font: 12px/16px sans-serif;'].each do |shorthand|
58
+ declarations = expand_declarations(shorthand)
59
+ assert_equal('normal', declarations['font-weight'], shorthand)
60
+ end
61
+ end
62
+
63
+ def test_getting_font_variant_from_shorthand
64
+ shorthand = "font: small-caps italic 12px sans-serif;"
65
+ declarations = expand_declarations(shorthand)
66
+ assert_equal('small-caps', declarations['font-variant'])
67
+
68
+ # ensure normal is the default state
69
+ ['font: normal italic 12px sans-serif;', 'font: italic 12px sans-serif;',
70
+ 'font: normal 12px sans-serif;', 'font: 12px/16px sans-serif;'].each do |shorthand|
71
+ declarations = expand_declarations(shorthand)
72
+ assert_equal('normal', declarations['font-variant'], shorthand)
73
+ end
74
+ end
75
+
76
+ def test_getting_font_style_from_shorthand
77
+ ['italic', 'oblique'].each do |unit|
78
+ shorthand = "font: normal #{unit} bold 12px sans-serif;"
79
+ declarations = expand_declarations(shorthand)
80
+ assert_equal(unit, declarations['font-style'])
81
+ end
82
+
83
+ # ensure normal is the default state
84
+ ['font: normal bold 12px sans-serif;', 'font: small-caps 12px sans-serif;',
85
+ 'font: normal 12px sans-serif;', 'font: 12px/16px sans-serif;'].each do |shorthand|
86
+ declarations = expand_declarations(shorthand)
87
+ assert_equal('normal', declarations['font-style'], shorthand)
88
+ end
89
+ end
90
+
91
+ def test_getting_line_height_from_shorthand
92
+ ['em', 'ex', 'in', 'px', 'pt', 'pc', '%'].each do |unit|
93
+ shorthand = "font: 300 italic 12px/0.25#{unit} verdana, helvetica, sans-serif;"
94
+ declarations = expand_declarations(shorthand)
95
+ assert_equal("0.25#{unit}", declarations['line-height'])
96
+ end
97
+
98
+ # ensure normal is the default state
99
+ ['font: normal bold 12px sans-serif;', 'font: small-caps 12px sans-serif;',
100
+ 'font: normal 12px sans-serif;', 'font: 12px sans-serif;'].each do |shorthand|
101
+ declarations = expand_declarations(shorthand)
102
+ assert_equal('normal', declarations['line-height'], shorthand)
103
+ end
104
+ end
105
+
106
+
107
+ # ==== Background shorthand
108
+ def test_getting_background_properties_from_shorthand
109
+ expected = {"background-image" => "url('chess.png')", "background-color" => "gray", "background-repeat" => "repeat",
110
+ "background-attachment" => "fixed", "background-position" => "50%"}
111
+
112
+ shorthand = "background: url('chess.png') gray 50% repeat fixed;"
113
+ declarations = expand_declarations(shorthand)
114
+ assert_equal expected, declarations
115
+ end
116
+
117
+ def test_getting_background_position_from_shorthand
118
+ ['em', 'ex', 'in', 'px', 'pt', 'pc', '%'].each do |unit|
119
+ shorthand = "background: url('chess.png') gray 30% -0.15#{unit} repeat fixed;"
120
+ declarations = expand_declarations(shorthand)
121
+ assert_equal("30% -0.15#{unit}", declarations['background-position'])
122
+ end
123
+
124
+ ['left', 'center', 'right', 'top', 'bottom', 'inherit'].each do |position|
125
+ shorthand = "background: url('chess.png') #000fff #{position} no-repeat fixed;"
126
+ declarations = expand_declarations(shorthand)
127
+ assert_equal(position, declarations['background-position'])
128
+ end
129
+ end
130
+
131
+ def test_getting_background_colour_from_shorthand
132
+ ['blue', 'lime', 'rgb(10,10,10)', 'rgb ( -10%, 99, 300)', '#ffa0a0', '#03c', 'trAnsparEnt', 'inherit'].each do |colour|
133
+ shorthand = "background:#{colour} url('chess.png') center repeat fixed ;"
134
+ declarations = expand_declarations(shorthand)
135
+ assert_equal(colour, declarations['background-color'])
136
+ end
137
+ end
138
+
139
+ def test_getting_background_attachment_from_shorthand
140
+ ['scroll', 'fixed', 'inherit'].each do |attachment|
141
+ shorthand = "background:#0f0f0f url('chess.png') center repeat #{attachment};"
142
+ declarations = expand_declarations(shorthand)
143
+ assert_equal(attachment, declarations['background-attachment'])
144
+ end
145
+ end
146
+
147
+ def test_getting_background_repeat_from_shorthand
148
+ ['repeat-x', 'repeat-y', 'no-repeat', 'inherit'].each do |repeat|
149
+ shorthand = "background:#0f0f0f none #{repeat};"
150
+ declarations = expand_declarations(shorthand)
151
+ assert_equal(repeat, declarations['background-repeat'])
152
+ end
153
+ end
154
+
155
+ def test_getting_background_image_from_shorthand
156
+ ['url("chess.png")', 'url("https://example.org:80/~files/chess.png?123=abc&test#5")',
157
+ 'url(https://example.org:80/~files/chess.png?123=abc&test#5)',
158
+ "url('https://example.org:80/~files/chess.png?123=abc&test#5')", 'none', 'inherit'].each do |image|
159
+
160
+ shorthand = "background: #0f0f0f #{image} ;"
161
+ declarations = expand_declarations(shorthand)
162
+ assert_equal(image, declarations['background-image'])
163
+ end
164
+ end
165
+
166
+
167
+ protected
168
+ def expand_declarations(declarations)
169
+ ruleset = RuleSet.new(nil, declarations)
170
+ ruleset.expand_shorthand!
171
+
172
+ collected = {}
173
+ ruleset.each_declaration do |prop, val, imp|
174
+ collected[prop.to_s] = val.to_s
175
+ end
176
+ collected
177
+ end
178
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deadweight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aanand Prasad
@@ -9,19 +9,9 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-18 00:00:00 -04:00
12
+ date: 2009-12-15 00:00:00 -05:00
13
13
  default_executable: deadweight
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: css_parser
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
15
  - !ruby/object:Gem::Dependency
26
16
  name: hpricot
27
17
  type: :runtime
@@ -60,6 +50,28 @@ files:
60
50
  - test/fixtures/style.css
61
51
  - test/rake_task_test.rb
62
52
  - test/test_helper.rb
53
+ - vendor/gems/css_parser-0.9.1/CHANGELOG
54
+ - vendor/gems/css_parser-0.9.1/LICENSE
55
+ - vendor/gems/css_parser-0.9.1/README
56
+ - vendor/gems/css_parser-0.9.1/lib/css_parser.rb
57
+ - vendor/gems/css_parser-0.9.1/lib/css_parser/parser.rb
58
+ - vendor/gems/css_parser-0.9.1/lib/css_parser/regexps.rb
59
+ - vendor/gems/css_parser-0.9.1/lib/css_parser/rule_set.rb
60
+ - vendor/gems/css_parser-0.9.1/test/fixtures/import-circular-reference.css
61
+ - vendor/gems/css_parser-0.9.1/test/fixtures/import-with-media-types.css
62
+ - vendor/gems/css_parser-0.9.1/test/fixtures/import1.css
63
+ - vendor/gems/css_parser-0.9.1/test/fixtures/simple.css
64
+ - vendor/gems/css_parser-0.9.1/test/fixtures/subdir/import2.css
65
+ - vendor/gems/css_parser-0.9.1/test/test_css_parser_basic.rb
66
+ - vendor/gems/css_parser-0.9.1/test/test_css_parser_downloading.rb
67
+ - vendor/gems/css_parser-0.9.1/test/test_css_parser_media_types.rb
68
+ - vendor/gems/css_parser-0.9.1/test/test_css_parser_misc.rb
69
+ - vendor/gems/css_parser-0.9.1/test/test_css_parser_regexps.rb
70
+ - vendor/gems/css_parser-0.9.1/test/test_helper.rb
71
+ - vendor/gems/css_parser-0.9.1/test/test_merging.rb
72
+ - vendor/gems/css_parser-0.9.1/test/test_rule_set.rb
73
+ - vendor/gems/css_parser-0.9.1/test/test_rule_set_creating_shorthand.rb
74
+ - vendor/gems/css_parser-0.9.1/test/test_rule_set_expanding_shorthand.rb
63
75
  has_rdoc: true
64
76
  homepage: http://github.com/aanand/deadweight
65
77
  licenses: []
@@ -84,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
96
  requirements: []
85
97
 
86
98
  rubyforge_project:
87
- rubygems_version: 1.3.4
99
+ rubygems_version: 1.3.5
88
100
  signing_key:
89
101
  specification_version: 3
90
102
  summary: A coverage tool for finding unused CSS