unused_css 0.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 313295e4c474b843705e8d12a7bd397969e64605
4
+ data.tar.gz: 39e1a472f668e1323bb94700bbca0a686ca965b4
5
+ SHA512:
6
+ metadata.gz: 7bd5203d64675e585294ad55a6774d8429c642c68868943896ac4bec673ad44f043174df6e0fece37bfa376f86252eac5b9e44ea33ccad2e2be0ca4f93e058e6
7
+ data.tar.gz: ecc113b62ddfe035ae389c54779f79ee7d4bafc8c3942de5e19930110dd17d220b904c2fef735489150de79331fd162c013615b64b3651be715cd45cee11b9a3
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ log/
2
+ tmp/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ unused-css
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ before_install:
2
+ - "export DISPLAY=:99.0"
3
+ - "sh -e /etc/init.d/xvfb start"
4
+
5
+ script:
6
+ - "bundle exec cucumber features"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unused_css (0.0.1)
5
+ css_parser
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.5)
11
+ builder (3.2.2)
12
+ childprocess (0.5.1)
13
+ ffi (~> 1.0, >= 1.0.11)
14
+ css_parser (1.3.5)
15
+ addressable
16
+ cucumber (1.3.10)
17
+ builder (>= 2.1.2)
18
+ diff-lcs (>= 1.1.3)
19
+ gherkin (~> 2.12)
20
+ multi_json (>= 1.7.5, < 2.0)
21
+ multi_test (>= 0.0.2)
22
+ daemons (1.1.9)
23
+ diff-lcs (1.2.5)
24
+ eventmachine (1.0.3)
25
+ ffi (1.9.3)
26
+ gherkin (2.12.2)
27
+ multi_json (~> 1.3)
28
+ multi_json (1.8.4)
29
+ multi_test (0.0.3)
30
+ rack (1.5.2)
31
+ rack-protection (1.5.2)
32
+ rack
33
+ rake (10.1.0)
34
+ rubyzip (1.1.0)
35
+ selenium-webdriver (2.39.0)
36
+ childprocess (>= 0.2.5)
37
+ multi_json (~> 1.0)
38
+ rubyzip (~> 1.0)
39
+ websocket (~> 1.0.4)
40
+ sinatra (1.4.4)
41
+ rack (~> 1.4)
42
+ rack-protection (~> 1.4)
43
+ tilt (~> 1.3, >= 1.3.4)
44
+ thin (1.6.1)
45
+ daemons (>= 1.0.9)
46
+ eventmachine (>= 1.0.0)
47
+ rack (>= 1.0.0)
48
+ tilt (1.4.1)
49
+ watir-webdriver (0.6.7)
50
+ selenium-webdriver (>= 2.18.0)
51
+ websocket (1.0.7)
52
+
53
+ PLATFORMS
54
+ ruby
55
+
56
+ DEPENDENCIES
57
+ bundler (~> 1.3)
58
+ cucumber
59
+ rake
60
+ sinatra
61
+ thin
62
+ unused_css!
63
+ watir-webdriver
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ Unused CSS
2
+ ==========
3
+
4
+ [![Build Status](https://travis-ci.org/christemple/unused-css.png?branch=master)](https://travis-ci.org/christemple/unused-css)
5
+
6
+ A Ruby gem, built from a need, to watch a suite of functional tests and gather all of the unused CSS styles.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rake'
2
+ require "bundler/gem_tasks"
3
+
4
+ desc "Start the application"
5
+ task :default do
6
+ start_application!
7
+ end
8
+
9
+ def start_application!
10
+ stop_application! if application_running?
11
+
12
+ fail "Failed to start app" unless system "thin start -d -p 3000"
13
+ wait_until do
14
+ application_running?
15
+ end
16
+ end
17
+
18
+ def stop_application!
19
+ system "kill -9 #{application_process_id}"
20
+ end
21
+
22
+ def application_running?
23
+ not `lsof -i tcp:3000 | grep LISTEN`.empty?
24
+ end
25
+
26
+ def application_process_id
27
+ `lsof -i tcp:3000 | grep LISTEN`.split[1]
28
+ end
29
+
30
+ def wait_until timeout=60
31
+ start_time = Time.now
32
+ until Time.now > start_time + timeout
33
+ return if yield
34
+ sleep 0.5
35
+ end
36
+ raise "action took too long"
37
+ end
data/app.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "sinatra"
2
+
3
+ get '/' do
4
+ erb :index
5
+ end
6
+
7
+ get '/multiple' do
8
+ erb :multiple
9
+ end
data/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require './app'
2
+
3
+ run Sinatra::Application
@@ -0,0 +1,26 @@
1
+ Feature: Home page
2
+
3
+ Scenario: Going to a page with a single stylesheet
4
+ Given I go to the home page
5
+ Then I should see style '#heading' was used
6
+ Then I should see style '.sub-heading' was not used
7
+
8
+
9
+ Scenario: Going to a page with more than one stylesheet
10
+ Given I go to a page with 2 stylesheets
11
+ Then I should see style '#heading' was used
12
+ Then I should see style '.notification' was used
13
+ Then I should see style '.sub-heading' was not used
14
+ Then I should see style '.sub-heading span' was not used
15
+ Then I should see style '.old-error' was not used
16
+
17
+
18
+ Scenario: Going to a page with styles for hover state
19
+ Given I go to a page with 2 stylesheets
20
+ Then I should see style '#heading' was used
21
+ Then I should see style '.notification' was used
22
+ Then I should see style '.notification:hover' was used
23
+ Then I should see style '.sub-heading' was not used
24
+ Then I should see style '.sub-heading span' was not used
25
+ Then I should see style '.old-error' was not used
26
+
@@ -0,0 +1,7 @@
1
+ Given "I go to the home page" do
2
+ $browser.goto('http://localhost:3000')
3
+ end
4
+
5
+ Given "I go to a page with 2 stylesheets" do
6
+ $browser.goto('http://localhost:3000/multiple')
7
+ end
@@ -0,0 +1,11 @@
1
+ Then "I should see '$text'" do |text|
2
+ fail "Can't find #{text}" unless $browser.text.include? text
3
+ end
4
+
5
+ Then "I should see style '$style' was used" do |style|
6
+ fail "#{style} style was not used" if $unused_css.stylesheets.styles.include? style
7
+ end
8
+
9
+ Then "I should see style '$style' was not used" do |style|
10
+ fail "#{style} style was used" unless $unused_css.stylesheets.styles.include? style
11
+ end
@@ -0,0 +1,12 @@
1
+ require "watir-webdriver"
2
+ require "unused_css"
3
+
4
+ system "rake"
5
+
6
+ $browser = Watir::Browser.new
7
+ $unused_css = UnusedCSS::Watcher.new
8
+ $unused_css.watch! $browser
9
+
10
+ at_exit do
11
+ $browser.close
12
+ end
@@ -0,0 +1,47 @@
1
+ require "css_parser"
2
+
3
+ class Stylesheet
4
+ attr_accessor :uri, :styles, :parser
5
+
6
+ def initialize (uri)
7
+ @styles = Set.new
8
+ @uri = uri
9
+ parse_styles!
10
+ end
11
+
12
+ def parse_styles!
13
+ @parser = CssParser::Parser.new
14
+ @parser.load_uri! @uri
15
+ @parser.each_selector { |styles| @styles << styles }
16
+ end
17
+
18
+ def remove_pseudo_styles!
19
+ @styles.delete_if { |style| style.match /::?[\w\-]+/ }
20
+ end
21
+ end
22
+
23
+
24
+ class Stylesheets
25
+ attr_accessor :stylesheets
26
+
27
+ def initialize
28
+ @stylesheets = []
29
+ end
30
+
31
+ def add uris
32
+ uris = Array(uris)
33
+ uris.each { |uri| @stylesheets << Stylesheet.new(uri) unless already_included? uri }
34
+ end
35
+
36
+ def already_included? uri
37
+ @stylesheets.any? { |stylesheet| stylesheet.uri == uri }
38
+ end
39
+
40
+ def [](uri)
41
+ @stylesheets.find { |stylesheet| stylesheet.uri == uri }
42
+ end
43
+
44
+ def styles
45
+ @stylesheets.inject(Set.new) {|styles, stylesheet| styles.merge stylesheet.styles }
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module UnusedCSS
2
+ VERSION = "0.0.1"
3
+ end
data/lib/unused_css.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "unused_css/version"
2
+ require "unused_css/stylesheet"
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
+ end
26
+ watir_browser.instance_exec self, &unused_css_block
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ .notification {
2
+ color: red;
3
+ font-size: 40px;
4
+ }
5
+
6
+ .notification:hover {
7
+ color: white;
8
+ background-color: red;
9
+ }
10
+
11
+ .old-error {
12
+ color: yellow;
13
+ font-size: 60px;
14
+ }
@@ -0,0 +1,14 @@
1
+ #heading {
2
+ font-size: 32px;
3
+ line-height: 36px;
4
+ }
5
+
6
+ .sub-heading {
7
+ font-size: 24px;
8
+ line-height: 28px;
9
+ }
10
+
11
+ .sub-heading span{
12
+ font-size: 24px;
13
+ line-height: 28px;
14
+ }
data/unused-css.iml ADDED
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$">
6
+ <excludeFolder url="file://$MODULE_DIR$/log" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="jdk" jdkName="RVM: ruby-2.0.0-p247 [unused-css]" jdkType="RUBY_SDK" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ <orderEntry type="library" scope="PROVIDED" name="addressable (v2.3.5, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
12
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
13
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.3.5, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
14
+ <orderEntry type="library" scope="PROVIDED" name="childprocess (v0.5.1, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="css_parser (v1.3.5, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="cucumber (v1.3.10, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="daemons (v1.1.9, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.2.5, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="eventmachine (v1.0.3, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.9.3, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="gherkin (v2.12.2, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.8.4, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="multi_test (v0.0.3, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="rack (v1.5.2, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="rack-protection (v1.5.2, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="rake (v10.1.1, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="rubyzip (v1.1.0, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="selenium-webdriver (v2.39.0, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="sinatra (v1.4.4, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="thin (v1.6.1, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="tilt (v1.4.1, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="watir-webdriver (v0.6.8, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="websocket (v1.0.7, RVM: ruby-2.0.0-p247 [unused-css]) [gem]" level="application" />
34
+ </component>
35
+ </module>
36
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'unused_css/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unused_css"
8
+ spec.version = UnusedCSS::VERSION
9
+ spec.authors = ["Chris Temple"]
10
+ spec.email = ["temple3188@gmail.com"]
11
+ spec.description = %q{A Ruby gem, built from a need, to watch a suite of functional tests and gather all of the unused CSS styles.}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/christemple/unused-css"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "css_parser"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sinatra"
26
+ spec.add_development_dependency "thin"
27
+ spec.add_development_dependency "cucumber"
28
+ spec.add_development_dependency "watir-webdriver"
29
+ end
data/views/index.erb ADDED
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Unused CSS</title>
6
+ <link rel="stylesheet" href="/stylesheets/style.css"/>
7
+ </head>
8
+ <body>
9
+ <div id="heading">Very nice</div>
10
+ <div class="old-error">No such style for old-error in style.css</div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Unused CSS</title>
6
+ <link rel="stylesheet" href="/stylesheets/style.css"/>
7
+ <link rel="stylesheet" href="/stylesheets/multiple.css"/>
8
+ </head>
9
+ <body>
10
+ <div id="heading">Very nice</div>
11
+ <div class="notification">Oops</div>
12
+ </body>
13
+ </html>
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unused_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Temple
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: css_parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thin
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: watir-webdriver
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A Ruby gem, built from a need, to watch a suite of functional tests and
112
+ gather all of the unused CSS styles.
113
+ email:
114
+ - temple3188@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .ruby-gemset
121
+ - .ruby-version
122
+ - .travis.yml
123
+ - Gemfile
124
+ - Gemfile.lock
125
+ - README.md
126
+ - Rakefile
127
+ - app.rb
128
+ - config.ru
129
+ - features/home_page.feature
130
+ - features/step_definitions/navigation_steps.rb
131
+ - features/step_definitions/observation_steps.rb
132
+ - features/support/env.rb
133
+ - lib/unused_css.rb
134
+ - lib/unused_css/stylesheet.rb
135
+ - lib/unused_css/version.rb
136
+ - public/stylesheets/multiple.css
137
+ - public/stylesheets/style.css
138
+ - unused-css.iml
139
+ - unused_css.gemspec
140
+ - views/index.erb
141
+ - views/multiple.erb
142
+ homepage: https://github.com/christemple/unused-css
143
+ licenses:
144
+ - MIT
145
+ metadata: {}
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubyforge_project:
162
+ rubygems_version: 2.0.6
163
+ signing_key:
164
+ specification_version: 4
165
+ summary: A Ruby gem, built from a need, to watch a suite of functional tests and gather
166
+ all of the unused CSS styles.
167
+ test_files:
168
+ - features/home_page.feature
169
+ - features/step_definitions/navigation_steps.rb
170
+ - features/step_definitions/observation_steps.rb
171
+ - features/support/env.rb