aanand-deadweight 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  Deadweight is RCov for CSS, kind of. Given a set of stylesheets and a set of URLs, it determines which selectors are actually used and reports which can be "safely" deleted.
4
4
 
5
- Simple example:
5
+ === A Simple Example
6
+
6
7
  # lib/tasks/deadweight.rake
7
8
 
8
9
  require 'deadweight'
9
10
 
10
- description "run Deadweight (script/server needs to be running)"
11
+ desc "run Deadweight (script/server needs to be running)"
11
12
  task :deadweight do
12
13
  dw = Deadweight.new
13
14
  dw.stylesheets = %w( /stylesheets/style.css )
@@ -17,18 +18,24 @@ Simple example:
17
18
 
18
19
  This will output all unused selectors, one per line.
19
20
 
20
- Things to note:
21
+ === How You Install It
22
+
23
+ gem sources -a http://gems.github.com
24
+ sudo gem install aanand-deadweight
25
+
26
+ === Things to Note
27
+
21
28
  - By default, it looks at http://localhost:3000.
22
29
  - It's completely dumb about any classes, IDs or tags that are only added by your Javascript layer, but you can filter them out by setting +ignore_selectors+.
23
30
  - You can optionally tell it to use Mechanize, and set up more complicated targets for scraping by specifying them as Procs.
24
31
 
25
- More complex example:
32
+ === A More Complex Example, In Light of All That
26
33
 
27
34
  # lib/tasks/deadweight.rake
28
35
 
29
36
  require 'deadweight'
30
37
 
31
- description "run Deadweight on staging server"
38
+ desc "run Deadweight on staging server"
32
39
  task :deadweight do
33
40
  dw = Deadweight.new
34
41
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/deadweight.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{deadweight}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aanand Prasad"]
9
- s.date = %q{2009-07-21}
9
+ s.date = %q{2009-08-18}
10
10
  s.email = %q{aanand.prasad@gmail.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
data/lib/deadweight.rb CHANGED
@@ -33,6 +33,13 @@ class Deadweight
33
33
  end
34
34
  end
35
35
 
36
+ # Remove selectors with pseudo classes that already have an equivalent
37
+ # without the pseudo class. Keep the ones that don't, we need to test
38
+ # them.
39
+ unused_selectors.reject! do |selector|
40
+ has_pseudo_classes(selector) && unused_selectors.include?(strip(selector))
41
+ end
42
+
36
43
  pages.each do |page|
37
44
  case page
38
45
  when String
@@ -53,7 +60,9 @@ class Deadweight
53
60
  found_selectors = []
54
61
 
55
62
  unused_selectors.each do |selector|
56
- unless doc.search(selector).empty?
63
+ # We test against the selector stripped of any pseudo classes,
64
+ # but we report on the selector with its pseudo classes.
65
+ unless doc.search(strip(selector)).empty?
57
66
  log.info(" #{selector}")
58
67
  found_selectors << selector
59
68
  end
@@ -86,9 +95,17 @@ class Deadweight
86
95
  else
87
96
  open(loc).read
88
97
  end
89
- end
98
+ end
99
+
100
+ private
90
101
 
91
- private
102
+ def has_pseudo_classes(selector)
103
+ selector =~ /::?[\w\-]+/
104
+ end
105
+
106
+ def strip(selector)
107
+ selector.gsub(/::?[\w\-]+/, '')
108
+ end
92
109
 
93
110
  def log
94
111
  @log ||= Logger.new(@log_file)
@@ -108,6 +125,6 @@ class Deadweight
108
125
 
109
126
  raise
110
127
  end
111
- end
128
+ end
112
129
  end
113
130
 
@@ -20,6 +20,17 @@ class DeadweightTest < Test::Unit::TestCase
20
20
  assert !@result.include?('#foo .bar')
21
21
  end
22
22
 
23
+ should 'strip pseudo classes from selectors' do
24
+ # #oof:hover (#oof does not exist)
25
+ assert @result.include?('#oof:hover'), @result.inspect
26
+
27
+ # #foo:hover (#foo does exist)
28
+ assert !@result.include?('#foo:hover')
29
+
30
+ # #rab:hover::selection (#rab does not exist)
31
+ assert @result.include?('#rab:hover::selection')
32
+ end
33
+
23
34
  should "accept Procs as targets" do
24
35
  @dw.mechanize = true
25
36
 
@@ -11,6 +11,10 @@
11
11
  </div>
12
12
  </div>
13
13
  </div>
14
+
15
+ <div id="oof"></div>
16
+
17
+ <div id="rab"></div>
14
18
  </body>
15
19
  </html>
16
20
 
@@ -10,3 +10,15 @@
10
10
  color: red;
11
11
  }
12
12
 
13
+ /* pseudo classes */
14
+ #foo:hover {
15
+ color: red;
16
+ }
17
+
18
+ #oof:hover {
19
+ color: white;
20
+ }
21
+
22
+ #rab:hover::selection {
23
+ color: black;
24
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aanand-deadweight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aanand Prasad
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-21 00:00:00 -07:00
12
+ date: 2009-08-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -57,6 +57,7 @@ files:
57
57
  - test/test_helper.rb
58
58
  has_rdoc: false
59
59
  homepage: http://github.com/aanand/deadweight
60
+ licenses:
60
61
  post_install_message:
61
62
  rdoc_options:
62
63
  - --charset=UTF-8
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
78
  requirements: []
78
79
 
79
80
  rubyforge_project:
80
- rubygems_version: 1.2.0
81
+ rubygems_version: 1.3.5
81
82
  signing_key:
82
83
  specification_version: 3
83
84
  summary: RCov for CSS