jekyll-bookshop 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cac00131ec04e5582dc6c8f89e177a3aa306abbc5c51522f0a9175af5016249
4
- data.tar.gz: b3b97e8005d57aaef0c5b12c813c4671e07e9336b83a17ece8888ef8347e2a59
3
+ metadata.gz: 2d0e9021962d6d2d9eef26d3151037110b8438ce7ef83736631cbc05f87c29d0
4
+ data.tar.gz: a9c525e23e1dc61a008d86755d5216e91ebbcbf64dd1331297f7ef103d3fa731
5
5
  SHA512:
6
- metadata.gz: 7e9706e863b2d8b1f5b5edbe00afd8f011270faae31f4b8d0db3ab8863414e66f3c30c80a7ffcc5c1de69172846f50d5ca5c6066659050acd005e8b7babb8a14
7
- data.tar.gz: db11956432b5a16c4b27e464c2c3de3d20f1d06128e2ce15f959c056846573e2e75e4d213bd3d822eb8b5fbecc3570a1668b4bcebe39ba5f9a3b6b6d1ab1b602
6
+ metadata.gz: f678a6095815f900eeff2a8810f64dfe45d10eaf03884aba0aff9d9b164cd9712029a9f0f1649b97327df5a217dc4b54548eb56b3efe5c79a4efc1b7870be006
7
+ data.tar.gz: dfdf1bdadfb87ad5989707ee70aaed180937defcf87c50dffbef5156f9f82fdc52ee9646e6cdc2ed627fb6778e1d7f7df561c9bd5a5cabe4643d95ca757b8a20
@@ -1,5 +1,6 @@
1
1
  require "jekyll"
2
- require 'pathname'
2
+ require "pathname"
3
+ require "dry/inflector"
3
4
 
4
5
  module JekyllBookshop
5
6
  class Tag < Jekyll::Tags::IncludeTag
@@ -9,6 +10,61 @@ module JekyllBookshop
9
10
  context['site']['bookshop_component_locations'].freeze
10
11
  end
11
12
 
13
+ def expand_param_templates(params, context, parent_param)
14
+ param_hash = {}
15
+ new_params = {}
16
+
17
+ is_template = params.key?("__template") || params.key?("__template_code")
18
+ template = params["__template"] || params["__template_code"] || ""
19
+ return Liquid::Template.parse(template).render(context) if is_template
20
+
21
+ array_template = params["__array_template"] || ""
22
+ if params.key? "__array_template"
23
+ # We're adding a new root scope here and then removing it.
24
+ # Who knows why, but assign and capture always add to the root scope.
25
+ # Which is why this is hacked in, instead of using context.stack 🤷‍♂️
26
+ context.scopes.push({})
27
+ Liquid::Template.parse(array_template).render(context)
28
+ template_scope = context.scopes.pop()
29
+ template_array = template_scope[parent_param] || "";
30
+ unless template_array.is_a? Array
31
+ Jekyll.logger.warn "Bookshop:",
32
+ "#{array_template} did not evaluate to an array
33
+ as required for key #{parent_param}.__array_template"
34
+ template_array = []
35
+ end
36
+
37
+ params.delete("__array_template")
38
+ output_array = []
39
+ template_array.each do |item|
40
+ inflector = Dry::Inflector.new
41
+ singular_parent = inflector.singularize(parent_param)
42
+ next_scope = {}
43
+ next_scope[singular_parent] = item
44
+
45
+ context.push(next_scope)
46
+ output_array.push(expand_param_templates(params, context, ""))
47
+ context.pop()
48
+ end
49
+ return output_array
50
+ end
51
+
52
+ params.each_pair do |param, value|
53
+ is_template = param.end_with?("_template") || param.end_with?("_template_code")
54
+ if is_template
55
+ param_root, param_remainder = param.split('.', 2)
56
+ param_hash[param_root] ||= {}
57
+ param_hash[param_root][param_remainder] = value
58
+ else
59
+ new_params[param] = value
60
+ end
61
+ end
62
+ param_hash.each_pair do |param, values|
63
+ new_params[param] = expand_param_templates(values, context, param)
64
+ end
65
+ new_params
66
+ end
67
+
12
68
  # Support the bind syntax, spreading an object into params
13
69
  def parse_params(context)
14
70
  params = super
@@ -22,6 +78,9 @@ module JekyllBookshop
22
78
  end
23
79
 
24
80
  params.delete('bind')
81
+ context.scopes.push({}) # Do all expansion in an ephemeral root scope
82
+ params = expand_param_templates(params, context, "")
83
+ context.scopes.pop()
25
84
 
26
85
  params
27
86
  end
@@ -31,6 +90,9 @@ module JekyllBookshop
31
90
  site = context.registers[:site]
32
91
 
33
92
  file = render_variable(context) || @file
93
+ is_template = file.end_with? "__template"
94
+
95
+ file = file.gsub(".__template", "")
34
96
  cname = file.strip.split("/").last
35
97
  file = "#{file}/#{cname}.jekyll.html"
36
98
  validate_file_name(file)
@@ -52,6 +114,7 @@ module JekyllBookshop
52
114
  raise e
53
115
  end
54
116
  end
117
+
55
118
  end
56
119
  end
57
120
 
@@ -1,3 +1,3 @@
1
1
  module JekyllBookshop
2
- VERSION = "2.0.0.pre.alpha.7"
2
+ VERSION = "2.0.0.pre.alpha.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-bookshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.7
4
+ version: 2.0.0.pre.alpha.12
5
5
  platform: ruby
6
6
  authors:
7
- - Liam Bigelow
7
+ - CloudCannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-02 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -30,9 +30,29 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: dry-inflector
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0.1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
33
53
  description:
34
54
  email:
35
- - liam@cloudcannon.com
55
+ - support@cloudcannon.com
36
56
  executables: []
37
57
  extensions: []
38
58
  extra_rdoc_files: []