unused_css 0.1.0 → 0.2.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 +1 -3
- data/features/step_definitions/observation_steps.rb +2 -2
- data/features/support/env.rb +1 -3
- data/lib/unused_css/version.rb +1 -1
- data/lib/unused_css/watir.rb +34 -0
- data/lib/unused_css.rb +1 -35
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2a9ef39b6aeb0dac1e93d2cdc72890b40da563b
|
4
|
+
data.tar.gz: 9f4b93533589a7a829a500448889b2f44463c6a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a0fcc98240b3261dbc8d81c8e414e94b5f8b825c125d3ca168cbfe9684914b3d56052dfcf9cb6ee8811eab03f5407f5f15e20b65d328150c704d85480263bb
|
7
|
+
data.tar.gz: 539ab00925b8c5a9c7cbdf24aac95259a88407a6db87239ee24de2d4b778e5f95c88124c7d84d415d326d51fcc14a03f0399cc119821f6cba897ffc744be9363
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,11 +20,9 @@ Here's a typical 'features/support/env.rb' file using Unused CSS to watch the Wa
|
|
20
20
|
|
21
21
|
```ruby
|
22
22
|
require "watir-webdriver"
|
23
|
-
require "unused_css"
|
23
|
+
require "unused_css/watir"
|
24
24
|
|
25
25
|
$browser = Watir::Browser.new
|
26
|
-
$unused_css = UnusedCSS::Watcher.new
|
27
|
-
$unused_css.watch! $browser
|
28
26
|
|
29
27
|
at_exit do
|
30
28
|
$browser.close
|
@@ -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 $
|
6
|
+
fail "#{style} style was not used" if $browser.stylesheets.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 $
|
10
|
+
fail "#{style} style was used" unless $browser.stylesheets.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
data/lib/unused_css/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "unused_css/stylesheet"
|
2
|
+
|
3
|
+
module Watir
|
4
|
+
|
5
|
+
class Browser
|
6
|
+
attr_accessor :stylesheets
|
7
|
+
|
8
|
+
alias_method :original_initialize, :initialize
|
9
|
+
def initialize(*args)
|
10
|
+
@stylesheets = Stylesheets.new
|
11
|
+
original_initialize(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
alias_method :original_goto, :goto
|
15
|
+
def goto(*args)
|
16
|
+
original_goto(*args)
|
17
|
+
@stylesheets.add stylesheets_on_page
|
18
|
+
remove_used_styles!
|
19
|
+
end
|
20
|
+
|
21
|
+
def stylesheets_on_page
|
22
|
+
elements(tag_name: 'link').map { |stylesheet| stylesheet.attribute_value('href') }
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove_used_styles!
|
26
|
+
@stylesheets.each do |stylesheet|
|
27
|
+
stylesheet.styles.delete_if { |style| self.element(css: style).exist? }
|
28
|
+
stylesheet.remove_pseudo_styles!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_method :check_for_unused_styles!, :remove_used_styles!
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/unused_css.rb
CHANGED
@@ -1,36 +1,2 @@
|
|
1
1
|
require "unused_css/version"
|
2
|
-
require "unused_css/
|
3
|
-
|
4
|
-
module UnusedCSS
|
5
|
-
class Watcher
|
6
|
-
attr_accessor :stylesheets
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@stylesheets = Stylesheets.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def watch!(watir_browser)
|
13
|
-
unused_css_block = Proc.new do |unused_css|
|
14
|
-
@unused_css = unused_css
|
15
|
-
def goto(uri)
|
16
|
-
super(uri)
|
17
|
-
stylesheets = elements(tag_name: 'link').map {|stylesheet| stylesheet.attribute_value('href') }
|
18
|
-
@unused_css.stylesheets.add stylesheets
|
19
|
-
stylesheets.each do |stylesheet|
|
20
|
-
stylesheet = @unused_css.stylesheets[stylesheet]
|
21
|
-
stylesheet.styles.delete_if {|style| self.element(css: style).exist? }
|
22
|
-
stylesheet.remove_pseudo_styles!
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def check_for_unused_styles!
|
27
|
-
@unused_css.stylesheets.each do |stylesheet|
|
28
|
-
stylesheet.styles.delete_if {|style| self.element(css: style).exist? }
|
29
|
-
stylesheet.remove_pseudo_styles!
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
watir_browser.instance_exec self, &unused_css_block
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
2
|
+
require "unused_css/watir"
|
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: 0.2.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-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/unused_css.rb
|
134
134
|
- lib/unused_css/stylesheet.rb
|
135
135
|
- lib/unused_css/version.rb
|
136
|
+
- lib/unused_css/watir.rb
|
136
137
|
- public/stylesheets/multiple.css
|
137
138
|
- public/stylesheets/style.css
|
138
139
|
- unused-css.iml
|