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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2a9ef39b6aeb0dac1e93d2cdc72890b40da563b
4
- data.tar.gz: 9f4b93533589a7a829a500448889b2f44463c6a8
3
+ metadata.gz: 3e5ad61518c27f5f0e809acc13fc7fdc30994499
4
+ data.tar.gz: ceb72ff52d091e4ff0db3675827bf17ba0527716
5
5
  SHA512:
6
- metadata.gz: a3a0fcc98240b3261dbc8d81c8e414e94b5f8b825c125d3ca168cbfe9684914b3d56052dfcf9cb6ee8811eab03f5407f5f15e20b65d328150c704d85480263bb
7
- data.tar.gz: 539ab00925b8c5a9c7cbdf24aac95259a88407a6db87239ee24de2d4b778e5f95c88124c7d84d415d326d51fcc14a03f0399cc119821f6cba897ffc744be9363
6
+ metadata.gz: 73a1f5002becd686113dfdc36f3fb7fed16e346d314f2db2c3d04a08b467de2c24dab25da6b588a66dccae429d3efe56c47267e8badec9e7518c3f7512ba16e4
7
+ data.tar.gz: b6ac6f04f53af44248bd7ebefe51248d8e6407c28ce4795d43d969c483404f737239ce1f8f4a163c1ef119b9c6ce772f79e4f31bcf65e516009b4a479d1c4fb2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unused_css (0.1.0)
4
+ unused_css (1.0.0)
5
5
  css_parser
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -3,7 +3,7 @@ Unused CSS
3
3
 
4
4
  [![Build Status](https://travis-ci.org/christemple/unused-css.png?branch=master)](https://travis-ci.org/christemple/unused-css)
5
5
 
6
- A Ruby gem, built from a need, to watch a suite of functional tests and gather all of the unused CSS styles.
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
- $unused_css.stylesheets.each do |stylesheet|
32
+ $browser.stylesheets.each do |stylesheet|
33
33
  puts stylesheet.uri
34
- stylesheet.styles.each { |style| puts style }
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 that you
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.styles.include? style
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.styles.include? style
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
@@ -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, :styles, :parser
4
+ attr_accessor :uri, :unused_styles, :parser
5
5
 
6
6
  def initialize (uri)
7
- @styles = Set.new
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 { |styles| @styles << styles }
15
+ @parser.each_selector { |style| @unused_styles << style }
16
16
  end
17
17
 
18
18
  def remove_pseudo_styles!
19
- @styles.delete_if { |style| style.match /::?[\w\-]+/ }
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 styles
50
- @stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.styles }
49
+ def unused_styles
50
+ @stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.unused_styles }
51
51
  end
52
52
  end
@@ -1,3 +1,3 @@
1
1
  module UnusedCSS
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -15,20 +15,19 @@ module Watir
15
15
  def goto(*args)
16
16
  original_goto(*args)
17
17
  @stylesheets.add stylesheets_on_page
18
- remove_used_styles!
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 remove_used_styles!
25
+ def check_for_unused_styles!
26
26
  @stylesheets.each do |stylesheet|
27
- stylesheet.styles.delete_if { |style| self.element(css: style).exist? }
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.2.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-10 00:00:00.000000000 Z
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser