csscss 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - 2.0.0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.0.0 - 4/7/2013 ##
2
+
3
+ * Allows the user to specify ignored properties and selectors
4
+ * Better parse error messages
5
+
1
6
  ## 0.2.1 - 3/28/2013 ##
2
7
 
3
8
  * Changes coloring to the selectors and declarations
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- csscss (0.2.1)
4
+ csscss (1.0.0)
5
5
  colorize
6
6
  parslet (~> 1.5)
7
7
 
data/lib/csscss/cli.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  module Csscss
2
2
  class CLI
3
3
  def initialize(argv)
4
- @argv = argv
5
- @verbose = false
6
- @color = true
7
- @minimum = 3
8
- @compass = false
4
+ @argv = argv
5
+ @verbose = false
6
+ @color = true
7
+ @minimum = 3
8
+ @compass = false
9
+ @ignored_properties = []
10
+ @ignored_selectors = []
9
11
  end
10
12
 
11
13
  def run
@@ -40,7 +42,9 @@ module Csscss
40
42
  open(filename) {|f| f.read }
41
43
  end
42
44
 
43
- RedundancyAnalyzer.new(contents).redundancies(@minimum)
45
+ RedundancyAnalyzer.new(contents).redundancies(minimum: @minimum,
46
+ ignored_properties: @ignored_properties,
47
+ ignored_selectors: @ignored_selectors)
44
48
  end
45
49
 
46
50
  combined_redundancies = all_redundancies.inject({}) do |combined, redundancies|
@@ -61,8 +65,13 @@ module Csscss
61
65
  end
62
66
 
63
67
  rescue Parslet::ParseFailed => e
64
- puts "Had a problem parsing the css"
65
- puts e.cause.ascii_tree
68
+ line, column = e.cause.source.line_and_column
69
+ puts "Had a problem parsing the css at line: #{line}, column: #{column}".red
70
+ if ENV['CSSCSS_DEBUG'] == 'true'
71
+ puts e.cause.ascii_tree.red
72
+ else
73
+ puts "Run with CSSCSS_DEBUG=true for verbose parser errors".red
74
+ end
66
75
  exit 1
67
76
  end
68
77
 
@@ -83,6 +92,14 @@ module Csscss
83
92
  @minimum = n
84
93
  end
85
94
 
95
+ opts.on("--ignore-properties property1,property2,...", Array, "Ignore these properties when finding matches") do |ignored_properties|
96
+ @ignored_properties = ignored_properties
97
+ end
98
+
99
+ opts.on('--ignore-selectors "selector1","selector2",...', Array, "Ignore these selectors when finding matches") do |ignored_selectors|
100
+ @ignored_selectors = ignored_selectors
101
+ end
102
+
86
103
  opts.on("-V", "--version", "Show version") do |v|
87
104
  puts opts.ver
88
105
  exit
@@ -5,13 +5,20 @@ module Csscss
5
5
  @raw_css = raw_css
6
6
  end
7
7
 
8
- def redundancies(minimum = nil)
8
+ def redundancies(opts = {})
9
+ minimum = opts[:minimum]
10
+ ignored_properties = opts[:ignored_properties] || []
11
+ ignored_selectors = opts[:ignored_selectors] || []
12
+
9
13
  rule_sets = Parser::Css.parse(@raw_css)
10
14
  matches = {}
11
15
  parents = {}
12
16
  rule_sets.each do |rule_set|
17
+ next if ignored_selectors.include?(rule_set.selectors.selectors)
18
+ sel = rule_set.selectors
19
+
13
20
  rule_set.declarations.each do |dec|
14
- sel = rule_set.selectors
21
+ next if ignored_properties.include?(dec.property)
15
22
 
16
23
  if parser = shorthand_parser(dec.property)
17
24
  if new_decs = parser.parse(dec.property, dec.value)
@@ -1,3 +1,3 @@
1
1
  module Csscss
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -22,7 +22,7 @@ module Csscss
22
22
  [sel(".bar"), sel("h1, h2")] , [dec("outline", "none"), dec("position", "relative")]
23
23
  ]
24
24
 
25
- RedundancyAnalyzer.new(css).redundancies(2).must_equal({
25
+ RedundancyAnalyzer.new(css).redundancies(minimum:2).must_equal({
26
26
  [sel(".bar"), sel("h1, h2")] => [dec("outline", "none"), dec("position", "relative")]
27
27
  })
28
28
  end
@@ -88,7 +88,7 @@ module Csscss
88
88
  }
89
89
  $
90
90
 
91
- redundancies = RedundancyAnalyzer.new(css).redundancies(3)
91
+ redundancies = RedundancyAnalyzer.new(css).redundancies(minimum:3)
92
92
  redundancies[[sel(".bar"), sel(".bar2"), sel(".baz")]].size.must_equal(5)
93
93
  end
94
94
 
@@ -230,7 +230,7 @@ module Csscss
230
230
  [sel(".bar"), sel(".baz"), sel(".foo")] => [dec("border-style", "solid"), dec("border-width", "4px")]
231
231
  })
232
232
 
233
- RedundancyAnalyzer.new(css).redundancies(2).must_equal({
233
+ RedundancyAnalyzer.new(css).redundancies(minimum:2).must_equal({
234
234
  [sel(".bar"), sel(".baz"), sel(".foo")] => [dec("border-style", "solid"), dec("border-width", "4px")]
235
235
  })
236
236
  end
@@ -248,6 +248,24 @@ module Csscss
248
248
  })
249
249
  end
250
250
 
251
+ it "ignores specific properties" do
252
+ css = %$
253
+ h1, h2 { display: none; position: relative; outline:none}
254
+ .foo { DISPLAY: none; width: 1px }
255
+ .bar { position: relative; width: 1px; outline: none }
256
+ .baz { display: none }
257
+ $
258
+
259
+ RedundancyAnalyzer.new(css).redundancies(ignored_properties:%w(display outline)).must_equal({
260
+ [sel(".bar"), sel("h1, h2")] => [dec("position", "relative")],
261
+ [sel(".bar"), sel(".foo")] => [dec("width", "1px")],
262
+ })
263
+
264
+ RedundancyAnalyzer.new(css).redundancies(ignored_properties:%w(display outline), ignored_selectors:%w(.foo)).must_equal({
265
+ [sel(".bar"), sel("h1, h2")] => [dec("position", "relative")]
266
+ })
267
+ end
268
+
251
269
  # TODO: someday
252
270
  # it "reports duplication within the same selector" do
253
271
  # css = %$
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csscss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
12
+ date: 2013-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parslet
@@ -120,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: -1849161592586961535
123
+ hash: 2330083466520748341
124
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  none: false
126
126
  requirements:
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: '0'
130
130
  segments:
131
131
  - 0
132
- hash: -1849161592586961535
132
+ hash: 2330083466520748341
133
133
  requirements: []
134
134
  rubyforge_project:
135
135
  rubygems_version: 1.8.25