dry_css 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc0ed26d7724ef6b7ecf1c9dc5d1483ff4ce006f
4
+ data.tar.gz: c6fc90223428c1cc543ecfd9b6867bc4649432b8
5
+ SHA512:
6
+ metadata.gz: d66200aceae8baf15828e905ea661cc636619d0bac385e53ed4310610b21977876a5dba0308be8e92f3ee81fa1fa0ac0f7cbe78bb6de383a2ecf696ab970329e
7
+ data.tar.gz: ae456c39dbc23c2e687ba219fc5a224f220df48ad45c78581ef51ec394e48be84197852f9b936b32861c22d385b8963cb512b70bbcf4603d2d2a2bb229ce8943
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dry_css.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 gpxl
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # DryCss
2
+
3
+ A gem for identifying redundant css
4
+
5
+ ## Usage
6
+
7
+ css = DryCss::CSS.new(uri)
8
+ css.colors
9
+
10
+ <small>more to come...</small>
11
+
12
+ ## Contributing
13
+
14
+ 1. Fork it
15
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
16
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
17
+ 4. Push to the branch (`git push origin my-new-feature`)
18
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
data/dry_css.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dry_css/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dry_css"
8
+ spec.version = DryCss::VERSION
9
+ spec.authors = ["gpxl"]
10
+ spec.email = ["gerlando@gmail.com"]
11
+ spec.description = %q{A gem for pointing out redundant css}
12
+ spec.summary = %q{A gem for pointing out redundant css (ironic?)}
13
+ spec.homepage = ""
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+
26
+ spec.add_runtime_dependency "css_parser"
27
+ end
@@ -0,0 +1,37 @@
1
+ module DryCss
2
+ class CSS
3
+ attr_reader :parser
4
+ def initialize(uri)
5
+ @parser = DryCss::Parser.new
6
+ @parser.load_uri!(uri)
7
+ end
8
+
9
+ def colors
10
+ @colors ||= scan_for(CssParser::RE_COLOUR)
11
+ end
12
+
13
+ def sorted(scan)
14
+ scan.sort_by{|k,v| v }.reverse
15
+ end
16
+
17
+ private
18
+
19
+ def scan_for(property)
20
+ @property = property
21
+ @values_hash = {}
22
+ @parser.each_selector do |selector, declarations, specificity|
23
+ if d_val = declarations.scan(/([\w-]+):[ ]?(#{@property})/)
24
+ d_val.each do |val|
25
+ if @values_hash[val[1].to_sym].nil?
26
+ @values_hash.merge!(val[1].to_sym => 1)
27
+ else
28
+ @values_hash[val[1].to_sym] += 1
29
+ end
30
+ end
31
+ end
32
+ end
33
+ return @values_hash
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,8 @@
1
+ require 'css_parser'
2
+
3
+ module DryCss
4
+ include CssParser
5
+ class Parser < CssParser::Parser
6
+ end
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module DryCss
2
+ VERSION = "0.0.1"
3
+ end
data/lib/dry_css.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative "dry_css/version"
2
+ Dir[File.dirname(__FILE__) + "/dry_css/*.rb"].each {|f| require f}
3
+
4
+ module DryCss
5
+ end
@@ -0,0 +1,8 @@
1
+ body {
2
+ background: #fff;
3
+ color: #000;
4
+ }
5
+
6
+ a {
7
+ color: #000;
8
+ }
@@ -0,0 +1,17 @@
1
+ require File.expand_path('../../spec_helper.rb', __FILE__)
2
+
3
+ describe DryCss::CSS do
4
+ before(:all) do
5
+ file_name = 'file://' + File.expand_path(File.dirname(__FILE__)) + '/../fixtures/example.css'
6
+ @css = DryCss::CSS.new(file_name)
7
+ end
8
+
9
+ it 'returns a CSSParser object' do
10
+ @css.parser.should be_a(DryCss::Parser)
11
+ end
12
+
13
+ it 'returns array of color values' do
14
+ @css.colors.should eq({:"#fff;"=>1, :"#000;"=>2})
15
+ end
16
+
17
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe DryCss do
4
+ end
5
+
@@ -0,0 +1 @@
1
+ require 'dry_css'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry_css
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - gpxl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: webmock
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: css_parser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A gem for pointing out redundant css
84
+ email:
85
+ - gerlando@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - dry_css.gemspec
96
+ - lib/dry_css.rb
97
+ - lib/dry_css/css.rb
98
+ - lib/dry_css/parser.rb
99
+ - lib/dry_css/version.rb
100
+ - spec/fixtures/example.css
101
+ - spec/lib/css_spec.rb
102
+ - spec/lib/dry_css_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.0.3
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A gem for pointing out redundant css (ironic?)
128
+ test_files:
129
+ - spec/fixtures/example.css
130
+ - spec/lib/css_spec.rb
131
+ - spec/lib/dry_css_spec.rb
132
+ - spec/spec_helper.rb