habaki 0.5.1 → 0.5.2
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 +4 -4
- data/lib/habaki/declarations.rb +45 -14
- data/lib/habaki/formal_syntax.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee20d465ea2f474b8f107ecf41a360004ce2af899e743cd86670ed782627702
|
4
|
+
data.tar.gz: 59fb98647b7107ace1fbbc80e92d91520c06fa5853abdb1ef25cf65f28c78a73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e5593ac13b7eff2064fb75a51a26e829fda0658fdb3b2d1491f1bdd6212299e00516f6776a0436f9f43939f9739f875f8c73d77dd5e88e05bb5755cc789b21
|
7
|
+
data.tar.gz: e660626ccaee9bec98a5392bc57cc3dc2ede8526437e4056f6fd2c771a1b4e1c14eabcec6e5b9817fb71fc80a247b3678d1f87b8d73f78db0767255432a22a11
|
data/lib/habaki/declarations.rb
CHANGED
@@ -98,8 +98,8 @@ module Habaki
|
|
98
98
|
props[match.reference] << match.value
|
99
99
|
end
|
100
100
|
|
101
|
-
props.each do |
|
102
|
-
new_decl = add_by_property(
|
101
|
+
props.each do |prop, values|
|
102
|
+
new_decl = add_by_property(prop, values)
|
103
103
|
new_decl.position = declaration.position
|
104
104
|
end
|
105
105
|
|
@@ -122,10 +122,10 @@ module Habaki
|
|
122
122
|
border_style_properties = %w[border-width border-style border-color]
|
123
123
|
|
124
124
|
border_style_properties.each do |prop|
|
125
|
-
create_shorthand_properties! prop unless
|
125
|
+
create_shorthand_properties! prop unless has_property?(prop)
|
126
126
|
end
|
127
127
|
|
128
|
-
create_shorthand_properties! 'border' if border_style_properties.map{|prop|
|
128
|
+
create_shorthand_properties! 'border' if border_style_properties.map{|prop| has_property?(prop)}.all?
|
129
129
|
end
|
130
130
|
|
131
131
|
# Looks for long format CSS background properties (e.g. <tt>background-color</tt>) and
|
@@ -159,15 +159,37 @@ module Habaki
|
|
159
159
|
create_shorthand_properties! 'list-style'
|
160
160
|
end
|
161
161
|
|
162
|
+
def self.shorthand_properties(shorthand_property)
|
163
|
+
nodes = []
|
164
|
+
FormalSyntax::Tree.tree.property("--shorthand-"+shorthand_property).traverse do |node|
|
165
|
+
nodes << {type: node.type, value: node.value, next_value: node.parent&.children&.last&.value} if [:ref, :token].include?(node.type)
|
166
|
+
end
|
167
|
+
nodes
|
168
|
+
end
|
169
|
+
|
170
|
+
PRECOMPUTED_SHORTHAND_PROPS = {
|
171
|
+
"background" => shorthand_properties("background"),
|
172
|
+
"font" => shorthand_properties("font"),
|
173
|
+
"list-style" => shorthand_properties("list-style"),
|
174
|
+
"border" => shorthand_properties("border"),
|
175
|
+
"border-top" => shorthand_properties("border-top"),
|
176
|
+
"border-bottom" => shorthand_properties("border-bottom"),
|
177
|
+
"border-left" => shorthand_properties("border-left"),
|
178
|
+
"border-right" => shorthand_properties("border-right"),
|
179
|
+
"border-width" => shorthand_properties("border-width"),
|
180
|
+
"border-style" => shorthand_properties("border-style"),
|
181
|
+
"border-color" => shorthand_properties("border-color"),
|
182
|
+
}
|
183
|
+
|
162
184
|
# Combine several properties into a shorthand one
|
163
185
|
def create_shorthand_properties!(shorthand_property, need_all = false)
|
164
186
|
properties_to_delete = []
|
165
|
-
|
166
187
|
new_values = []
|
167
|
-
|
168
|
-
|
188
|
+
|
189
|
+
PRECOMPUTED_SHORTHAND_PROPS[shorthand_property].each do |node|
|
190
|
+
case node[:type]
|
169
191
|
when :ref
|
170
|
-
decl = find_by_property(node
|
192
|
+
decl = find_by_property(node[:value])
|
171
193
|
if decl
|
172
194
|
properties_to_delete << decl.property
|
173
195
|
new_values += decl.values
|
@@ -176,7 +198,7 @@ module Habaki
|
|
176
198
|
end
|
177
199
|
when :token
|
178
200
|
# only if next node property is present (line-height, background-size)
|
179
|
-
new_values << Operator.new(node
|
201
|
+
new_values << Operator.new(node[:value]) if node[:next_value] && has_property?(node[:next_value])
|
180
202
|
end
|
181
203
|
end
|
182
204
|
|
@@ -251,11 +273,6 @@ module Habaki
|
|
251
273
|
decls
|
252
274
|
end
|
253
275
|
|
254
|
-
def push_declaration(decl)
|
255
|
-
@hash[decl.property] = decl
|
256
|
-
push decl
|
257
|
-
end
|
258
|
-
|
259
276
|
# Parse inline declarations and append to current declarations
|
260
277
|
# @param [String] data
|
261
278
|
# @return [void]
|
@@ -268,6 +285,12 @@ module Habaki
|
|
268
285
|
end
|
269
286
|
end
|
270
287
|
|
288
|
+
# Does declaration with property present ?
|
289
|
+
# @return [Boolean]
|
290
|
+
def has_property?(property)
|
291
|
+
@hash.has_key?(property)
|
292
|
+
end
|
293
|
+
|
271
294
|
# Find declaration with property
|
272
295
|
# @param [String] property
|
273
296
|
# @return [Declaration]
|
@@ -342,5 +365,13 @@ module Habaki
|
|
342
365
|
push_declaration Declaration.read_from_katana(decl)
|
343
366
|
end
|
344
367
|
end
|
368
|
+
|
369
|
+
private
|
370
|
+
|
371
|
+
def push_declaration(decl)
|
372
|
+
@hash[decl.property] = decl
|
373
|
+
push decl
|
374
|
+
end
|
375
|
+
|
345
376
|
end
|
346
377
|
end
|
data/lib/habaki/formal_syntax.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: habaki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julien Boulnois
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: minitest
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|