crass 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/HISTORY.md +8 -0
- data/lib/crass/parser.rb +7 -7
- data/lib/crass/version.rb +1 -1
- data/test/test_parse_properties.rb +107 -0
- data/test/test_serialization.rb +26 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3371590f5953c99ef49044bb7866a70568707f5c
|
4
|
+
data.tar.gz: 16bab682ee608b24dda34b8181cf1a4733a9d9c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77f57cca2304bf549e5ba35281364806634397b88ecdeda3310a1e38c17cff83346ef423db1b719b05c744281e4eedfbe85f5df4b9e5fb6883bf092efead5be2
|
7
|
+
data.tar.gz: 43d3a7ee5ae7670fffeb35c8843321a70d65447aea7f2ca8a650c8c772d2f8ad92804c20639137eae05296ad13a920a898f9735385d73d6811fdd026396c57fe
|
data/.travis.yml
CHANGED
data/HISTORY.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
Crass Change History
|
2
2
|
====================
|
3
3
|
|
4
|
+
1.0.2 (2015-04-17)
|
5
|
+
------------------
|
6
|
+
|
7
|
+
* Fixed: An at-rule immediately followed by a `{}` simple block would have the
|
8
|
+
block (and subsequent tokens until a semicolon) incorrectly appended to its
|
9
|
+
prelude. This was super dumb and made me very sad.
|
10
|
+
|
11
|
+
|
4
12
|
1.0.1 (2014-11-16)
|
5
13
|
------------------
|
6
14
|
|
data/lib/crass/parser.rb
CHANGED
@@ -133,7 +133,7 @@ module Crass
|
|
133
133
|
|
134
134
|
# Consumes an at-rule and returns it.
|
135
135
|
#
|
136
|
-
# 5.4.2. http://dev.w3.org/csswg/css-syntax-3/#consume-
|
136
|
+
# 5.4.2. http://dev.w3.org/csswg/css-syntax-3/#consume-at-rule
|
137
137
|
def consume_at_rule(input = @tokens)
|
138
138
|
rule = {}
|
139
139
|
|
@@ -142,15 +142,15 @@ module Crass
|
|
142
142
|
rule[:prelude] = []
|
143
143
|
|
144
144
|
while token = input.consume
|
145
|
-
|
146
|
-
|
147
|
-
|
145
|
+
node = token[:node]
|
146
|
+
|
147
|
+
if node == :comment # Non-standard.
|
148
148
|
next
|
149
149
|
|
150
|
-
|
150
|
+
elsif node == :semicolon
|
151
151
|
break
|
152
152
|
|
153
|
-
|
153
|
+
elsif node === :'{'
|
154
154
|
# Note: The spec says the block should _be_ the consumed simple
|
155
155
|
# block, but Simon Sapin's CSS parsing tests and tinycss2 expect
|
156
156
|
# only the _value_ of the consumed simple block here. I assume I'm
|
@@ -159,7 +159,7 @@ module Crass
|
|
159
159
|
rule[:block] = consume_simple_block(input)[:value]
|
160
160
|
break
|
161
161
|
|
162
|
-
|
162
|
+
elsif node == :simple_block && token[:start] == '{'
|
163
163
|
# Note: The spec says the block should _be_ the simple block, but
|
164
164
|
# Simon Sapin's CSS parsing tests and tinycss2 expect only the
|
165
165
|
# _value_ of the simple block here. I assume I'm interpreting the
|
data/lib/crass/version.rb
CHANGED
@@ -67,6 +67,113 @@ describe 'Crass::Parser' do
|
|
67
67
|
], tree)
|
68
68
|
end
|
69
69
|
|
70
|
+
it 'should parse at-rules with a {} simple block immediately following the prelude' do
|
71
|
+
tree = parse(%[
|
72
|
+
@page :right {
|
73
|
+
@top-center { content: "Preliminary edition" }
|
74
|
+
@bottom-center { content: counter(page) }
|
75
|
+
}
|
76
|
+
].strip)
|
77
|
+
|
78
|
+
tree = parse(tree.first[:block])
|
79
|
+
|
80
|
+
assert_equal([
|
81
|
+
{:node=>:whitespace, :pos=>14, :raw=>"\n "},
|
82
|
+
{:node=>:at_rule,
|
83
|
+
:name=>"top-center",
|
84
|
+
:prelude=>[{:node=>:whitespace, :pos=>36, :raw=>" "}],
|
85
|
+
:block=>
|
86
|
+
[{:node=>:whitespace, :pos=>38, :raw=>" "},
|
87
|
+
{:node=>:ident, :pos=>39, :raw=>"content", :value=>"content"},
|
88
|
+
{:node=>:colon, :pos=>46, :raw=>":"},
|
89
|
+
{:node=>:whitespace, :pos=>47, :raw=>" "},
|
90
|
+
{:node=>:string,
|
91
|
+
:pos=>48,
|
92
|
+
:raw=>"\"Preliminary edition\"",
|
93
|
+
:value=>"Preliminary edition"},
|
94
|
+
{:node=>:whitespace, :pos=>69, :raw=>" "}],
|
95
|
+
:tokens=>
|
96
|
+
[{:node=>:at_keyword, :pos=>25, :raw=>"@top-center", :value=>"top-center"},
|
97
|
+
{:node=>:whitespace, :pos=>36, :raw=>" "},
|
98
|
+
{:node=>:simple_block,
|
99
|
+
:start=>"{",
|
100
|
+
:end=>"}",
|
101
|
+
:value=>
|
102
|
+
[{:node=>:whitespace, :pos=>38, :raw=>" "},
|
103
|
+
{:node=>:ident, :pos=>39, :raw=>"content", :value=>"content"},
|
104
|
+
{:node=>:colon, :pos=>46, :raw=>":"},
|
105
|
+
{:node=>:whitespace, :pos=>47, :raw=>" "},
|
106
|
+
{:node=>:string,
|
107
|
+
:pos=>48,
|
108
|
+
:raw=>"\"Preliminary edition\"",
|
109
|
+
:value=>"Preliminary edition"},
|
110
|
+
{:node=>:whitespace, :pos=>69, :raw=>" "}],
|
111
|
+
:tokens=>
|
112
|
+
[{:node=>:"{", :pos=>37, :raw=>"{"},
|
113
|
+
{:node=>:whitespace, :pos=>38, :raw=>" "},
|
114
|
+
{:node=>:ident, :pos=>39, :raw=>"content", :value=>"content"},
|
115
|
+
{:node=>:colon, :pos=>46, :raw=>":"},
|
116
|
+
{:node=>:whitespace, :pos=>47, :raw=>" "},
|
117
|
+
{:node=>:string,
|
118
|
+
:pos=>48,
|
119
|
+
:raw=>"\"Preliminary edition\"",
|
120
|
+
:value=>"Preliminary edition"},
|
121
|
+
{:node=>:whitespace, :pos=>69, :raw=>" "},
|
122
|
+
{:node=>:"}", :pos=>70, :raw=>"}"}]}]},
|
123
|
+
{:node=>:whitespace, :pos=>71, :raw=>"\n "},
|
124
|
+
{:node=>:at_rule,
|
125
|
+
:name=>"bottom-center",
|
126
|
+
:prelude=>[{:node=>:whitespace, :pos=>96, :raw=>" "}],
|
127
|
+
:block=>
|
128
|
+
[{:node=>:whitespace, :pos=>98, :raw=>" "},
|
129
|
+
{:node=>:ident, :pos=>99, :raw=>"content", :value=>"content"},
|
130
|
+
{:node=>:colon, :pos=>106, :raw=>":"},
|
131
|
+
{:node=>:whitespace, :pos=>107, :raw=>" "},
|
132
|
+
{:node=>:function,
|
133
|
+
:name=>"counter",
|
134
|
+
:value=>[{:node=>:ident, :pos=>116, :raw=>"page", :value=>"page"}],
|
135
|
+
:tokens=>
|
136
|
+
[{:node=>:function, :pos=>108, :raw=>"counter(", :value=>"counter"},
|
137
|
+
{:node=>:ident, :pos=>116, :raw=>"page", :value=>"page"},
|
138
|
+
{:node=>:")", :pos=>120, :raw=>")"}]},
|
139
|
+
{:node=>:whitespace, :pos=>121, :raw=>" "}],
|
140
|
+
:tokens=>
|
141
|
+
[{:node=>:at_keyword,
|
142
|
+
:pos=>82,
|
143
|
+
:raw=>"@bottom-center",
|
144
|
+
:value=>"bottom-center"},
|
145
|
+
{:node=>:whitespace, :pos=>96, :raw=>" "},
|
146
|
+
{:node=>:simple_block,
|
147
|
+
:start=>"{",
|
148
|
+
:end=>"}",
|
149
|
+
:value=>
|
150
|
+
[{:node=>:whitespace, :pos=>98, :raw=>" "},
|
151
|
+
{:node=>:ident, :pos=>99, :raw=>"content", :value=>"content"},
|
152
|
+
{:node=>:colon, :pos=>106, :raw=>":"},
|
153
|
+
{:node=>:whitespace, :pos=>107, :raw=>" "},
|
154
|
+
{:node=>:function,
|
155
|
+
:name=>"counter",
|
156
|
+
:value=>[{:node=>:ident, :pos=>116, :raw=>"page", :value=>"page"}],
|
157
|
+
:tokens=>
|
158
|
+
[{:node=>:function, :pos=>108, :raw=>"counter(", :value=>"counter"},
|
159
|
+
{:node=>:ident, :pos=>116, :raw=>"page", :value=>"page"},
|
160
|
+
{:node=>:")", :pos=>120, :raw=>")"}]},
|
161
|
+
{:node=>:whitespace, :pos=>121, :raw=>" "}],
|
162
|
+
:tokens=>
|
163
|
+
[{:node=>:"{", :pos=>97, :raw=>"{"},
|
164
|
+
{:node=>:whitespace, :pos=>98, :raw=>" "},
|
165
|
+
{:node=>:ident, :pos=>99, :raw=>"content", :value=>"content"},
|
166
|
+
{:node=>:colon, :pos=>106, :raw=>":"},
|
167
|
+
{:node=>:whitespace, :pos=>107, :raw=>" "},
|
168
|
+
{:node=>:function, :pos=>108, :raw=>"counter(", :value=>"counter"},
|
169
|
+
{:node=>:ident, :pos=>116, :raw=>"page", :value=>"page"},
|
170
|
+
{:node=>:")", :pos=>120, :raw=>")"},
|
171
|
+
{:node=>:whitespace, :pos=>121, :raw=>" "},
|
172
|
+
{:node=>:"}", :pos=>122, :raw=>"}"}]}]},
|
173
|
+
{:node=>:whitespace, :pos=>123, :raw=>"\n "}
|
174
|
+
], tree)
|
175
|
+
end
|
176
|
+
|
70
177
|
it 'should parse values containing functions' do
|
71
178
|
tree = parse("content: attr(data-foo) \" \";")
|
72
179
|
|
data/test/test_serialization.rb
CHANGED
@@ -42,4 +42,30 @@ describe 'Serialization' do
|
|
42
42
|
Crass::Parser.stringify(tree)
|
43
43
|
)
|
44
44
|
end
|
45
|
+
|
46
|
+
it "should serialize a @page rule" do
|
47
|
+
css = %[
|
48
|
+
@page { margin: 2cm }
|
49
|
+
|
50
|
+
@page :right {
|
51
|
+
@top-center { content: "Preliminary edition" }
|
52
|
+
@bottom-center { content: counter(page) }
|
53
|
+
}
|
54
|
+
|
55
|
+
@page {
|
56
|
+
size: 8.5in 11in;
|
57
|
+
margin: 10%;
|
58
|
+
|
59
|
+
@top-left {
|
60
|
+
content: "Hamlet";
|
61
|
+
}
|
62
|
+
@top-right {
|
63
|
+
content: "Page " counter(page);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
].strip
|
67
|
+
|
68
|
+
tree = Crass.parse(css)
|
69
|
+
assert_equal(css, Crass::Parser.stringify(tree))
|
70
|
+
end
|
45
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Grove
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.4.5
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: CSS parser based on the CSS Syntax Level 3 spec.
|