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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22677855f6b324f9afb59568c281564392c3fdd50777dfe1b90067aedbc11391
4
- data.tar.gz: 2e16193303b823509f81735a4f9c77ea1a88a49c9f77954f218dd3136ab8d5a0
3
+ metadata.gz: 6cf0300e43535775fbc9d534f5423f73273d5aa43f6ec11173d3a131d987f0c1
4
+ data.tar.gz: dbfc037fa29d74277e0671baac116036c2b5341de316f7943c86f920dba0d0b7
5
5
  SHA512:
6
- metadata.gz: c58f22533b9570e8fd2a1b5026e57efae6633cadb20eb735bfbc6d2fd99276c36bd8b0ab01ec87e236fdf9d80521bada5ebd9395b50b8b84099422cf6294064d
7
- data.tar.gz: ad50d2713c9c761e30b5e486b865663f503e5458e48b768bbd005a4ccd3f4a893eddca731728890e877fee166c17ae4f3b121ce63f0fea3b99941314735c8bf3
6
+ metadata.gz: 907e37b22973b00d90f6f17bc69c598ea9506a41d9faaa691af7bc4d338cd21d9651fec61744ae775e1e8aa993bd021138c3d551530262630b7f824a4db92bfd
7
+ data.tar.gz: c52ca5c3d5df70c3a5d3de2b6dd3c35c64d06d2f4289aac82fd0740b4e8cd996de12004f5a2a4a40aa27ece9d4f1e4a98d3af24c7acfd18365598db5397dedd8
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.11)
5
5
  dry-inflector (>= 0.1, < 1.0)
6
6
  jekyll (>= 3.7, < 5.0)
7
7
  toml-rb (>= 2.0, < 3.0)
@@ -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 = ["Tate"]
7
- spec.email = ["tate@cloudcannon.com"]
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
- unwrap_structure_template(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)
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
- flattened_keys[flat_key] = ""
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.each_key do |k|
263
+ hash.each_pair do |k, v|
255
264
  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}}}"
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
@@ -1,5 +1,5 @@
1
1
  module Bookshop
2
2
  module Arraystructures
3
- VERSION = "2.0.0.pre.alpha.8"
3
+ VERSION = "2.0.0.pre.alpha.13"
4
4
  end
5
5
  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.8
4
+ version: 2.0.0.pre.alpha.13
5
5
  platform: ruby
6
6
  authors:
7
- - Tate
7
+ - CloudCannon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-12 00:00:00.000000000 Z
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
- - tate@cloudcannon.com
75
+ - support@cloudcannon.com
76
76
  executables: []
77
77
  extensions: []
78
78
  extra_rdoc_files: []