bookshop-array-structures 2.0.0.pre.alpha.3 → 2.0.0.pre.alpha.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -2
- data/bookshop-array-structures.gemspec +1 -0
- data/lib/bookshop-array-structures.rb +125 -17
- data/lib/bookshop-array-structures/version.rb +1 -1
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22677855f6b324f9afb59568c281564392c3fdd50777dfe1b90067aedbc11391
|
4
|
+
data.tar.gz: 2e16193303b823509f81735a4f9c77ea1a88a49c9f77954f218dd3136ab8d5a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c58f22533b9570e8fd2a1b5026e57efae6633cadb20eb735bfbc6d2fd99276c36bd8b0ab01ec87e236fdf9d80521bada5ebd9395b50b8b84099422cf6294064d
|
7
|
+
data.tar.gz: ad50d2713c9c761e30b5e486b865663f503e5458e48b768bbd005a4ccd3f4a893eddca731728890e877fee166c17ae4f3b121ce63f0fea3b99941314735c8bf3
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bookshop-array-structures (
|
4
|
+
bookshop-array-structures (2.0.0.pre.alpha.7)
|
5
|
+
dry-inflector (>= 0.1, < 1.0)
|
5
6
|
jekyll (>= 3.7, < 5.0)
|
6
7
|
toml-rb (>= 2.0, < 3.0)
|
7
8
|
|
@@ -15,7 +16,8 @@ GEM
|
|
15
16
|
builder (3.2.4)
|
16
17
|
citrus (3.0.2)
|
17
18
|
colorator (1.1.0)
|
18
|
-
concurrent-ruby (1.1.
|
19
|
+
concurrent-ruby (1.1.9)
|
20
|
+
dry-inflector (0.2.0)
|
19
21
|
em-websocket (0.5.2)
|
20
22
|
eventmachine (>= 0.12.9)
|
21
23
|
http_parser.rb (~> 0.6.0)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "jekyll"
|
2
|
-
require
|
2
|
+
require "pathname"
|
3
3
|
require "toml-rb"
|
4
|
+
require "dry/inflector"
|
4
5
|
|
5
6
|
module Bookshop
|
6
7
|
class ArrayStructures
|
@@ -28,6 +29,7 @@ module Bookshop
|
|
28
29
|
structure["_comments"] ||= {}
|
29
30
|
structure["value"] ||= {}
|
30
31
|
value_context = structure["value"] if value_context.nil?
|
32
|
+
inflector = Dry::Inflector.new
|
31
33
|
value_obj.each_pair {|key, value|
|
32
34
|
if value_context.has_key?(key)
|
33
35
|
next
|
@@ -47,7 +49,8 @@ module Bookshop
|
|
47
49
|
end
|
48
50
|
if value["select"]
|
49
51
|
value_context[key] = nil
|
50
|
-
|
52
|
+
plural_key = inflector.pluralize(key)
|
53
|
+
structure["_select_data"][plural_key] = value["select"]
|
51
54
|
next
|
52
55
|
end
|
53
56
|
if value["preview"]
|
@@ -65,7 +68,14 @@ module Bookshop
|
|
65
68
|
structure["_comments"][key] = value[0]["--bookshop_comment"]
|
66
69
|
end
|
67
70
|
|
68
|
-
|
71
|
+
singular_title = inflector.classify(key).gsub(/(.)([A-Z])/, '\1 \2')
|
72
|
+
structure["_array_structures"][key] ||= {
|
73
|
+
"values" => [{
|
74
|
+
"label" => singular_title,
|
75
|
+
"icon" => "add_box",
|
76
|
+
"value" => {}
|
77
|
+
}]
|
78
|
+
}
|
69
79
|
handle_bookprops( value[0],
|
70
80
|
structure["_array_structures"][key]["values"][0],
|
71
81
|
structure["_array_structures"][key]["values"][0]["value"])
|
@@ -161,7 +171,103 @@ module Bookshop
|
|
161
171
|
result["array_structures"].push("bookshop_components")
|
162
172
|
end
|
163
173
|
result.delete("_hidden") unless result["_hidden"].nil?
|
164
|
-
|
174
|
+
results = [result]
|
175
|
+
if result["_template"]
|
176
|
+
results.push(transform_template_component(result))
|
177
|
+
end
|
178
|
+
result.delete("_template")
|
179
|
+
return results
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.transform_template_component(result)
|
183
|
+
schema_result = Marshal.load(Marshal.dump(result))
|
184
|
+
unwrap_structure_template(schema_result)
|
185
|
+
schema_result["value"] = templatize_values(schema_result["value"])
|
186
|
+
schema_result["_comments"] = templatize_comments(schema_result["_comments"])
|
187
|
+
schema_result["value"]["_bookshop_name"] = "#{schema_result["value"]["_bookshop_name"]}.__template"
|
188
|
+
schema_result["label"] = "Templated #{schema_result["label"]}"
|
189
|
+
schema_result["_array_structures"] = {}
|
190
|
+
schema_result["_select_data"] = {}
|
191
|
+
schema_result.delete("_template")
|
192
|
+
schema_result
|
193
|
+
end
|
194
|
+
|
195
|
+
# Breadth-first search through the structure, looking for keys
|
196
|
+
# that will match array structure or comments and flattening them
|
197
|
+
# into the root structure
|
198
|
+
def self.unwrap_structure_template(structure)
|
199
|
+
flattened_keys = {}
|
200
|
+
structure["value"].each_pair do |base_key, base_value|
|
201
|
+
flattened_keys[base_key] = base_value if base_key.start_with? "_"
|
202
|
+
end
|
203
|
+
flatten_hash(structure["value"]).each do |flat_key|
|
204
|
+
cascade_key = flat_key.split(".").last
|
205
|
+
matched_comment = structure.dig("_comments", cascade_key)
|
206
|
+
matched_substructure = structure.dig("_array_structures", cascade_key, "values", 0)
|
207
|
+
|
208
|
+
if matched_substructure
|
209
|
+
unwrap_structure_template(matched_substructure)
|
210
|
+
matched_substructure["value"].each_pair do |subkey, subvalue|
|
211
|
+
# Pull substructure's flat keys into this structure
|
212
|
+
flattened_keys["#{flat_key}.#{subkey}"] = subvalue
|
213
|
+
end
|
214
|
+
matched_substructure["_comments"].each_pair do |subkey, subcomment|
|
215
|
+
# Pull substructure's comments into this structure
|
216
|
+
structure["_comments"]["#{flat_key}.#{subkey}"] = subcomment
|
217
|
+
end
|
218
|
+
# Mark this key as an array so the include plugin knows to return
|
219
|
+
# a value and not a string
|
220
|
+
flattened_keys["#{flat_key}.__array_template"] = "{{#{cascade_key}}}"
|
221
|
+
if matched_comment
|
222
|
+
structure["_comments"].delete(cascade_key)
|
223
|
+
structure["_comments"]["#{flat_key}.__array_template"] = matched_comment
|
224
|
+
end
|
225
|
+
else
|
226
|
+
flattened_keys[flat_key] = ""
|
227
|
+
if matched_comment
|
228
|
+
structure["_comments"].delete(cascade_key)
|
229
|
+
structure["_comments"][flat_key] = matched_comment
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
structure["value"] = flattened_keys
|
234
|
+
end
|
235
|
+
|
236
|
+
# Recursively convert a hash into flat dot-notation keys
|
237
|
+
def self.flatten_hash(hash)
|
238
|
+
keys = [];
|
239
|
+
hash.each_pair do |k, v|
|
240
|
+
next if k.start_with? "_"
|
241
|
+
if v.is_a? Hash
|
242
|
+
flatten_hash(v).each do |ik|
|
243
|
+
keys.push("#{k}.#{ik}")
|
244
|
+
end
|
245
|
+
else
|
246
|
+
keys.push(k)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
keys
|
250
|
+
end
|
251
|
+
|
252
|
+
def self.templatize_values(hash)
|
253
|
+
templated_hash = hash.dup
|
254
|
+
hash.each_key do |k|
|
255
|
+
next if k.start_with? "_"
|
256
|
+
next if k.end_with? "__array_template"
|
257
|
+
templated_hash.delete(k)
|
258
|
+
templated_hash["#{k}.__template"] = "{{#{k.split('.').last}}}"
|
259
|
+
end
|
260
|
+
templated_hash
|
261
|
+
end
|
262
|
+
|
263
|
+
def self.templatize_comments(hash)
|
264
|
+
templated_hash = hash.dup
|
265
|
+
hash.each_pair do |k, comment|
|
266
|
+
next if k.end_with? "__array_template"
|
267
|
+
templated_hash.delete(k)
|
268
|
+
templated_hash["#{k}.__template"] = comment
|
269
|
+
end
|
270
|
+
templated_hash
|
165
271
|
end
|
166
272
|
|
167
273
|
def self.transform_legacy_component(path, component, site)
|
@@ -182,7 +288,7 @@ module Bookshop
|
|
182
288
|
result["array_structures"].push("components")
|
183
289
|
end
|
184
290
|
result.delete("_hidden") unless result["_hidden"].nil?
|
185
|
-
return result
|
291
|
+
return [result]
|
186
292
|
end
|
187
293
|
|
188
294
|
def self.rewrite_bookshop_toml(content)
|
@@ -225,24 +331,26 @@ module Bookshop
|
|
225
331
|
puts exception
|
226
332
|
next
|
227
333
|
end
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
334
|
+
transformed_components = transform_component(f, component, site)
|
335
|
+
transformed_components.each{|transformed_component|
|
336
|
+
array_structures = transformed_component.delete("array_structures")
|
337
|
+
array_structures.each{|key|
|
338
|
+
begin
|
339
|
+
site.config["_array_structures"][key] ||= {}
|
340
|
+
site.config["_array_structures"][key]["values"] ||= []
|
341
|
+
site.config["_array_structures"][key]["values"].push(transformed_component)
|
342
|
+
rescue => exception
|
343
|
+
puts "❌ Error Adding Story to Array Structures: " + f
|
344
|
+
puts "🤔 Maybe your current _config.yml has conflicting array structures?"
|
345
|
+
end
|
346
|
+
}
|
239
347
|
}
|
240
348
|
end
|
241
349
|
end
|
242
350
|
|
243
351
|
def self.build_array_structures(site)
|
244
352
|
bookshop_locations = site.config['bookshop_locations']&.collect do |location|
|
245
|
-
Pathname.new(location
|
353
|
+
Pathname.new("#{site.source}/#{location}/components").cleanpath.to_s
|
246
354
|
end
|
247
355
|
bookshop_locations = bookshop_locations.select do |location|
|
248
356
|
Dir.exist?(location)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bookshop-array-structures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.alpha.
|
4
|
+
version: 2.0.0.pre.alpha.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tate
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -50,6 +50,26 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '3.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: dry-inflector
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.1'
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.1'
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.0'
|
53
73
|
description:
|
54
74
|
email:
|
55
75
|
- tate@cloudcannon.com
|