bookshop-array-structures 2.0.0.pre.alpha.7 → 2.0.0.pre.alpha.12
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 +125 -13
- 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: f1c3232034512e94f37ffdd823056583093147468723ef0efd169f48d51c0b89
|
4
|
+
data.tar.gz: f58e5f60f7a5c9c49332a2b679ebbbe34ff159437367c7a3b1868ab7ad42efab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49fcdd1d50ba4740410399a0f9e578f6c663d0c0ea9e424d573d32b9ac33ae09d76d14e0b78ae8a0f014e47c12e1e2885f9a0e2ba88e59f4b22c384cf175b90b
|
7
|
+
data.tar.gz: 9e35da2d5f2af938db611d847f850b72cbefe31b3187887a1c53d0cfaacfa311f30ee028353013fb9bb3baa5b583dee292dd291b0beea952c6b6aec9586581fb
|
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.11)
|
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,117 @@ 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
|
+
base_template_hash = {"pre.__template_code" => ""}
|
184
|
+
base_comment_hash = {"pre.__template_code" => "Helper liquid to run before the feilds below. Assigns and captures will be available"}
|
185
|
+
schema_result = Marshal.load(Marshal.dump(result))
|
186
|
+
unwrap_structure_template(schema_result, "site")
|
187
|
+
schema_result["value"] = base_template_hash.merge! templatize_values(schema_result["value"])
|
188
|
+
schema_result["_comments"] = base_comment_hash.merge! templatize_comments(schema_result["_comments"])
|
189
|
+
schema_result["value"]["_bookshop_name"] = "#{schema_result["value"]["_bookshop_name"]}.__template"
|
190
|
+
schema_result["label"] = "Templated #{schema_result["label"]}"
|
191
|
+
schema_result["_array_structures"] = {}
|
192
|
+
schema_result["_select_data"] = {}
|
193
|
+
schema_result.delete("_template")
|
194
|
+
schema_result
|
195
|
+
end
|
196
|
+
|
197
|
+
# Breadth-first search through the structure, looking for keys
|
198
|
+
# that will match array structure or comments and flattening them
|
199
|
+
# into the root structure
|
200
|
+
def self.unwrap_structure_template(structure, parent_scope)
|
201
|
+
inflector = Dry::Inflector.new
|
202
|
+
singular_parent_scope = inflector.singularize(parent_scope)
|
203
|
+
flattened_keys = {}
|
204
|
+
structure["value"].each_pair do |base_key, base_value|
|
205
|
+
flattened_keys[base_key] = base_value if base_key.start_with? "_"
|
206
|
+
end
|
207
|
+
flatten_hash(structure["value"]).each do |flat_key|
|
208
|
+
cascade_key = flat_key.split(".").last
|
209
|
+
matched_comment = structure.dig("_comments", cascade_key)
|
210
|
+
matched_substructure = structure.dig("_array_structures", cascade_key, "values", 0)
|
211
|
+
|
212
|
+
if matched_substructure
|
213
|
+
# Mark this key as an array so the include plugin knows to return
|
214
|
+
# a value and not a string
|
215
|
+
flattened_keys["#{flat_key}.__array_template"] = "{% assign #{cascade_key} = #{singular_parent_scope}.#{cascade_key} %}"
|
216
|
+
if matched_comment
|
217
|
+
structure["_comments"].delete(cascade_key)
|
218
|
+
structure["_comments"]["#{flat_key}.__array_template"] = matched_comment
|
219
|
+
end
|
220
|
+
|
221
|
+
unwrap_structure_template(matched_substructure, cascade_key)
|
222
|
+
matched_substructure["value"].each_pair do |subkey, subvalue|
|
223
|
+
# Pull substructure's flat keys into this structure
|
224
|
+
flattened_keys["#{flat_key}.#{subkey}"] = subvalue
|
225
|
+
end
|
226
|
+
matched_substructure["_comments"].each_pair do |subkey, subcomment|
|
227
|
+
# Pull substructure's comments into this structure
|
228
|
+
structure["_comments"]["#{flat_key}.#{subkey}"] = subcomment
|
229
|
+
end
|
230
|
+
else
|
231
|
+
key_parent_scope = ""
|
232
|
+
unless singular_parent_scope == "site"
|
233
|
+
key_parent_scope = "#{singular_parent_scope}."
|
234
|
+
end
|
235
|
+
flattened_keys[flat_key] = "{{ #{key_parent_scope}#{flat_key.split('.').last} }}"
|
236
|
+
if matched_comment
|
237
|
+
structure["_comments"].delete(cascade_key)
|
238
|
+
structure["_comments"][flat_key] = matched_comment
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
structure["value"] = flattened_keys
|
243
|
+
end
|
244
|
+
|
245
|
+
# Recursively convert a hash into flat dot-notation keys
|
246
|
+
def self.flatten_hash(hash)
|
247
|
+
keys = [];
|
248
|
+
hash.each_pair do |k, v|
|
249
|
+
next if k.start_with? "_"
|
250
|
+
if v.is_a? Hash
|
251
|
+
flatten_hash(v).each do |ik|
|
252
|
+
keys.push("#{k}.#{ik}")
|
253
|
+
end
|
254
|
+
else
|
255
|
+
keys.push(k)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
keys
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.templatize_values(hash)
|
262
|
+
templated_hash = hash.dup
|
263
|
+
hash.each_pair do |k, v|
|
264
|
+
next if k.start_with? "_"
|
265
|
+
if k.end_with? "__array_template"
|
266
|
+
# Remove and re-add the array so position is preserved
|
267
|
+
templated_hash.delete(k)
|
268
|
+
templated_hash[k] = v
|
269
|
+
else
|
270
|
+
templated_hash.delete(k)
|
271
|
+
templated_hash["#{k}.__template"] = v
|
272
|
+
end
|
273
|
+
end
|
274
|
+
templated_hash
|
275
|
+
end
|
276
|
+
|
277
|
+
def self.templatize_comments(hash)
|
278
|
+
templated_hash = hash.dup
|
279
|
+
hash.each_pair do |k, comment|
|
280
|
+
next if k.end_with? "__array_template"
|
281
|
+
templated_hash.delete(k)
|
282
|
+
templated_hash["#{k}.__template"] = comment
|
283
|
+
end
|
284
|
+
templated_hash
|
175
285
|
end
|
176
286
|
|
177
287
|
def self.transform_legacy_component(path, component, site)
|
@@ -192,7 +302,7 @@ module Bookshop
|
|
192
302
|
result["array_structures"].push("components")
|
193
303
|
end
|
194
304
|
result.delete("_hidden") unless result["_hidden"].nil?
|
195
|
-
return result
|
305
|
+
return [result]
|
196
306
|
end
|
197
307
|
|
198
308
|
def self.rewrite_bookshop_toml(content)
|
@@ -235,17 +345,19 @@ module Bookshop
|
|
235
345
|
puts exception
|
236
346
|
next
|
237
347
|
end
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
348
|
+
transformed_components = transform_component(f, component, site)
|
349
|
+
transformed_components.each{|transformed_component|
|
350
|
+
array_structures = transformed_component.delete("array_structures")
|
351
|
+
array_structures.each{|key|
|
352
|
+
begin
|
353
|
+
site.config["_array_structures"][key] ||= {}
|
354
|
+
site.config["_array_structures"][key]["values"] ||= []
|
355
|
+
site.config["_array_structures"][key]["values"].push(transformed_component)
|
356
|
+
rescue => exception
|
357
|
+
puts "❌ Error Adding Story to Array Structures: " + f
|
358
|
+
puts "🤔 Maybe your current _config.yml has conflicting array structures?"
|
359
|
+
end
|
360
|
+
}
|
249
361
|
}
|
250
362
|
end
|
251
363
|
end
|
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.12
|
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-14 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: []
|