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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e462ed292655141cffd66539af92a6d4f4cabadf23ff19d37fb94fe53b83254
4
- data.tar.gz: 0d9836c8ad1816e22fb6cbd8c4001c3289ea8b32576e8538a79721d7366d481c
3
+ metadata.gz: 8bdfa2472fe2135938ef5d3c819411412c46f1b5c30cc224ae1f388442a28e3a
4
+ data.tar.gz: 0140b5a55a4684fe41e00e448fafafee6e2c61d569d881fe82e73870b3bad1e8
5
5
  SHA512:
6
- metadata.gz: 669c00b48bfa5819817c0d86804dfee927b3a923d4203afddb58c821450cb2341081b91c93ad07b2aeb3069bcff2db10f766d8f57a1fee83caef1a2f30029983
7
- data.tar.gz: f4d365d566d66c731720db57ada3306228dfd0196c481bf40ea1d84c7ace0432956cc516c851ffc011be1c1f9b8e4449dedb70f07de6039eab99d4401bce8a7b
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.7)
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)
@@ -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
- unwrap_structure_template(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)
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
- flattened_keys[flat_key] = ""
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.each_key do |k|
261
+ hash.each_pair do |k, v|
255
262
  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}}}"
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
@@ -1,5 +1,5 @@
1
1
  module Bookshop
2
2
  module Arraystructures
3
- VERSION = "2.0.0.pre.alpha.9"
3
+ VERSION = "2.0.0.pre.alpha.10"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.9
4
+ version: 2.0.0.pre.alpha.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon