bookshop-array-structures 2.0.0.pre.alpha.5 → 2.0.0.pre.alpha.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/bookshop-array-structures.gemspec +2 -2
- data/lib/bookshop-array-structures.rb +124 -14
- data/lib/bookshop-array-structures/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bdfa2472fe2135938ef5d3c819411412c46f1b5c30cc224ae1f388442a28e3a
|
4
|
+
data.tar.gz: 0140b5a55a4684fe41e00e448fafafee6e2c61d569d881fe82e73870b3bad1e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583bd805506bf76b676efa8f456799a51d487454af3374f6d8dc4678af9abf2063ba623b7dc34b4ab722ec926abb6fae86ad78a13fddeae94d8ae4359062c741
|
7
|
+
data.tar.gz: 9b0d91988ba19200cc686cb5fc3a9f1bbc781dca017bca5ab1e179f5c51048c25a457e1ca97ccef93692c90edca92b66460633ea9f23ce294562811d1722072f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bookshop-array-structures (2.0.0.pre.alpha.
|
4
|
+
bookshop-array-structures (2.0.0.pre.alpha.9)
|
5
5
|
dry-inflector (>= 0.1, < 1.0)
|
6
6
|
jekyll (>= 3.7, < 5.0)
|
7
7
|
toml-rb (>= 2.0, < 3.0)
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
builder (3.2.4)
|
17
17
|
citrus (3.0.2)
|
18
18
|
colorator (1.1.0)
|
19
|
-
concurrent-ruby (1.1.
|
19
|
+
concurrent-ruby (1.1.9)
|
20
20
|
dry-inflector (0.2.0)
|
21
21
|
em-websocket (0.5.2)
|
22
22
|
eventmachine (>= 0.12.9)
|
@@ -3,8 +3,8 @@ require_relative 'lib/bookshop-array-structures/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "bookshop-array-structures"
|
5
5
|
spec.version = Bookshop::Arraystructures::VERSION
|
6
|
-
spec.authors = ["
|
7
|
-
spec.email = ["
|
6
|
+
spec.authors = ["CloudCannon"]
|
7
|
+
spec.email = ["support@cloudcannon.com"]
|
8
8
|
spec.homepage = "https://github.com/cloudcannon/bookshop"
|
9
9
|
spec.summary = "A Jekyll plugin to generate array structures from bookshop"
|
10
10
|
|
@@ -171,7 +171,115 @@ module Bookshop
|
|
171
171
|
result["array_structures"].push("bookshop_components")
|
172
172
|
end
|
173
173
|
result.delete("_hidden") unless result["_hidden"].nil?
|
174
|
-
|
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, "site")
|
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, parent_scope)
|
199
|
+
inflector = Dry::Inflector.new
|
200
|
+
singular_parent_scope = inflector.singularize(parent_scope)
|
201
|
+
flattened_keys = {}
|
202
|
+
structure["value"].each_pair do |base_key, base_value|
|
203
|
+
flattened_keys[base_key] = base_value if base_key.start_with? "_"
|
204
|
+
end
|
205
|
+
flatten_hash(structure["value"]).each do |flat_key|
|
206
|
+
cascade_key = flat_key.split(".").last
|
207
|
+
matched_comment = structure.dig("_comments", cascade_key)
|
208
|
+
matched_substructure = structure.dig("_array_structures", cascade_key, "values", 0)
|
209
|
+
|
210
|
+
if matched_substructure
|
211
|
+
# Mark this key as an array so the include plugin knows to return
|
212
|
+
# a value and not a string
|
213
|
+
flattened_keys["#{flat_key}.__array_template"] = "{% assign #{cascade_key} = #{singular_parent_scope}.#{cascade_key} %}"
|
214
|
+
if matched_comment
|
215
|
+
structure["_comments"].delete(cascade_key)
|
216
|
+
structure["_comments"]["#{flat_key}.__array_template"] = matched_comment
|
217
|
+
end
|
218
|
+
|
219
|
+
unwrap_structure_template(matched_substructure, cascade_key)
|
220
|
+
matched_substructure["value"].each_pair do |subkey, subvalue|
|
221
|
+
# Pull substructure's flat keys into this structure
|
222
|
+
flattened_keys["#{flat_key}.#{subkey}"] = subvalue
|
223
|
+
end
|
224
|
+
matched_substructure["_comments"].each_pair do |subkey, subcomment|
|
225
|
+
# Pull substructure's comments into this structure
|
226
|
+
structure["_comments"]["#{flat_key}.#{subkey}"] = subcomment
|
227
|
+
end
|
228
|
+
else
|
229
|
+
key_parent_scope = ""
|
230
|
+
unless singular_parent_scope == "site"
|
231
|
+
key_parent_scope = "#{singular_parent_scope}."
|
232
|
+
end
|
233
|
+
flattened_keys[flat_key] = "{{ #{key_parent_scope}#{flat_key.split('.').last} }}"
|
234
|
+
if matched_comment
|
235
|
+
structure["_comments"].delete(cascade_key)
|
236
|
+
structure["_comments"][flat_key] = matched_comment
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
structure["value"] = flattened_keys
|
241
|
+
end
|
242
|
+
|
243
|
+
# Recursively convert a hash into flat dot-notation keys
|
244
|
+
def self.flatten_hash(hash)
|
245
|
+
keys = [];
|
246
|
+
hash.each_pair do |k, v|
|
247
|
+
next if k.start_with? "_"
|
248
|
+
if v.is_a? Hash
|
249
|
+
flatten_hash(v).each do |ik|
|
250
|
+
keys.push("#{k}.#{ik}")
|
251
|
+
end
|
252
|
+
else
|
253
|
+
keys.push(k)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
keys
|
257
|
+
end
|
258
|
+
|
259
|
+
def self.templatize_values(hash)
|
260
|
+
templated_hash = hash.dup
|
261
|
+
hash.each_pair do |k, v|
|
262
|
+
next if k.start_with? "_"
|
263
|
+
if k.end_with? "__array_template"
|
264
|
+
# Remove and re-add the array so position is preserved
|
265
|
+
templated_hash.delete(k)
|
266
|
+
templated_hash[k] = v
|
267
|
+
else
|
268
|
+
templated_hash.delete(k)
|
269
|
+
templated_hash["#{k}.__template"] = v
|
270
|
+
end
|
271
|
+
end
|
272
|
+
templated_hash
|
273
|
+
end
|
274
|
+
|
275
|
+
def self.templatize_comments(hash)
|
276
|
+
templated_hash = hash.dup
|
277
|
+
hash.each_pair do |k, comment|
|
278
|
+
next if k.end_with? "__array_template"
|
279
|
+
templated_hash.delete(k)
|
280
|
+
templated_hash["#{k}.__template"] = comment
|
281
|
+
end
|
282
|
+
templated_hash
|
175
283
|
end
|
176
284
|
|
177
285
|
def self.transform_legacy_component(path, component, site)
|
@@ -192,7 +300,7 @@ module Bookshop
|
|
192
300
|
result["array_structures"].push("components")
|
193
301
|
end
|
194
302
|
result.delete("_hidden") unless result["_hidden"].nil?
|
195
|
-
return result
|
303
|
+
return [result]
|
196
304
|
end
|
197
305
|
|
198
306
|
def self.rewrite_bookshop_toml(content)
|
@@ -235,24 +343,26 @@ module Bookshop
|
|
235
343
|
puts exception
|
236
344
|
next
|
237
345
|
end
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
346
|
+
transformed_components = transform_component(f, component, site)
|
347
|
+
transformed_components.each{|transformed_component|
|
348
|
+
array_structures = transformed_component.delete("array_structures")
|
349
|
+
array_structures.each{|key|
|
350
|
+
begin
|
351
|
+
site.config["_array_structures"][key] ||= {}
|
352
|
+
site.config["_array_structures"][key]["values"] ||= []
|
353
|
+
site.config["_array_structures"][key]["values"].push(transformed_component)
|
354
|
+
rescue => exception
|
355
|
+
puts "❌ Error Adding Story to Array Structures: " + f
|
356
|
+
puts "🤔 Maybe your current _config.yml has conflicting array structures?"
|
357
|
+
end
|
358
|
+
}
|
249
359
|
}
|
250
360
|
end
|
251
361
|
end
|
252
362
|
|
253
363
|
def self.build_array_structures(site)
|
254
364
|
bookshop_locations = site.config['bookshop_locations']&.collect do |location|
|
255
|
-
Pathname.new(location
|
365
|
+
Pathname.new("#{site.source}/#{location}/components").cleanpath.to_s
|
256
366
|
end
|
257
367
|
bookshop_locations = bookshop_locations.select do |location|
|
258
368
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- CloudCannon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
version: '1.0'
|
73
73
|
description:
|
74
74
|
email:
|
75
|
-
-
|
75
|
+
- support@cloudcannon.com
|
76
76
|
executables: []
|
77
77
|
extensions: []
|
78
78
|
extra_rdoc_files: []
|