csscss 0.2.0 → 0.2.1

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.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.1 - 3/28/2013 ##
2
+
3
+ * Changes coloring to the selectors and declarations
4
+ * Fixes bug where some duplicates weren't being combined #1
5
+
1
6
  ## 0.2.0 - 3/24/2013 ##
2
7
 
3
8
  * Colorizes text output.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csscss (0.2.0)
4
+ csscss (0.2.1)
5
5
  colorize
6
6
  parslet (~> 1.5)
7
7
 
@@ -87,16 +87,20 @@ module Csscss
87
87
 
88
88
  # combines selector keys by common declarations
89
89
  final_inverted_matches = inverted_matches.dup
90
- inverted_matches.to_a[0..-2].each_with_index do |(selector_group1, declarations1), index|
90
+ inverted_matches.to_a.each_with_index do |(selector_group1, declarations1), index|
91
+ keys = [selector_group1]
91
92
  inverted_matches.to_a[(index + 1)..-1].each do |selector_group2, declarations2|
92
- if declarations1 == declarations2
93
- final_inverted_matches.delete(selector_group1)
93
+ if declarations1 == declarations2 && final_inverted_matches[selector_group2]
94
+ keys << selector_group2
94
95
  final_inverted_matches.delete(selector_group2)
95
- key = (selector_group1 + selector_group2).sort.uniq
96
- final_inverted_matches[key] ||= []
97
- final_inverted_matches[key].concat(declarations1 + declarations2).uniq!
98
96
  end
99
97
  end
98
+
99
+ if keys.size > 1
100
+ final_inverted_matches.delete(selector_group1)
101
+ key = keys.flatten.sort.uniq
102
+ final_inverted_matches[key] = declarations1
103
+ end
100
104
  end
101
105
 
102
106
  # sort hash by number of matches
@@ -10,12 +10,12 @@ module Csscss
10
10
 
11
11
  io = StringIO.new
12
12
  @redundancies.each do |selector_groups, declarations|
13
- selector_groups = selector_groups.map {|selectors| maybe_color("{#{selectors}}", :red, should_color) }
13
+ selector_groups = selector_groups.map {|selectors| "{#{maybe_color(selectors, :red, should_color)}}" }
14
14
  last_selector = selector_groups.pop
15
15
  count = declarations.size
16
16
  io.puts %Q(#{selector_groups.join(", ")} AND #{last_selector} share #{maybe_color(count, :red, should_color)} rule#{"s" if count > 1})
17
17
  if verbose
18
- declarations.each {|dec| io.puts(maybe_color(" - #{dec}", :yellow, should_color)) }
18
+ declarations.each {|dec| io.puts(" - #{maybe_color(dec, :yellow, should_color)}") }
19
19
  end
20
20
  end
21
21
 
@@ -1,3 +1,3 @@
1
1
  module Csscss
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -76,10 +76,68 @@ module Csscss
76
76
  -moz-box-shadow: 1px 1px 10px #CCCCCC;
77
77
  -webkit-box-shadow: 1px 1px 10px #CCCCCC;
78
78
  }
79
+
80
+ .bar2 {
81
+ background: white;
82
+
83
+ -webkit-border-radius: 4px;
84
+ -moz-border-radius: 4px;
85
+ box-shadow: 1px 1px 10px #CCCCCC;
86
+ -moz-box-shadow: 1px 1px 10px #CCCCCC;
87
+ -webkit-box-shadow: 1px 1px 10px #CCCCCC;
88
+ }
79
89
  $
80
90
 
81
91
  redundancies = RedundancyAnalyzer.new(css).redundancies(3)
82
- redundancies[[sel(".bar"), sel(".baz")]].size.must_equal(5)
92
+ redundancies[[sel(".bar"), sel(".bar2"), sel(".baz")]].size.must_equal(5)
93
+ end
94
+
95
+ it "correctly finds counts with 3+ shared rules" do
96
+ css = %$
97
+ .foo1 {
98
+ background: white;
99
+
100
+ -webkit-border-radius: 4px;
101
+ -moz-border-radius: 4px;
102
+ box-shadow: 1px 1px 10px #CCCCCC;
103
+ -moz-box-shadow: 1px 1px 10px #CCCCCC;
104
+ -webkit-box-shadow: 1px 1px 10px #CCCCCC;
105
+ }
106
+
107
+ .foo2 {
108
+ background: white;
109
+
110
+ -webkit-border-radius: 4px;
111
+ -moz-border-radius: 4px;
112
+ box-shadow: 1px 1px 10px #CCCCCC;
113
+ -moz-box-shadow: 1px 1px 10px #CCCCCC;
114
+ -webkit-box-shadow: 1px 1px 10px #CCCCCC;
115
+ }
116
+
117
+ .foo3 {
118
+ background: white;
119
+
120
+ -webkit-border-radius: 4px;
121
+ -moz-border-radius: 4px;
122
+ box-shadow: 1px 1px 10px #CCCCCC;
123
+ -moz-box-shadow: 1px 1px 10px #CCCCCC;
124
+ -webkit-box-shadow: 1px 1px 10px #CCCCCC;
125
+ }
126
+
127
+ .foo4 {
128
+ background: white;
129
+
130
+ -webkit-border-radius: 4px;
131
+ -moz-border-radius: 4px;
132
+ box-shadow: 1px 1px 10px #CCCCCC;
133
+ -moz-box-shadow: 1px 1px 10px #CCCCCC;
134
+ -webkit-box-shadow: 1px 1px 10px #CCCCCC;
135
+ }
136
+ $
137
+
138
+ redundancies = RedundancyAnalyzer.new(css).redundancies
139
+ redundancies.keys.size.must_equal 1
140
+ redundancies[[sel(".foo1"), sel(".foo2"), sel(".foo3"), sel(".foo4")]].size.must_equal(6)
83
141
  end
84
142
 
85
143
  it "also matches shorthand rules" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csscss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: -2897207436893680163
123
+ hash: -1849161592586961535
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: -2897207436893680163
132
+ hash: -1849161592586961535
133
133
  requirements: []
134
134
  rubyforge_project:
135
135
  rubygems_version: 1.8.25