unused_css 0.2.0 → 1.0.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +4 -15
- data/features/step_definitions/observation_steps.rb +2 -2
- data/features/support/env.rb +11 -0
- data/lib/unused_css/stylesheet.rb +6 -6
- data/lib/unused_css/version.rb +1 -1
- data/lib/unused_css/watir.rb +3 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e5ad61518c27f5f0e809acc13fc7fdc30994499
|
4
|
+
data.tar.gz: ceb72ff52d091e4ff0db3675827bf17ba0527716
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73a1f5002becd686113dfdc36f3fb7fed16e346d314f2db2c3d04a08b467de2c24dab25da6b588a66dccae429d3efe56c47267e8badec9e7518c3f7512ba16e4
|
7
|
+
data.tar.gz: b6ac6f04f53af44248bd7ebefe51248d8e6407c28ce4795d43d969c483404f737239ce1f8f4a163c1ef119b9c6ce772f79e4f31bcf65e516009b4a479d1c4fb2
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Unused CSS
|
|
3
3
|
|
4
4
|
[](https://travis-ci.org/christemple/unused-css)
|
5
5
|
|
6
|
-
A Ruby gem
|
6
|
+
A Ruby gem that will watch a suite of functional tests running and gather all of the unused CSS styles.
|
7
7
|
|
8
8
|
Install
|
9
9
|
-------
|
@@ -29,9 +29,9 @@ at_exit do
|
|
29
29
|
|
30
30
|
# A list of all stylehseets together with their unused styles
|
31
31
|
puts "Unused CSS"
|
32
|
-
$
|
32
|
+
$browser.stylesheets.each do |stylesheet|
|
33
33
|
puts stylesheet.uri
|
34
|
-
stylesheet.
|
34
|
+
stylesheet.unused_styles.each { |style| puts style }
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
@@ -55,9 +55,7 @@ In one of your step definitions you can simply call:
|
|
55
55
|
```ruby
|
56
56
|
When(/^I recheck the styles on the page$/) do
|
57
57
|
|
58
|
-
# Where $browser is an instance of Watir webdriver
|
59
|
-
# have called the unused css watch! method on
|
60
|
-
|
58
|
+
# Where $browser is an instance of Watir webdriver
|
61
59
|
$browser.check_for_unused_styles!
|
62
60
|
end
|
63
61
|
```
|
@@ -67,15 +65,6 @@ Limitations
|
|
67
65
|
|
68
66
|
Unused CSS currently only works with Watir webdriver, I will be adding more webdrivers soon.
|
69
67
|
|
70
|
-
TODO
|
71
|
-
----
|
72
|
-
|
73
|
-
There are still a few things I am looking to do with this Ruby gem.
|
74
|
-
- Add support for more web drivers.
|
75
|
-
- Add ability to create report after watching the tests.
|
76
|
-
- ...not sure, you tell me :)
|
77
|
-
|
78
|
-
|
79
68
|
Feedback
|
80
69
|
--------
|
81
70
|
Please send me a message or an email and let me know what you think.
|
@@ -3,11 +3,11 @@ Then "I should see '$text'" do |text|
|
|
3
3
|
end
|
4
4
|
|
5
5
|
Then "I should see style '$style' was used" do |style|
|
6
|
-
fail "#{style} style was not used" if $browser.stylesheets.
|
6
|
+
fail "#{style} style was not used" if $browser.stylesheets.unused_styles.include? style
|
7
7
|
end
|
8
8
|
|
9
9
|
Then "I should see style '$style' was not used" do |style|
|
10
|
-
fail "#{style} style was used" unless $browser.stylesheets.
|
10
|
+
fail "#{style} style was used" unless $browser.stylesheets.unused_styles.include? style
|
11
11
|
end
|
12
12
|
|
13
13
|
When(/^I wait for content to be loaded into the DOM via AJAX$/) do
|
data/features/support/env.rb
CHANGED
@@ -7,4 +7,15 @@ $browser = Watir::Browser.new
|
|
7
7
|
|
8
8
|
at_exit do
|
9
9
|
$browser.close
|
10
|
+
|
11
|
+
puts "==================="
|
12
|
+
puts "Unused CSS"
|
13
|
+
puts "===================\n\n"
|
14
|
+
$browser.stylesheets.each do |stylesheet|
|
15
|
+
puts stylesheet.uri
|
16
|
+
puts "-------------------------------"
|
17
|
+
stylesheet.unused_styles.each do |style|
|
18
|
+
puts "\t#{style}"
|
19
|
+
end
|
20
|
+
end
|
10
21
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "css_parser"
|
2
2
|
|
3
3
|
class Stylesheet
|
4
|
-
attr_accessor :uri, :
|
4
|
+
attr_accessor :uri, :unused_styles, :parser
|
5
5
|
|
6
6
|
def initialize (uri)
|
7
|
-
@
|
7
|
+
@unused_styles = Set.new
|
8
8
|
@uri = uri
|
9
9
|
parse_styles!
|
10
10
|
end
|
@@ -12,11 +12,11 @@ class Stylesheet
|
|
12
12
|
def parse_styles!
|
13
13
|
@parser = CssParser::Parser.new
|
14
14
|
@parser.load_uri! @uri
|
15
|
-
@parser.each_selector { |
|
15
|
+
@parser.each_selector { |style| @unused_styles << style }
|
16
16
|
end
|
17
17
|
|
18
18
|
def remove_pseudo_styles!
|
19
|
-
@
|
19
|
+
@unused_styles.delete_if { |style| style.match /::?[\w\-]+/ }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -46,7 +46,7 @@ class Stylesheets
|
|
46
46
|
@stylesheets.each &block
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
@stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.
|
49
|
+
def unused_styles
|
50
|
+
@stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.unused_styles }
|
51
51
|
end
|
52
52
|
end
|
data/lib/unused_css/version.rb
CHANGED
data/lib/unused_css/watir.rb
CHANGED
@@ -15,20 +15,19 @@ module Watir
|
|
15
15
|
def goto(*args)
|
16
16
|
original_goto(*args)
|
17
17
|
@stylesheets.add stylesheets_on_page
|
18
|
-
|
18
|
+
check_for_unused_styles!
|
19
19
|
end
|
20
20
|
|
21
21
|
def stylesheets_on_page
|
22
22
|
elements(tag_name: 'link').map { |stylesheet| stylesheet.attribute_value('href') }
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def check_for_unused_styles!
|
26
26
|
@stylesheets.each do |stylesheet|
|
27
|
-
stylesheet.
|
27
|
+
stylesheet.unused_styles.delete_if { |style| self.element(css: style).exist? }
|
28
28
|
stylesheet.remove_pseudo_styles!
|
29
29
|
end
|
30
30
|
end
|
31
|
-
alias_method :check_for_unused_styles!, :remove_used_styles!
|
32
31
|
end
|
33
32
|
|
34
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unused_css
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Temple
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|