bookshop-array-structures 2.0.0.pre.alpha.8 → 2.0.0.pre.alpha.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bookshop-array-structures.gemspec +2 -2
- data/lib/bookshop-array-structures.rb +31 -17
- 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: 6cf0300e43535775fbc9d534f5423f73273d5aa43f6ec11173d3a131d987f0c1
|
4
|
+
data.tar.gz: dbfc037fa29d74277e0671baac116036c2b5341de316f7943c86f920dba0d0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907e37b22973b00d90f6f17bc69c598ea9506a41d9faaa691af7bc4d338cd21d9651fec61744ae775e1e8aa993bd021138c3d551530262630b7f824a4db92bfd
|
7
|
+
data.tar.gz: c52ca5c3d5df70c3a5d3de2b6dd3c35c64d06d2f4289aac82fd0740b4e8cd996de12004f5a2a4a40aa27ece9d4f1e4a98d3af24c7acfd18365598db5397dedd8
|
data/Gemfile.lock
CHANGED
@@ -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
|
|
@@ -180,10 +180,12 @@ module Bookshop
|
|
180
180
|
end
|
181
181
|
|
182
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"}
|
183
185
|
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"])
|
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"])
|
187
189
|
schema_result["value"]["_bookshop_name"] = "#{schema_result["value"]["_bookshop_name"]}.__template"
|
188
190
|
schema_result["label"] = "Templated #{schema_result["label"]}"
|
189
191
|
schema_result["_array_structures"] = {}
|
@@ -195,7 +197,9 @@ module Bookshop
|
|
195
197
|
# Breadth-first search through the structure, looking for keys
|
196
198
|
# that will match array structure or comments and flattening them
|
197
199
|
# into the root structure
|
198
|
-
def self.unwrap_structure_template(structure)
|
200
|
+
def self.unwrap_structure_template(structure, parent_scope)
|
201
|
+
inflector = Dry::Inflector.new
|
202
|
+
singular_parent_scope = inflector.singularize(parent_scope)
|
199
203
|
flattened_keys = {}
|
200
204
|
structure["value"].each_pair do |base_key, base_value|
|
201
205
|
flattened_keys[base_key] = base_value if base_key.start_with? "_"
|
@@ -206,7 +210,15 @@ module Bookshop
|
|
206
210
|
matched_substructure = structure.dig("_array_structures", cascade_key, "values", 0)
|
207
211
|
|
208
212
|
if matched_substructure
|
209
|
-
|
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)
|
210
222
|
matched_substructure["value"].each_pair do |subkey, subvalue|
|
211
223
|
# Pull substructure's flat keys into this structure
|
212
224
|
flattened_keys["#{flat_key}.#{subkey}"] = subvalue
|
@@ -215,15 +227,12 @@ module Bookshop
|
|
215
227
|
# Pull substructure's comments into this structure
|
216
228
|
structure["_comments"]["#{flat_key}.#{subkey}"] = subcomment
|
217
229
|
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
230
|
else
|
226
|
-
|
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} }}"
|
227
236
|
if matched_comment
|
228
237
|
structure["_comments"].delete(cascade_key)
|
229
238
|
structure["_comments"][flat_key] = matched_comment
|
@@ -251,11 +260,16 @@ module Bookshop
|
|
251
260
|
|
252
261
|
def self.templatize_values(hash)
|
253
262
|
templated_hash = hash.dup
|
254
|
-
hash.
|
263
|
+
hash.each_pair do |k, v|
|
255
264
|
next if k.start_with? "_"
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
259
273
|
end
|
260
274
|
templated_hash
|
261
275
|
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.13
|
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-21 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: []
|