csscss 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/lib/csscss/cli.rb +40 -28
- data/lib/csscss/parser/css.rb +37 -2
- data/lib/csscss/sass_include_extensions.rb +19 -0
- data/lib/csscss/version.rb +1 -1
- data/test/csscss/parser/css_test.rb +44 -1
- data/test/csscss/sass_include_extensions_test.rb +45 -0
- metadata +6 -3
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.3.0 - 4/20/2013 ##
|
2
|
+
|
3
|
+
* Adds --require switch for user configuration
|
4
|
+
* Deprecates --compass-with-config config.rb in favor of --compass --require config.rb
|
5
|
+
* Ignores @import statements. Users will need to run csscss on those directly
|
6
|
+
* Adds --ignore-sass-mixins which won't match declarations coming from sass mixins
|
7
|
+
|
1
8
|
## 1.2.0 - 4/14/2013 ##
|
2
9
|
|
3
10
|
* 0 and 0px are now reconciled as redundancies
|
data/Gemfile.lock
CHANGED
data/lib/csscss/cli.rb
CHANGED
@@ -9,6 +9,7 @@ module Csscss
|
|
9
9
|
@ignored_properties = []
|
10
10
|
@ignored_selectors = []
|
11
11
|
@match_shorthand = true
|
12
|
+
@ignore_sass_mixins = false
|
12
13
|
end
|
13
14
|
|
14
15
|
def run
|
@@ -18,7 +19,7 @@ module Csscss
|
|
18
19
|
|
19
20
|
private
|
20
21
|
def execute
|
21
|
-
|
22
|
+
deprecate("Use --show-parser-errors instead of CSSCSS_DEBUG") if ENV["CSSCSS_DEBUG"]
|
22
23
|
|
23
24
|
all_contents= @argv.map do |filename|
|
24
25
|
if filename =~ URI.regexp
|
@@ -71,48 +72,61 @@ module Csscss
|
|
71
72
|
@verbose = v
|
72
73
|
end
|
73
74
|
|
74
|
-
opts.on("--[no-]color", "Colorize output (default is #{@color})") do |c|
|
75
|
+
opts.on("--[no-]color", "Colorize output", "(default is #{@color})") do |c|
|
75
76
|
@color = c
|
76
77
|
end
|
77
78
|
|
78
|
-
opts.on("-n", "--num N", Integer, "Print matches with at least this many rules.
|
79
|
+
opts.on("-n", "--num N", Integer, "Print matches with at least this many rules.", "(default is 3)") do |n|
|
79
80
|
@minimum = n
|
80
81
|
end
|
81
82
|
|
82
|
-
opts.on("--
|
83
|
-
@
|
83
|
+
opts.on("--[no-]match-shorthand", "Expand shorthand rules and matches on explicit rules", "(default is true)") do |match_shorthand|
|
84
|
+
@match_shorthand = match_shorthand
|
84
85
|
end
|
85
86
|
|
86
|
-
opts.on(
|
87
|
-
@
|
87
|
+
opts.on("-j", "--[no-]json", "Output results in JSON") do |j|
|
88
|
+
@json = j
|
88
89
|
end
|
89
90
|
|
90
|
-
opts.on("-
|
91
|
-
|
92
|
-
|
91
|
+
opts.on("--ignore-sass-mixins", "EXPERIMENTAL: Ignore matches that come from including sass/scss mixins",
|
92
|
+
"This is an experimental feature and may not be included in future releases",
|
93
|
+
"(default is false)") do |ignore|
|
94
|
+
@ignore_sass_mixins = ignore
|
93
95
|
end
|
94
96
|
|
95
97
|
opts.on("--[no-]compass", "Enable compass extensions when parsing sass/scss (default is false)") do |compass|
|
96
98
|
enable_compass if @compass = compass
|
97
99
|
end
|
98
100
|
|
99
|
-
opts.on("--compass-with-config config", "Enable compass extensions when parsing sass/scss and pass config file"
|
101
|
+
opts.on("--compass-with-config config", "Enable compass extensions when parsing sass/scss and pass config file",
|
102
|
+
"DEPRECATED: use --compass --require path/to/config.rb instead."
|
103
|
+
) do |config|
|
104
|
+
deprecate("Use --compass --require #{config} instead of --compass-with-config #{config}")
|
100
105
|
@compass = true
|
101
106
|
enable_compass(config)
|
102
107
|
end
|
103
108
|
|
104
|
-
opts.on("--
|
105
|
-
|
109
|
+
opts.on("--require file.rb", "Load ruby file before running csscss.", "Great for bootstrapping requires/configurations") do |file|
|
110
|
+
load file
|
106
111
|
end
|
107
112
|
|
108
|
-
opts.on("-
|
109
|
-
@
|
113
|
+
opts.on("--ignore-properties property1,property2,...", Array, "Ignore these properties when finding matches") do |ignored_properties|
|
114
|
+
@ignored_properties = ignored_properties
|
115
|
+
end
|
116
|
+
|
117
|
+
opts.on('--ignore-selectors "selector1","selector2",...', Array, "Ignore these selectors when finding matches") do |ignored_selectors|
|
118
|
+
@ignored_selectors = ignored_selectors
|
110
119
|
end
|
111
120
|
|
112
121
|
opts.on("--show-parser-errors", "Print verbose parser errors") do |show_parser_errors|
|
113
122
|
@show_parser_errors = show_parser_errors
|
114
123
|
end
|
115
124
|
|
125
|
+
opts.on("-V", "--version", "Show version") do |v|
|
126
|
+
puts opts.ver
|
127
|
+
exit
|
128
|
+
end
|
129
|
+
|
116
130
|
opts.on_tail("-h", "--help", "Show this message") do
|
117
131
|
print_help(opts)
|
118
132
|
end
|
@@ -129,20 +143,18 @@ module Csscss
|
|
129
143
|
exit
|
130
144
|
end
|
131
145
|
|
132
|
-
def
|
133
|
-
$stderr.puts
|
146
|
+
def deprecate(message)
|
147
|
+
$stderr.puts("DEPRECATED: #{message}".yellow)
|
134
148
|
end
|
135
149
|
|
136
150
|
def enable_compass(config = nil)
|
137
|
-
|
151
|
+
abort 'Must install the "compass" gem before enabling its extensions' unless gem_installed?("compass")
|
138
152
|
|
139
153
|
if config
|
140
154
|
Compass.add_configuration(config)
|
141
155
|
else
|
142
156
|
Compass.add_configuration("config.rb") if File.exist?("config.rb")
|
143
157
|
end
|
144
|
-
rescue LoadError
|
145
|
-
abort "Must install compass gem before enabling its extensions"
|
146
158
|
end
|
147
159
|
|
148
160
|
def windows_1_9
|
@@ -159,14 +171,17 @@ module Csscss
|
|
159
171
|
end
|
160
172
|
|
161
173
|
def load_sass_file(filename)
|
162
|
-
|
163
|
-
abort 'Must install the "sass" gem before parsing sass/scss files'
|
164
|
-
end
|
174
|
+
abort 'Must install the "sass" gem before parsing sass/scss files' unless gem_installed?("sass")
|
165
175
|
|
166
176
|
sass_options = {cache:false}
|
167
177
|
sass_options[:load_paths] = Compass.configuration.sass_load_paths if @compass
|
168
178
|
begin
|
169
|
-
Sass::Engine.for_file(filename, sass_options).
|
179
|
+
tree = Sass::Engine.for_file(filename, sass_options).to_tree
|
180
|
+
if @ignore_sass_mixins
|
181
|
+
require "csscss/sass_include_extensions"
|
182
|
+
Csscss::SassMixinVisitor.visit(tree)
|
183
|
+
end
|
184
|
+
tree.render
|
170
185
|
rescue Sass::SyntaxError => e
|
171
186
|
if e.message =~ /compass/ && !@compass
|
172
187
|
puts "Enable --compass option to use compass's extensions"
|
@@ -178,10 +193,7 @@ module Csscss
|
|
178
193
|
end
|
179
194
|
|
180
195
|
def load_less_file(filename)
|
181
|
-
|
182
|
-
abort 'Must install the "less" gem before parsing less files'
|
183
|
-
end
|
184
|
-
|
196
|
+
abort 'Must install the "less" gem before parsing less files' unless gem_installed?("less")
|
185
197
|
contents = load_css_file(filename)
|
186
198
|
Less::Parser.new.parse(contents).to_css
|
187
199
|
end
|
data/lib/csscss/parser/css.rb
CHANGED
@@ -36,12 +36,30 @@ module Csscss
|
|
36
36
|
space?
|
37
37
|
}
|
38
38
|
|
39
|
+
rule(:mixin_attributes) {
|
40
|
+
(
|
41
|
+
str('/* CSSCSS START MIXIN') >>
|
42
|
+
(str('*/').absent? >> any).repeat >>
|
43
|
+
str('*/') >>
|
44
|
+
(str('/* CSSCSS END MIXIN').absent? >> any).repeat >>
|
45
|
+
str('/* CSSCSS END MIXIN') >>
|
46
|
+
(str('*/').absent? >> any).repeat >>
|
47
|
+
str('*/') >>
|
48
|
+
space?
|
49
|
+
).as(:mixin)
|
50
|
+
}
|
51
|
+
|
39
52
|
rule(:ruleset) {
|
40
53
|
(
|
41
54
|
match["^{}"].repeat(1).as(:selector) >>
|
42
55
|
str("{") >>
|
43
56
|
space? >>
|
44
|
-
(
|
57
|
+
(
|
58
|
+
mixin_attributes |
|
59
|
+
comment |
|
60
|
+
attribute |
|
61
|
+
blank_attribute
|
62
|
+
).repeat(0).as(:properties) >>
|
45
63
|
str("}") >>
|
46
64
|
space?
|
47
65
|
).as(:ruleset)
|
@@ -58,8 +76,22 @@ module Csscss
|
|
58
76
|
).as(:nested_ruleset)
|
59
77
|
}
|
60
78
|
|
79
|
+
rule(:import) {
|
80
|
+
(
|
81
|
+
stri("@import") >>
|
82
|
+
match["^;"].repeat(1) >>
|
83
|
+
str(";") >>
|
84
|
+
space?
|
85
|
+
).as(:import)
|
86
|
+
}
|
87
|
+
|
61
88
|
rule(:blocks) {
|
62
|
-
space? >> (
|
89
|
+
space? >> (
|
90
|
+
comment |
|
91
|
+
import |
|
92
|
+
nested_ruleset |
|
93
|
+
ruleset
|
94
|
+
).repeat(1).as(:blocks) >> space?
|
63
95
|
}
|
64
96
|
|
65
97
|
root(:blocks)
|
@@ -70,6 +102,9 @@ module Csscss
|
|
70
102
|
rulesets
|
71
103
|
}
|
72
104
|
|
105
|
+
rule(import: simple(:import)) { [] }
|
106
|
+
rule(mixin: simple(:mixin)) { nil }
|
107
|
+
|
73
108
|
rule(comment: simple(:comment)) { nil }
|
74
109
|
|
75
110
|
rule(ruleset: {
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "sass"
|
2
|
+
|
3
|
+
module Csscss
|
4
|
+
class SassMixinVisitor < Sass::Tree::Visitors::Base
|
5
|
+
def self.visit(root)
|
6
|
+
new.send(:visit, root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def visit_mixindef(node)
|
10
|
+
begin_comment = Sass::Tree::CommentNode.new(["/* CSSCSS START MIXIN: #{node.name} */"], :normal)
|
11
|
+
end_comment = Sass::Tree::CommentNode.new(["/* CSSCSS END MIXIN: #{node.name} */"], :normal)
|
12
|
+
|
13
|
+
begin_comment.options = end_comment.options = {}
|
14
|
+
|
15
|
+
node.children.unshift(begin_comment)
|
16
|
+
node.children.push(end_comment)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/csscss/version.rb
CHANGED
@@ -104,7 +104,7 @@ module Csscss::Parser
|
|
104
104
|
])
|
105
105
|
end
|
106
106
|
|
107
|
-
it "recognizes media queries" do
|
107
|
+
it "recognizes @media queries" do
|
108
108
|
css = %$
|
109
109
|
@media only screen {
|
110
110
|
/* some comment */
|
@@ -129,12 +129,55 @@ module Csscss::Parser
|
|
129
129
|
])
|
130
130
|
end
|
131
131
|
|
132
|
+
it "ignores @import statements" do
|
133
|
+
css = %$
|
134
|
+
@import "foo.css";
|
135
|
+
@import "bar.css";
|
136
|
+
|
137
|
+
/*
|
138
|
+
.x {
|
139
|
+
padding: 3px;
|
140
|
+
}
|
141
|
+
*/
|
142
|
+
|
143
|
+
h1 {
|
144
|
+
outline: 1px;
|
145
|
+
}
|
146
|
+
$
|
147
|
+
|
148
|
+
trans(css).must_equal([
|
149
|
+
rs(sel("h1"), [dec("outline", "1px")])
|
150
|
+
])
|
151
|
+
end
|
152
|
+
|
132
153
|
it "ignores double semicolons" do
|
133
154
|
trans("h1 { display:none;;}").must_equal([
|
134
155
|
rs(sel("h1"), [dec("display", "none")])
|
135
156
|
])
|
136
157
|
end
|
137
158
|
|
159
|
+
it "ignores mixin selectors" do
|
160
|
+
css = %$
|
161
|
+
h1 {
|
162
|
+
/* CSSCSS START MIXIN: foo */
|
163
|
+
font-family: serif;
|
164
|
+
font-size: 10px;
|
165
|
+
display: block;
|
166
|
+
/* CSSCSS END MIXIN: foo */
|
167
|
+
|
168
|
+
/* CSSCSS START MIXIN: bar */
|
169
|
+
outline: 1px;
|
170
|
+
/* CSSCSS END MIXIN: bar */
|
171
|
+
|
172
|
+
float: left;
|
173
|
+
}
|
174
|
+
$
|
175
|
+
|
176
|
+
trans(css).must_equal([
|
177
|
+
rs(sel("h1"), [dec("float", "left")])
|
178
|
+
])
|
179
|
+
end
|
180
|
+
|
138
181
|
it "parses attributes with encoded data that include semicolons" do
|
139
182
|
trans(%$
|
140
183
|
.foo1 {
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "csscss/sass_include_extensions"
|
3
|
+
|
4
|
+
module Csscss
|
5
|
+
describe "sass import extensions" do
|
6
|
+
it "should do something" do
|
7
|
+
scss =<<-SCSS
|
8
|
+
@mixin foo {
|
9
|
+
font: {
|
10
|
+
family: serif;
|
11
|
+
size: 10px;
|
12
|
+
}
|
13
|
+
|
14
|
+
display: block;
|
15
|
+
}
|
16
|
+
|
17
|
+
@mixin bar {
|
18
|
+
outline: 1px;
|
19
|
+
}
|
20
|
+
|
21
|
+
h1 {
|
22
|
+
@include foo;
|
23
|
+
@include bar;
|
24
|
+
}
|
25
|
+
SCSS
|
26
|
+
|
27
|
+
|
28
|
+
css =<<-CSS
|
29
|
+
h1 {
|
30
|
+
/* CSSCSS START MIXIN: foo */
|
31
|
+
font-family: serif;
|
32
|
+
font-size: 10px;
|
33
|
+
display: block;
|
34
|
+
/* CSSCSS END MIXIN: foo */
|
35
|
+
/* CSSCSS START MIXIN: bar */
|
36
|
+
outline: 1px;
|
37
|
+
/* CSSCSS END MIXIN: bar */ }
|
38
|
+
CSS
|
39
|
+
|
40
|
+
tree = Sass::Engine.new(scss, syntax: :scss).to_tree
|
41
|
+
Csscss::SassMixinVisitor.visit(tree)
|
42
|
+
tree.render.must_equal(css)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
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: 1.
|
4
|
+
version: 1.3.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-04-
|
12
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/csscss/parslet_optimizations.rb
|
86
86
|
- lib/csscss/redundancy_analyzer.rb
|
87
87
|
- lib/csscss/reporter.rb
|
88
|
+
- lib/csscss/sass_include_extensions.rb
|
88
89
|
- lib/csscss/types.rb
|
89
90
|
- lib/csscss/version.rb
|
90
91
|
- test/csscss/json_reporter_test.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- test/csscss/parser/padding_test.rb
|
105
106
|
- test/csscss/redundancy_analyzer_test.rb
|
106
107
|
- test/csscss/reporter_test.rb
|
108
|
+
- test/csscss/sass_include_extensions_test.rb
|
107
109
|
- test/csscss/types_test.rb
|
108
110
|
- test/just_parse.rb
|
109
111
|
- test/test_helper.rb
|
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
129
|
version: '0'
|
128
130
|
segments:
|
129
131
|
- 0
|
130
|
-
hash:
|
132
|
+
hash: 2367732181301313903
|
131
133
|
requirements: []
|
132
134
|
rubyforge_project:
|
133
135
|
rubygems_version: 1.8.25
|
@@ -152,6 +154,7 @@ test_files:
|
|
152
154
|
- test/csscss/parser/padding_test.rb
|
153
155
|
- test/csscss/redundancy_analyzer_test.rb
|
154
156
|
- test/csscss/reporter_test.rb
|
157
|
+
- test/csscss/sass_include_extensions_test.rb
|
155
158
|
- test/csscss/types_test.rb
|
156
159
|
- test/just_parse.rb
|
157
160
|
- test/test_helper.rb
|