bookshop-array-structures 2.0.0.pre.alpha.9 → 2.0.0.pre.alpha.10
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/Gemfile.lock +1 -1
- data/lib/bookshop-array-structures.rb +27 -15
- data/lib/bookshop-array-structures/version.rb +1 -1
- metadata +1 -1
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
@@ -181,7 +181,7 @@ module Bookshop
|
|
181
181
|
|
182
182
|
def self.transform_template_component(result)
|
183
183
|
schema_result = Marshal.load(Marshal.dump(result))
|
184
|
-
unwrap_structure_template(schema_result)
|
184
|
+
unwrap_structure_template(schema_result, "site")
|
185
185
|
schema_result["value"] = templatize_values(schema_result["value"])
|
186
186
|
schema_result["_comments"] = templatize_comments(schema_result["_comments"])
|
187
187
|
schema_result["value"]["_bookshop_name"] = "#{schema_result["value"]["_bookshop_name"]}.__template"
|
@@ -195,7 +195,9 @@ module Bookshop
|
|
195
195
|
# Breadth-first search through the structure, looking for keys
|
196
196
|
# that will match array structure or comments and flattening them
|
197
197
|
# into the root structure
|
198
|
-
def self.unwrap_structure_template(structure)
|
198
|
+
def self.unwrap_structure_template(structure, parent_scope)
|
199
|
+
inflector = Dry::Inflector.new
|
200
|
+
singular_parent_scope = inflector.singularize(parent_scope)
|
199
201
|
flattened_keys = {}
|
200
202
|
structure["value"].each_pair do |base_key, base_value|
|
201
203
|
flattened_keys[base_key] = base_value if base_key.start_with? "_"
|
@@ -206,7 +208,15 @@ module Bookshop
|
|
206
208
|
matched_substructure = structure.dig("_array_structures", cascade_key, "values", 0)
|
207
209
|
|
208
210
|
if matched_substructure
|
209
|
-
|
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)
|
210
220
|
matched_substructure["value"].each_pair do |subkey, subvalue|
|
211
221
|
# Pull substructure's flat keys into this structure
|
212
222
|
flattened_keys["#{flat_key}.#{subkey}"] = subvalue
|
@@ -215,15 +225,12 @@ module Bookshop
|
|
215
225
|
# Pull substructure's comments into this structure
|
216
226
|
structure["_comments"]["#{flat_key}.#{subkey}"] = subcomment
|
217
227
|
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
228
|
else
|
226
|
-
|
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} }}"
|
227
234
|
if matched_comment
|
228
235
|
structure["_comments"].delete(cascade_key)
|
229
236
|
structure["_comments"][flat_key] = matched_comment
|
@@ -251,11 +258,16 @@ module Bookshop
|
|
251
258
|
|
252
259
|
def self.templatize_values(hash)
|
253
260
|
templated_hash = hash.dup
|
254
|
-
hash.
|
261
|
+
hash.each_pair do |k, v|
|
255
262
|
next if k.start_with? "_"
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
259
271
|
end
|
260
272
|
templated_hash
|
261
273
|
end
|