visualci-gallery 0.2.1 → 0.3.0
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/README.md +1 -1
- data/app/assets/javascripts/visualci_gallery.js +1280 -466
- data/app/assets/stylesheets/visualci_gallery.css +93 -25
- data/lib/visualci/gallery/renderer.rb +141 -55
- data/lib/visualci/gallery/version.rb +1 -1
- data/lib/visualci/gallery.rb +254 -77
- metadata +1 -1
data/lib/visualci/gallery.rb
CHANGED
|
@@ -25,20 +25,27 @@ module VisualCI
|
|
|
25
25
|
|
|
26
26
|
DEFAULT_TITLE = 'Screenshots'
|
|
27
27
|
SEE_ALL_TEXT = 'See all screenshots'
|
|
28
|
-
SIZES = %w[desktop phone].freeze
|
|
29
|
-
THEMES = %w[light dark].freeze
|
|
30
28
|
# The largest width or height (SPEC.md, "Validation"): the density maths stays exact in every language.
|
|
31
29
|
MAX_SIZE = 1_000_000
|
|
32
|
-
SIZE_LABEL = { 'desktop' => 'Desktop', 'phone' => 'Phone' }.freeze
|
|
33
30
|
# The largest size in bytes or preload cap: a whole number every language holds exactly.
|
|
34
31
|
MAX_CAP = 1_000_000_000_000
|
|
35
32
|
# The preloader's caps when the site sets none (SPEC.md, "Options").
|
|
36
33
|
PRELOAD_DEFAULTS = { 'fold' => 250, 'count' => 500, 'bytes' => 50_000_000, 'parallel' => 4 }.freeze
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
# The two built-in dimensions (SPEC.md, "Dimensions"), as the model has them.
|
|
35
|
+
DEFAULT_DIMENSIONS = [
|
|
36
|
+
{ 'key' => 'theme', 'label' => 'Theme', 'missing' => 'error',
|
|
37
|
+
'values' => [{ 'key' => 'light', 'label' => 'Light', 'below' => nil, 'shape' => nil },
|
|
38
|
+
{ 'key' => 'dark', 'label' => 'Dark', 'below' => nil, 'shape' => nil }] },
|
|
39
|
+
{ 'key' => 'size', 'label' => 'Screen size', 'missing' => 'hide',
|
|
40
|
+
'values' => [{ 'key' => 'desktop', 'label' => 'Desktop', 'below' => nil, 'shape' => nil },
|
|
41
|
+
{ 'key' => 'phone', 'label' => 'Phone', 'below' => 768, 'shape' => nil }] }
|
|
42
|
+
].map { |d| d.merge('values' => d['values'].map(&:freeze).freeze).freeze }.freeze
|
|
43
|
+
MISSING = %w[error hide first].freeze
|
|
44
|
+
|
|
45
|
+
# Whole-string matches, ASCII digits only, so every language's regex engine agrees (SPEC.md, "A shot's name").
|
|
39
46
|
EXTENSION = /\.(?:[pP][nN][gG]|[jJ][pP][eE]?[gG]|[wW][eE][bB][pP])\z/
|
|
40
|
-
|
|
41
|
-
|
|
47
|
+
KEY = /\A[a-z0-9]+(-[a-z0-9]+)*\z/
|
|
48
|
+
DIGITS = /\A[0-9]+\z/
|
|
42
49
|
ABSOLUTE = %r{\A[hH][tT][tT][pP][sS]?://[^\x00-\x20\x7f]+\z}
|
|
43
50
|
CONTROL = /[\x00-\x20\x7f]/
|
|
44
51
|
SCHEME = /\A[A-Za-z][A-Za-z0-9+.-]*:/
|
|
@@ -85,15 +92,18 @@ module VisualCI
|
|
|
85
92
|
end
|
|
86
93
|
|
|
87
94
|
# The model (SPEC.md, "The model") as a Hash with the same keys as the fixtures' model.json.
|
|
88
|
-
def model(manifest, title: UNSET, heading_level: nil, id: nil,
|
|
89
|
-
group_order: nil, credit: nil, layout: nil, theme_switch: nil, see_all: nil, preload: nil)
|
|
95
|
+
def model(manifest, title: UNSET, heading_level: nil, id: nil, dimensions: nil, screens: nil, order: nil,
|
|
96
|
+
groups: nil, group_order: nil, credit: nil, layout: nil, theme_switch: nil, see_all: nil, preload: nil)
|
|
90
97
|
check_manifest(manifest)
|
|
91
98
|
# Options in the contract's order (SPEC.md, "Validation"): the first problem is the error.
|
|
92
99
|
level = opt(heading_level, 'headingLevel') { |v| integral?(v) }
|
|
93
100
|
title = title.equal?(UNSET) ? DEFAULT_TITLE : opt(title, 'title') { |v| v.is_a?(String) }
|
|
94
101
|
id = opt(id, 'id') { |v| v.is_a?(String) && ID.match?(v) } || 'vg'
|
|
102
|
+
given = opt(dimensions, 'dimensions') { |v| dimensions?(v) }
|
|
103
|
+
dims = resolve_dimensions(given && given.map { |d| dimension_entry(d) })
|
|
104
|
+
size_values = dims.find { |d| d['key'] == 'size' }['values']
|
|
95
105
|
screens_opt = texts(screens, 'screens', %w[title caption])
|
|
96
|
-
groups_opt = group_options(groups)
|
|
106
|
+
groups_opt = group_options(groups, size_values.map { |v| v['key'] })
|
|
97
107
|
order = strings(order, 'order')
|
|
98
108
|
group_order = strings(group_order, 'groupOrder')
|
|
99
109
|
credit = opt(credit, 'credit') { |v| boolean?(v) }
|
|
@@ -101,7 +111,10 @@ module VisualCI
|
|
|
101
111
|
layout = opt(layout, 'layout') { |v| %w[grid strip].include?(v.to_s) }&.to_s || 'grid'
|
|
102
112
|
see_all = opt(see_all, 'seeAll') { |v| see_all?(v) }
|
|
103
113
|
preload = opt(preload, 'preload') { |v| preload?(v) }
|
|
104
|
-
|
|
114
|
+
built = build_groups(manifest, dims, screens_opt, groups_opt, order, group_order)
|
|
115
|
+
raise Error, 'the gallery manifest has no screenshots to show' if built.empty?
|
|
116
|
+
|
|
117
|
+
{
|
|
105
118
|
'layout' => layout,
|
|
106
119
|
'themeSwitch' => layout == 'grid' && switch != false,
|
|
107
120
|
'seeAll' => see_all && { 'href' => fetch_key(see_all, 'href'), 'text' => fetch_key(see_all, 'text') || SEE_ALL_TEXT },
|
|
@@ -109,30 +122,77 @@ module VisualCI
|
|
|
109
122
|
'label' => title || DEFAULT_TITLE,
|
|
110
123
|
'headingLevel' => (level ? level.to_i : 2).clamp(1, 4),
|
|
111
124
|
'id' => id,
|
|
112
|
-
'credit' => credit.nil? ?
|
|
125
|
+
'credit' => credit.nil? ? false : credit,
|
|
113
126
|
'preload' => preload_model(preload),
|
|
114
|
-
'
|
|
127
|
+
'dimensions' => with_shapes(dims, built),
|
|
128
|
+
'groups' => built
|
|
115
129
|
}
|
|
116
|
-
raise Error, 'the gallery manifest has no screenshots to show' if model['groups'].empty?
|
|
117
|
-
|
|
118
|
-
model
|
|
119
130
|
end
|
|
120
131
|
|
|
121
|
-
# How a manifest name pairs (SPEC.md, "A shot's name"):
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
# How a manifest name pairs (SPEC.md, "A shot's name"): trailing `-`-separated tokens that are value keys, a CSS
|
|
133
|
+
# width and `2x` are peeled off the end, and the rest is the screen's key. `values` has the value the name gives
|
|
134
|
+
# by dimension key; a dimension it gives none of stands for every value.
|
|
135
|
+
def parse_shot(name, dimensions = DEFAULT_DIMENSIONS)
|
|
136
|
+
base = name.sub(EXTENSION, '')
|
|
137
|
+
parts = base.split('/', -1)
|
|
124
138
|
parts = [''] if parts.empty? # "".split gives [] in Ruby, [""] in JavaScript
|
|
125
139
|
last = parts.pop
|
|
126
140
|
folder = parts.join('/')
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
owner = {}
|
|
142
|
+
dimensions.each { |d| d['values'].each { |v| owner[v['key']] = d['key'] } }
|
|
143
|
+
tokens = last.split('-', -1)
|
|
144
|
+
tokens = [''] if tokens.empty?
|
|
145
|
+
x2 = false
|
|
146
|
+
if tokens.last == '2x'
|
|
147
|
+
tokens.pop
|
|
148
|
+
x2 = true
|
|
130
149
|
end
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
150
|
+
values = {}
|
|
151
|
+
css_width = nil
|
|
152
|
+
named = false
|
|
153
|
+
loop do
|
|
154
|
+
peeled = false
|
|
155
|
+
tokens.length.downto(1) do |n|
|
|
156
|
+
dim = owner[tokens.last(n).join('-')]
|
|
157
|
+
next if dim.nil? || values.key?(dim)
|
|
158
|
+
|
|
159
|
+
values[dim] = tokens.last(n).join('-')
|
|
160
|
+
tokens.pop(n)
|
|
161
|
+
named = peeled = true
|
|
162
|
+
break
|
|
163
|
+
end
|
|
164
|
+
next if peeled
|
|
165
|
+
|
|
166
|
+
if css_width.nil? && !tokens.empty? && DIGITS.match?(tokens.last)
|
|
167
|
+
css_width = tokens.pop.to_i
|
|
168
|
+
next
|
|
169
|
+
end
|
|
170
|
+
break
|
|
134
171
|
end
|
|
135
|
-
|
|
172
|
+
# `<screen>/<width>` (the last part only a width, under a folder) pairs by its folder.
|
|
173
|
+
width_only = !css_width.nil? && tokens.empty? && folder != ''
|
|
174
|
+
return { key: base, values: {}, x2: false, css_width: nil } if (!named && !width_only) || (tokens.empty? && folder == '')
|
|
175
|
+
|
|
176
|
+
rest = tokens.join('-')
|
|
177
|
+
key = if tokens.empty? then folder
|
|
178
|
+
elsif folder == '' then rest
|
|
179
|
+
else "#{folder}/#{rest}"
|
|
180
|
+
end
|
|
181
|
+
{ key: key, values: values, x2: x2, css_width: css_width }
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# A shot's size: the one its name gives, else the one its CSS width falls under, else the group's, else by the
|
|
185
|
+
# image's shape.
|
|
186
|
+
def size_of(shot, sizes, width, height, group_size)
|
|
187
|
+
return shot[:values]['size'] if shot[:values].key?('size')
|
|
188
|
+
|
|
189
|
+
open = sizes.find { |v| v['below'].nil? }['key']
|
|
190
|
+
bounded = sizes.each_with_index.reject { |v, _| v['below'].nil? }.sort_by { |v, i| [v['below'], i] }.map(&:first)
|
|
191
|
+
w = shot[:css_width]
|
|
192
|
+
return bounded.find { |v| w < v['below'] }&.dig('key') || open unless w.nil?
|
|
193
|
+
return group_size unless group_size.nil?
|
|
194
|
+
|
|
195
|
+
height > width && !bounded.empty? ? bounded[0]['key'] : open
|
|
136
196
|
end
|
|
137
197
|
|
|
138
198
|
# `billing/free` → "Billing, free".
|
|
@@ -154,22 +214,71 @@ module VisualCI
|
|
|
154
214
|
text.to_s.gsub('&', '&').gsub('<', '<').gsub('>', '>').gsub('"', '"').gsub("'", ''')
|
|
155
215
|
end
|
|
156
216
|
|
|
157
|
-
def build_groups(manifest, screens_opt, groups_opt, order, group_order)
|
|
217
|
+
def build_groups(manifest, dims, screens_opt, groups_opt, order, group_order)
|
|
158
218
|
slugs = {}
|
|
219
|
+
size_values = dims.find { |d| d['key'] == 'size' }['values']
|
|
159
220
|
groups = manifest['groups'].filter_map do |g|
|
|
160
221
|
set = groups_opt[g['name']] || {}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
222
|
+
shots = g['items'].map do |item|
|
|
223
|
+
shot = parse_shot(item['name'], dims)
|
|
224
|
+
size = size_of(shot, size_values, item['width'].to_i, item['height'].to_i, set['size'])
|
|
225
|
+
[item, shot.merge(values: shot[:values].merge('size' => size))]
|
|
226
|
+
end
|
|
227
|
+
# The group's values of each dimension: those its items name, else the dimension's first.
|
|
228
|
+
named = dims.to_h do |d|
|
|
229
|
+
keys = d['values'].map { |v| v['key'] }.select { |k| shots.any? { |_, shot| shot[:values][d['key']] == k } }
|
|
230
|
+
[d['key'], keys.empty? ? [d['values'][0]['key']] : keys]
|
|
231
|
+
end
|
|
232
|
+
screens = {}
|
|
233
|
+
shots.each do |item, shot|
|
|
234
|
+
variants = (screens[shot[:key]] ||= {})
|
|
235
|
+
combinations(dims) { |d| shot[:values].key?(d['key']) ? [shot[:values][d['key']]] : named[d['key']] }.each do |values|
|
|
236
|
+
vid = dims.map { |d| values[d['key']] }.join('.')
|
|
237
|
+
v = (variants[vid] ||= { 'values' => values, 'url' => '', 'url2x' => nil, 'width' => 0, 'height' => 0,
|
|
238
|
+
'bytes' => nil, 'bytes2x' => nil, 'thumb' => nil })
|
|
239
|
+
if shot[:x2]
|
|
240
|
+
if v['url2x'].nil?
|
|
241
|
+
v['url2x'] = item['url']
|
|
242
|
+
v['bytes2x'] = item['bytes']&.to_i
|
|
243
|
+
end
|
|
244
|
+
elsif v['url'] == ''
|
|
245
|
+
# An image wider than the width its name gives was taken at a higher density: shown at the name's
|
|
246
|
+
# width, its height rounded half up in integers (the same in every language).
|
|
247
|
+
width = item['width'].to_i
|
|
248
|
+
height = item['height'].to_i
|
|
249
|
+
w = shot[:css_width]
|
|
250
|
+
scaled = !w.nil? && width > w
|
|
251
|
+
v['url'] = item['url']
|
|
252
|
+
v['width'] = scaled ? w : width
|
|
253
|
+
v['height'] = scaled ? (2 * height * w + width) / (2 * width) : height
|
|
254
|
+
v['bytes'] = item['bytes']&.to_i
|
|
255
|
+
if (t = item['thumb'])
|
|
256
|
+
v['thumb'] = { 'url' => t['url'], 'width' => t['width'].to_i, 'height' => t['height'].to_i,
|
|
257
|
+
'bytes' => t['bytes']&.to_i }
|
|
258
|
+
end
|
|
259
|
+
end
|
|
169
260
|
end
|
|
170
261
|
end
|
|
262
|
+
rank_of = ->(v) { dims.map { |d| d['values'].index { |x| x['key'] == v['values'][d['key']] } } }
|
|
263
|
+
# The screens that have something to show; titles are made from these keys only.
|
|
264
|
+
kept = screens.filter_map do |key, variants|
|
|
265
|
+
list = variants.values.reject { |v| v['url'] == '' }.sort_by(&rank_of)
|
|
266
|
+
[key, list] unless list.empty?
|
|
267
|
+
end
|
|
171
268
|
next if kept.empty?
|
|
172
269
|
|
|
270
|
+
values = values_of(dims, kept.flat_map(&:last))
|
|
271
|
+
# Every combination a screen should have: the group's values of each "error" dimension, the screen's own of
|
|
272
|
+
# the rest. One theme's picture never stands in for another's.
|
|
273
|
+
kept.each do |key, variants|
|
|
274
|
+
own = values_of(dims, variants)
|
|
275
|
+
have = variants.to_h { |v| [dims.map { |d| v['values'][d['key']] }.join('.'), true] }
|
|
276
|
+
combinations(dims) { |d| d['missing'] == 'error' ? values[d['key']] : own[d['key']] }.each do |combo|
|
|
277
|
+
keys = dims.map { |d| combo[d['key']] }
|
|
278
|
+
raise Error, "gallery screen #{key} in group #{g['name']} has no #{keys.join(' ')} screenshot" unless have[keys.join('.')]
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
173
282
|
prefix = common_folder(kept.map(&:first)).length
|
|
174
283
|
list = kept.map do |key, variants|
|
|
175
284
|
screen = screens_opt[key] || {}
|
|
@@ -186,48 +295,117 @@ module VisualCI
|
|
|
186
295
|
end
|
|
187
296
|
slugs[slug] = true
|
|
188
297
|
{ 'name' => g['name'], 'title' => set['title'] || g['title'] || g['name'],
|
|
189
|
-
'slug' => slug, 'fit' => set['fit'] || 'cover', '
|
|
190
|
-
'screens' => list }
|
|
298
|
+
'slug' => slug, 'fit' => set['fit'] || 'cover', 'values' => values, 'screens' => list }
|
|
191
299
|
end
|
|
192
300
|
groups.each_with_index.sort_by { |g, i| [rank(group_order, g['name']), i] }.map(&:first)
|
|
193
301
|
end
|
|
194
302
|
|
|
195
|
-
#
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
303
|
+
# Every combination of one value per dimension, the first dimension varying slowest, each in the order the block
|
|
304
|
+
# gives.
|
|
305
|
+
def combinations(dims, &values_for)
|
|
306
|
+
dims.reduce([{}]) { |out, d| out.flat_map { |c| values_for.call(d).map { |k| c.merge(d['key'] => k) } } }
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
# The value keys some of `variants` have, per dimension, in each dimension's order.
|
|
310
|
+
def values_of(dims, variants)
|
|
311
|
+
dims.to_h do |d|
|
|
312
|
+
[d['key'], d['values'].map { |v| v['key'] }.select { |k| variants.any? { |v| v['values'][d['key']] == k } }]
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# Each size value's shape: portrait when more of its variants are taller than wide than aren't.
|
|
317
|
+
def with_shapes(dims, groups)
|
|
318
|
+
variants = groups.flat_map { |g| g['screens'].flat_map { |sc| sc['variants'] } }
|
|
319
|
+
dims.map do |d|
|
|
320
|
+
next d unless d['key'] == 'size'
|
|
321
|
+
|
|
322
|
+
d.merge('values' => d['values'].map do |v|
|
|
323
|
+
at = variants.select { |x| x['values']['size'] == v['key'] }
|
|
324
|
+
tall = at.count { |x| x['height'] > x['width'] }
|
|
325
|
+
v.merge('shape' => tall > at.length - tall ? 'portrait' : 'landscape')
|
|
326
|
+
end)
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
# A dimension entry or value with string keys (a Ruby caller may use symbols), and its key and missing as strings.
|
|
331
|
+
def dimension_entry(entry)
|
|
332
|
+
return entry unless entry.is_a?(Hash)
|
|
333
|
+
|
|
334
|
+
entry = entry.to_h { |k, x| [k.to_s, x] }
|
|
335
|
+
%w[key missing].each { |k| entry[k] = entry[k].to_s if entry[k].is_a?(Symbol) }
|
|
336
|
+
entry['values'] = entry['values'].map { |v| dimension_entry(v) } if entry['values'].is_a?(Array)
|
|
337
|
+
entry
|
|
338
|
+
end
|
|
339
|
+
|
|
340
|
+
# The `dimensions` option's shape (SPEC.md, "Validation").
|
|
341
|
+
def dimensions?(list)
|
|
342
|
+
return false unless list.is_a?(Array)
|
|
343
|
+
|
|
344
|
+
list = list.map { |d| dimension_entry(d) }
|
|
345
|
+
keys = {}
|
|
346
|
+
value_keys = {}
|
|
347
|
+
# Not only digits (a width), and not ending in "2x" (a name's last "2x" marks a high-density copy).
|
|
348
|
+
value_key = ->(k) { k.is_a?(String) && KEY.match?(k) && !DIGITS.match?(k) && !/(\A|-)2x\z/.match?(k) }
|
|
349
|
+
list.each do |d|
|
|
350
|
+
return false unless d.is_a?(Hash) && d.keys.all? { |k| %w[key label missing values].include?(k) }
|
|
351
|
+
return false unless d['key'].is_a?(String) && KEY.match?(d['key']) && !keys[d['key']]
|
|
352
|
+
|
|
353
|
+
keys[d['key']] = true
|
|
354
|
+
built_in = %w[theme size].include?(d['key'])
|
|
355
|
+
return false unless d['label'].nil? || d['label'].is_a?(String)
|
|
356
|
+
return false unless d['missing'].nil? || MISSING.include?(d['missing'])
|
|
357
|
+
|
|
358
|
+
if d['values'].nil?
|
|
359
|
+
return false unless built_in
|
|
360
|
+
|
|
361
|
+
next
|
|
362
|
+
end
|
|
363
|
+
return false unless d['values'].is_a?(Array) && !d['values'].empty?
|
|
364
|
+
|
|
365
|
+
d['values'].each do |v|
|
|
366
|
+
return false unless v.is_a?(Hash) && v.keys.all? { |k| %w[key label below].include?(k) }
|
|
367
|
+
return false unless value_key.call(v['key']) && !value_keys[v['key']]
|
|
368
|
+
|
|
369
|
+
value_keys[v['key']] = true
|
|
370
|
+
return false unless v['label'].nil? || v['label'].is_a?(String)
|
|
371
|
+
return false unless v['below'].nil? || (d['key'] == 'size' && positive_integral?(v['below']))
|
|
372
|
+
end
|
|
373
|
+
return false if d['key'] == 'size' && d['values'].none? { |v| v['below'].nil? }
|
|
374
|
+
end
|
|
375
|
+
# The built-in values a dimension doesn't replace still count.
|
|
376
|
+
DEFAULT_DIMENSIONS.each do |d|
|
|
377
|
+
next if list.any? { |x| x['key'] == d['key'] && x['values'].is_a?(Array) }
|
|
378
|
+
|
|
379
|
+
d['values'].each do |v|
|
|
380
|
+
return false if value_keys[v['key']]
|
|
381
|
+
|
|
382
|
+
value_keys[v['key']] = true
|
|
224
383
|
end
|
|
225
384
|
end
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
385
|
+
true
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# The built-in dimensions with the option's changes, then the option's own.
|
|
389
|
+
def resolve_dimensions(given)
|
|
390
|
+
given ||= []
|
|
391
|
+
resolve = lambda do |d, base|
|
|
392
|
+
{ 'key' => d['key'],
|
|
393
|
+
'label' => d['label'] || base&.dig('label') || d['key'],
|
|
394
|
+
'missing' => d['missing'] || base&.dig('missing') || 'first',
|
|
395
|
+
'values' => if d['values']
|
|
396
|
+
d['values'].map do |v|
|
|
397
|
+
{ 'key' => v['key'], 'label' => v['label'] || v['key'], 'below' => v['below']&.to_i, 'shape' => nil }
|
|
398
|
+
end
|
|
399
|
+
else
|
|
400
|
+
base['values'].map(&:dup)
|
|
401
|
+
end }
|
|
402
|
+
end
|
|
403
|
+
out = DEFAULT_DIMENSIONS.map do |base|
|
|
404
|
+
d = given.find { |x| x['key'] == base['key'] }
|
|
405
|
+
d ? resolve.call(d, base) : base.merge('values' => base['values'].map(&:dup))
|
|
230
406
|
end
|
|
407
|
+
given.each { |d| out << resolve.call(d, nil) unless DEFAULT_DIMENSIONS.any? { |base| base['key'] == d['key'] } }
|
|
408
|
+
out
|
|
231
409
|
end
|
|
232
410
|
|
|
233
411
|
def common_folder(keys)
|
|
@@ -325,17 +503,15 @@ module VisualCI
|
|
|
325
503
|
opt(value, name) { |v| v.is_a?(Array) && v.all?(String) } || []
|
|
326
504
|
end
|
|
327
505
|
|
|
328
|
-
# {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
# groups: {name => {title, size, fit}}; size and fit take their words as strings or symbols.
|
|
332
|
-
def group_options(value)
|
|
506
|
+
# groups: {name => {title, size, fit}}; size (one of `sizes`) and fit take their words as strings or symbols.
|
|
507
|
+
def group_options(value, sizes)
|
|
508
|
+
words = { 'size' => sizes, 'fit' => %w[cover contain] }
|
|
333
509
|
opt(value, 'groups') do |v|
|
|
334
510
|
v.is_a?(Hash) && v.values.all? do |entry|
|
|
335
511
|
entry.is_a?(Hash) && entry.all? do |k, x|
|
|
336
512
|
k = k.to_s
|
|
337
513
|
(k == 'title' && (x.nil? || x.is_a?(String))) ||
|
|
338
|
-
(
|
|
514
|
+
(words.key?(k) && (x.nil? || ((x.is_a?(String) || x.is_a?(Symbol)) && words[k].include?(x.to_s))))
|
|
339
515
|
end
|
|
340
516
|
end
|
|
341
517
|
end.to_h { |k, entry| [k.to_s, entry.to_h { |ek, ev| [ek.to_s, ev.is_a?(Symbol) ? ev.to_s : ev] }] }
|
|
@@ -365,7 +541,8 @@ module VisualCI
|
|
|
365
541
|
ABSOLUTE.match?(value) || (value != '' && !CONTROL.match?(value) && !SCHEME.match?(value))
|
|
366
542
|
end
|
|
367
543
|
|
|
368
|
-
private_class_method :build_groups, :get, :
|
|
544
|
+
private_class_method :build_groups, :get, :size_of, :combinations, :values_of, :with_shapes, :dimension_entry,
|
|
545
|
+
:dimensions?, :resolve_dimensions, :common_folder, :rank, :check_manifest, :integral?,
|
|
369
546
|
:positive_integral?, :bytes?, :thumb?, :preload?, :preload_model, :boolean?, :opt, :strings, :texts, :fetch_key, :see_all?, :safe_href?
|
|
370
547
|
end
|
|
371
548
|
end
|