jekyll-bookshop 2.0.0.pre.alpha.6 → 2.0.0.pre.alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-bookshop.rb +68 -9
- data/lib/jekyll-bookshop/version.rb +1 -1
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b83f0c00e59a3a11cd3c45a83b827b4746a059767be1b54aba7ca4bad15e6637
|
4
|
+
data.tar.gz: f0e07eaf06e489df91881bfb6fbd56f8aa92fbb703bdd9d00f88f745e6574c16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1531dbce913e222352948952e7ce04061cb384f592174eeddda60e22fe5051c8500726b24e7c3965af0fc881e29d5691cfe30da5fbc46be05ba572797ed020e7
|
7
|
+
data.tar.gz: eca3de9faa109f6b36e228857410e7faa92367a35f863ecbbc3e9585d01b38de5829304f7dc2386612724de082a893877e4e658d5d902e5c49689143bffac898
|
data/lib/jekyll-bookshop.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "jekyll"
|
2
|
-
require
|
2
|
+
require "pathname"
|
3
|
+
require "dry/inflector"
|
3
4
|
|
4
5
|
module JekyllBookshop
|
5
6
|
class Tag < Jekyll::Tags::IncludeTag
|
@@ -9,6 +10,59 @@ 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
|
+
template = params["__template"] || ""
|
18
|
+
return Liquid::Template.parse(template).render(context) if params.key? "__template"
|
19
|
+
|
20
|
+
array_template = params["__array_template"] || ""
|
21
|
+
if params.key? "__array_template"
|
22
|
+
# We're adding a new root scope here and then removing it.
|
23
|
+
# Who knows why, but assign and capture always add to the root scope.
|
24
|
+
# Which is why this is hacked in, instead of using context.stack 🤷♂️
|
25
|
+
context.scopes.push({})
|
26
|
+
Liquid::Template.parse(array_template).render(context)
|
27
|
+
template_scope = context.scopes.pop()
|
28
|
+
template_array = template_scope[parent_param] || "";
|
29
|
+
unless template_array.is_a? Array
|
30
|
+
Jekyll.logger.warn "Bookshop:",
|
31
|
+
"#{array_template} did not evaluate to an array
|
32
|
+
as required for key #{parent_param}.__array_template"
|
33
|
+
template_array = []
|
34
|
+
end
|
35
|
+
|
36
|
+
params.delete("__array_template")
|
37
|
+
output_array = []
|
38
|
+
template_array.each do |item|
|
39
|
+
inflector = Dry::Inflector.new
|
40
|
+
singular_parent = inflector.singularize(parent_param)
|
41
|
+
next_scope = {}
|
42
|
+
next_scope[singular_parent] = item
|
43
|
+
|
44
|
+
context.push(next_scope)
|
45
|
+
output_array.push(expand_param_templates(params, context, ""))
|
46
|
+
context.pop()
|
47
|
+
end
|
48
|
+
return output_array
|
49
|
+
end
|
50
|
+
|
51
|
+
params.each_pair do |param, value|
|
52
|
+
if param.end_with? "_template"
|
53
|
+
param_root, param_remainder = param.split('.', 2)
|
54
|
+
param_hash[param_root] ||= {}
|
55
|
+
param_hash[param_root][param_remainder] = value
|
56
|
+
else
|
57
|
+
new_params[param] = value
|
58
|
+
end
|
59
|
+
end
|
60
|
+
param_hash.each_pair do |param, values|
|
61
|
+
new_params[param] = expand_param_templates(values, context, param)
|
62
|
+
end
|
63
|
+
new_params
|
64
|
+
end
|
65
|
+
|
12
66
|
# Support the bind syntax, spreading an object into params
|
13
67
|
def parse_params(context)
|
14
68
|
params = super
|
@@ -22,6 +76,7 @@ module JekyllBookshop
|
|
22
76
|
end
|
23
77
|
|
24
78
|
params.delete('bind')
|
79
|
+
params = expand_param_templates(params, context, "")
|
25
80
|
|
26
81
|
params
|
27
82
|
end
|
@@ -31,6 +86,9 @@ module JekyllBookshop
|
|
31
86
|
site = context.registers[:site]
|
32
87
|
|
33
88
|
file = render_variable(context) || @file
|
89
|
+
is_template = file.end_with? "__template"
|
90
|
+
|
91
|
+
file = file.gsub(".__template", "")
|
34
92
|
cname = file.strip.split("/").last
|
35
93
|
file = "#{file}/#{cname}.jekyll.html"
|
36
94
|
validate_file_name(file)
|
@@ -52,6 +110,7 @@ module JekyllBookshop
|
|
52
110
|
raise e
|
53
111
|
end
|
54
112
|
end
|
113
|
+
|
55
114
|
end
|
56
115
|
end
|
57
116
|
|
@@ -60,7 +119,7 @@ module JekyllBookshop
|
|
60
119
|
site = context.registers[:site]
|
61
120
|
|
62
121
|
bookshop_scss_files = []
|
63
|
-
site.config['
|
122
|
+
site.config['bookshop_base_locations']&.each do |location|
|
64
123
|
components_loc = Pathname.new(location + "/").cleanpath.to_s
|
65
124
|
scss_files = Dir.glob(components_loc + "/**/*.scss")&.collect do |scss_file|
|
66
125
|
scss_file.sub!(components_loc+"/", '').sub!(".scss", '')
|
@@ -88,25 +147,25 @@ module JekyllBookshop
|
|
88
147
|
|
89
148
|
# Add the paths to find bookshop's styles
|
90
149
|
def self.open_bookshop(site)
|
91
|
-
|
150
|
+
bookshop_base_locations = site.config['bookshop_locations']&.collect do |location|
|
92
151
|
Pathname.new("#{site.source}/#{location}/").cleanpath.to_s
|
93
152
|
end
|
94
|
-
|
153
|
+
bookshop_base_locations = bookshop_base_locations.select do |location|
|
95
154
|
Dir.exist?(location)
|
96
155
|
end
|
97
|
-
bookshop_component_locations =
|
156
|
+
bookshop_component_locations = bookshop_base_locations&.collect do |location|
|
98
157
|
Pathname.new("#{location}/components/").cleanpath.to_s
|
99
158
|
end
|
100
159
|
|
101
160
|
site.config['watch_dirs'] ||= [] # Paired with CloudCannon/jekyll-watch
|
102
|
-
site.config['watch_dirs'].push(*
|
161
|
+
site.config['watch_dirs'].push(*bookshop_base_locations);
|
103
162
|
|
104
163
|
site.config['sass'] ||= {}
|
105
164
|
site.config['sass']['load_paths'] ||= []
|
106
|
-
site.config['sass']['load_paths'].push(*
|
165
|
+
site.config['sass']['load_paths'].push(*bookshop_base_locations)
|
107
166
|
|
108
|
-
site.config['
|
109
|
-
site.config['
|
167
|
+
site.config['bookshop_base_locations'] ||= []
|
168
|
+
site.config['bookshop_base_locations'].push(*bookshop_base_locations)
|
110
169
|
|
111
170
|
site.config['bookshop_component_locations'] ||= []
|
112
171
|
site.config['bookshop_component_locations'].push(*bookshop_component_locations)
|
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.
|
4
|
+
version: 2.0.0.pre.alpha.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- CloudCannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-13 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
|
-
-
|
55
|
+
- support@cloudcannon.com
|
36
56
|
executables: []
|
37
57
|
extensions: []
|
38
58
|
extra_rdoc_files: []
|