jekyll-bookshop 2.0.0.pre.alpha.16 → 2.0.0.pre.alpha.17
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/lib/jekyll-bookshop.rb +6 -194
- data/lib/jekyll-bookshop/filters.rb +22 -0
- data/lib/jekyll-bookshop/init-styles.rb +30 -0
- data/lib/jekyll-bookshop/page-without-a-file.rb +8 -0
- data/lib/jekyll-bookshop/tags/bookshop-tag.rb +116 -0
- data/lib/jekyll-bookshop/tags/site-data-tag.rb +53 -0
- data/lib/jekyll-bookshop/tags/style-tag.rb +30 -0
- data/lib/jekyll-bookshop/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78a649cb45837353193db2e946291f5ad53e42eb315848f8e7668311af853d79
|
4
|
+
data.tar.gz: ed7e3c420e86b4c3185d59f033aeea4e1bf9b95c77fa71f7968b815992403ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 217ff3475ee4a99f5a6fae5d14c515c2a3cf9460115d72ea03325ff7391335a8158fb3ac2dd1bbae5b99332bc7c1742aeb401508378cdb12e0346e625b14e5ee
|
7
|
+
data.tar.gz: 5113aff8f35680efdf3d0cfe843e9faab8200535c83a5c024bb5516792a73284af77ca0980f514d26b2f6f718c91e93541778b84c1eff0ba58380b137c934ebc
|
data/lib/jekyll-bookshop.rb
CHANGED
@@ -2,204 +2,16 @@ require "jekyll"
|
|
2
2
|
require "pathname"
|
3
3
|
require "dry/inflector"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
require_relative "jekyll-bookshop/tags/bookshop-tag"
|
6
|
+
require_relative "jekyll-bookshop/tags/style-tag"
|
7
|
+
require_relative "jekyll-bookshop/tags/site-data-tag"
|
8
|
+
require_relative "jekyll-bookshop/init-styles"
|
9
|
+
require_relative "jekyll-bookshop/filters"
|
7
10
|
|
8
|
-
# Look for includes in the built bookshop directory
|
9
|
-
def tag_includes_dirs(context)
|
10
|
-
context['site']['bookshop_component_locations'].freeze
|
11
|
-
end
|
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
|
-
|
68
|
-
# Support the bind syntax, spreading an object into params
|
69
|
-
def parse_params(context)
|
70
|
-
params = super
|
71
|
-
|
72
|
-
params.each do |key, value|
|
73
|
-
if key == 'bind' && value.is_a?(Hash)
|
74
|
-
valueHash = {}.merge(value)
|
75
|
-
params = valueHash.merge(params)
|
76
|
-
next
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
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()
|
84
|
-
|
85
|
-
params
|
86
|
-
end
|
87
|
-
|
88
|
-
# Map component names to the .jekyll.html files found in bookshop
|
89
|
-
def render(context)
|
90
|
-
site = context.registers[:site]
|
91
|
-
|
92
|
-
file = render_variable(context) || @file
|
93
|
-
is_template = file.end_with? "__template"
|
94
|
-
|
95
|
-
file = file.gsub(".__template", "")
|
96
|
-
cname = file.strip.split("/").last
|
97
|
-
file = "#{file}/#{cname}.jekyll.html"
|
98
|
-
validate_file_name(file)
|
99
|
-
|
100
|
-
path = locate_include_file(context, file, site.safe)
|
101
|
-
return unless path
|
102
|
-
|
103
|
-
add_include_to_dependency(site, path, context)
|
104
|
-
|
105
|
-
partial = load_cached_partial(path, context)
|
106
|
-
|
107
|
-
context.stack do
|
108
|
-
context["include"] = parse_params(context) if @params
|
109
|
-
begin
|
110
|
-
partial.render!(context)
|
111
|
-
rescue Liquid::Error => e
|
112
|
-
e.template_name = path
|
113
|
-
e.markup_context = "included " if e.markup_context.nil?
|
114
|
-
raise e
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class StyleTag < Liquid::Tag
|
122
|
-
def render(context)
|
123
|
-
site = context.registers[:site]
|
124
|
-
|
125
|
-
bookshop_scss_files = []
|
126
|
-
site.config['bookshop_base_locations']&.each do |location|
|
127
|
-
components_loc = Pathname.new(location + "/").cleanpath.to_s
|
128
|
-
scss_files = Dir.glob(components_loc + "/**/*.scss")&.collect do |scss_file|
|
129
|
-
scss_file.sub!(components_loc+"/", '').sub!(".scss", '')
|
130
|
-
end
|
131
|
-
bookshop_scss_files.push(*scss_files)
|
132
|
-
end
|
133
|
-
|
134
|
-
bookshop_scss_files = bookshop_scss_files&.collect do |file|
|
135
|
-
"@import \"#{file}\";"
|
136
|
-
end
|
137
|
-
|
138
|
-
output_css = if Jekyll.env == "production"
|
139
|
-
bookshop_scss_files.join("\n")
|
140
|
-
else
|
141
|
-
"@media all, bookshop {
|
142
|
-
#{bookshop_scss_files.join("\n")}
|
143
|
-
}"
|
144
|
-
end
|
145
|
-
|
146
|
-
output_css
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
class Styles
|
151
|
-
|
152
|
-
# Add the paths to find bookshop's styles
|
153
|
-
def self.open_bookshop(site)
|
154
|
-
bookshop_base_locations = site.config['bookshop_locations']&.collect do |location|
|
155
|
-
Pathname.new("#{site.source}/#{location}/").cleanpath.to_s
|
156
|
-
end
|
157
|
-
bookshop_base_locations = bookshop_base_locations.select do |location|
|
158
|
-
Dir.exist?(location)
|
159
|
-
end
|
160
|
-
bookshop_component_locations = bookshop_base_locations&.collect do |location|
|
161
|
-
Pathname.new("#{location}/components/").cleanpath.to_s
|
162
|
-
end
|
163
|
-
|
164
|
-
site.config['watch_dirs'] ||= [] # Paired with CloudCannon/jekyll-watch
|
165
|
-
site.config['watch_dirs'].push(*bookshop_base_locations);
|
166
|
-
|
167
|
-
site.config['sass'] ||= {}
|
168
|
-
site.config['sass']['load_paths'] ||= []
|
169
|
-
site.config['sass']['load_paths'].push(*bookshop_base_locations)
|
170
|
-
|
171
|
-
site.config['bookshop_base_locations'] ||= []
|
172
|
-
site.config['bookshop_base_locations'].push(*bookshop_base_locations)
|
173
|
-
|
174
|
-
site.config['bookshop_component_locations'] ||= []
|
175
|
-
site.config['bookshop_component_locations'].push(*bookshop_component_locations)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
module Filters
|
180
|
-
def addmods(classname, mods = {})
|
181
|
-
base = classname.partition(" ").first
|
182
|
-
mods.each do |mod|
|
183
|
-
if mod[1]
|
184
|
-
classname = "#{classname} #{base}--#{mod[0]}"
|
185
|
-
end
|
186
|
-
end
|
187
|
-
return classname
|
188
|
-
end
|
189
|
-
|
190
|
-
def addstates(classname, states = {})
|
191
|
-
states.each do |state|
|
192
|
-
if state[1]
|
193
|
-
classname = "#{classname} is-#{state[0]}"
|
194
|
-
end
|
195
|
-
end
|
196
|
-
return classname
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
11
|
|
201
12
|
Liquid::Template.register_tag("bookshop", JekyllBookshop::Tag)
|
202
13
|
Liquid::Template.register_tag("bookshop_scss", JekyllBookshop::StyleTag)
|
14
|
+
Liquid::Template.register_tag("bookshop_site_data", JekyllBookshop::SiteDataTag)
|
203
15
|
|
204
16
|
Liquid::Template.register_filter(JekyllBookshop::Filters)
|
205
17
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module JekyllBookshop
|
2
|
+
module Filters
|
3
|
+
def addmods(classname, mods = {})
|
4
|
+
base = classname.partition(" ").first
|
5
|
+
mods.each do |mod|
|
6
|
+
if mod[1]
|
7
|
+
classname = "#{classname} #{base}--#{mod[0]}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
return classname
|
11
|
+
end
|
12
|
+
|
13
|
+
def addstates(classname, states = {})
|
14
|
+
states.each do |state|
|
15
|
+
if state[1]
|
16
|
+
classname = "#{classname} is-#{state[0]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
return classname
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module JekyllBookshop
|
2
|
+
class Styles
|
3
|
+
|
4
|
+
# Add the paths to find bookshop's styles
|
5
|
+
def self.open_bookshop(site)
|
6
|
+
bookshop_base_locations = site.config['bookshop_locations']&.collect do |location|
|
7
|
+
Pathname.new("#{site.source}/#{location}/").cleanpath.to_s
|
8
|
+
end
|
9
|
+
bookshop_base_locations = bookshop_base_locations.select do |location|
|
10
|
+
Dir.exist?(location)
|
11
|
+
end
|
12
|
+
bookshop_component_locations = bookshop_base_locations&.collect do |location|
|
13
|
+
Pathname.new("#{location}/components/").cleanpath.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
site.config['watch_dirs'] ||= [] # Paired with CloudCannon/jekyll-watch
|
17
|
+
site.config['watch_dirs'].push(*bookshop_base_locations);
|
18
|
+
|
19
|
+
site.config['sass'] ||= {}
|
20
|
+
site.config['sass']['load_paths'] ||= []
|
21
|
+
site.config['sass']['load_paths'].push(*bookshop_base_locations)
|
22
|
+
|
23
|
+
site.config['bookshop_base_locations'] ||= []
|
24
|
+
site.config['bookshop_base_locations'].push(*bookshop_base_locations)
|
25
|
+
|
26
|
+
site.config['bookshop_component_locations'] ||= []
|
27
|
+
site.config['bookshop_component_locations'].push(*bookshop_component_locations)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module JekyllBookshop
|
2
|
+
class Tag < Jekyll::Tags::IncludeTag
|
3
|
+
|
4
|
+
# Look for includes in the built bookshop directory
|
5
|
+
def tag_includes_dirs(context)
|
6
|
+
context['site']['bookshop_component_locations'].freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def expand_param_templates(params, context, parent_param)
|
10
|
+
param_hash = {}
|
11
|
+
new_params = {}
|
12
|
+
|
13
|
+
is_template = params.key?("__template") || params.key?("__template_code")
|
14
|
+
template = params["__template"] || params["__template_code"] || ""
|
15
|
+
return Liquid::Template.parse(template).render(context) if is_template
|
16
|
+
|
17
|
+
array_template = params["__array_template"] || ""
|
18
|
+
if params.key? "__array_template"
|
19
|
+
# We're adding a new root scope here and then removing it.
|
20
|
+
# Who knows why, but assign and capture always add to the root scope.
|
21
|
+
# Which is why this is hacked in, instead of using context.stack 🤷♂️
|
22
|
+
context.scopes.push({})
|
23
|
+
Liquid::Template.parse(array_template).render(context)
|
24
|
+
template_scope = context.scopes.pop()
|
25
|
+
template_array = template_scope[parent_param] || "";
|
26
|
+
unless template_array.is_a? Array
|
27
|
+
Jekyll.logger.warn "Bookshop:",
|
28
|
+
"#{array_template} did not evaluate to an array
|
29
|
+
as required for key #{parent_param}.__array_template"
|
30
|
+
template_array = []
|
31
|
+
end
|
32
|
+
|
33
|
+
params.delete("__array_template")
|
34
|
+
output_array = []
|
35
|
+
template_array.each do |item|
|
36
|
+
inflector = Dry::Inflector.new
|
37
|
+
singular_parent = inflector.singularize(parent_param)
|
38
|
+
next_scope = {}
|
39
|
+
next_scope[singular_parent] = item
|
40
|
+
|
41
|
+
context.push(next_scope)
|
42
|
+
output_array.push(expand_param_templates(params, context, ""))
|
43
|
+
context.pop()
|
44
|
+
end
|
45
|
+
return output_array
|
46
|
+
end
|
47
|
+
|
48
|
+
params.each_pair do |param, value|
|
49
|
+
is_template = param.end_with?("_template") || param.end_with?("_template_code")
|
50
|
+
if is_template
|
51
|
+
param_root, param_remainder = param.split('.', 2)
|
52
|
+
param_hash[param_root] ||= {}
|
53
|
+
param_hash[param_root][param_remainder] = value
|
54
|
+
else
|
55
|
+
new_params[param] = value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
param_hash.each_pair do |param, values|
|
59
|
+
new_params[param] = expand_param_templates(values, context, param)
|
60
|
+
end
|
61
|
+
new_params
|
62
|
+
end
|
63
|
+
|
64
|
+
# Support the bind syntax, spreading an object into params
|
65
|
+
def parse_params(context)
|
66
|
+
params = super
|
67
|
+
|
68
|
+
params.each do |key, value|
|
69
|
+
if key == 'bind' && value.is_a?(Hash)
|
70
|
+
valueHash = {}.merge(value)
|
71
|
+
params = valueHash.merge(params)
|
72
|
+
next
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
params.delete('bind')
|
77
|
+
context.scopes.push({}) # Do all expansion in an ephemeral root scope
|
78
|
+
params = expand_param_templates(params, context, "")
|
79
|
+
context.scopes.pop()
|
80
|
+
|
81
|
+
params
|
82
|
+
end
|
83
|
+
|
84
|
+
# Map component names to the .jekyll.html files found in bookshop
|
85
|
+
def render(context)
|
86
|
+
site = context.registers[:site]
|
87
|
+
|
88
|
+
file = render_variable(context) || @file
|
89
|
+
is_template = file.end_with? "__template"
|
90
|
+
|
91
|
+
file = file.gsub(".__template", "")
|
92
|
+
cname = file.strip.split("/").last
|
93
|
+
file = "#{file}/#{cname}.jekyll.html"
|
94
|
+
validate_file_name(file)
|
95
|
+
|
96
|
+
path = locate_include_file(context, file, site.safe)
|
97
|
+
return unless path
|
98
|
+
|
99
|
+
add_include_to_dependency(site, path, context)
|
100
|
+
|
101
|
+
partial = load_cached_partial(path, context)
|
102
|
+
|
103
|
+
context.stack do
|
104
|
+
context["include"] = parse_params(context) if @params
|
105
|
+
begin
|
106
|
+
partial.render!(context)
|
107
|
+
rescue Liquid::Error => e
|
108
|
+
e.template_name = path
|
109
|
+
e.markup_context = "included " if e.markup_context.nil?
|
110
|
+
raise e
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'json/ext'
|
2
|
+
require_relative '../page-without-a-file'
|
3
|
+
|
4
|
+
module JekyllBookshop
|
5
|
+
class SiteDataTag < Liquid::Tag
|
6
|
+
def render(context)
|
7
|
+
@site = context.registers[:site]
|
8
|
+
|
9
|
+
payload_collections = {}
|
10
|
+
@site.collections.each_pair do |collection, items|
|
11
|
+
payload_collections[collection] = items.docs.map do |doc|
|
12
|
+
doc.data.merge(hydrate_document_fields(doc))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
payload_collections["data"] = @site.data
|
17
|
+
output_payload = {"site" => payload_collections}.to_json
|
18
|
+
|
19
|
+
filename = "site-data"
|
20
|
+
generate_file(filename, output_payload)
|
21
|
+
"<script>window.bookshopSiteData = #{output_payload};</script>"
|
22
|
+
end
|
23
|
+
|
24
|
+
def hydrate_document_fields(document)
|
25
|
+
keys = ["content", "url", "date", "relative_path", "permalink"]
|
26
|
+
hydrated_doc = {}
|
27
|
+
keys.each {|key| hydrated_doc[key] = document.send(key)}
|
28
|
+
hydrate_document_excerpt(document, hydrated_doc)
|
29
|
+
end
|
30
|
+
|
31
|
+
def hydrate_document_excerpt(document, hydrated_doc)
|
32
|
+
hydrated_doc.merge!({
|
33
|
+
"excerpt" => document.data["excerpt"].output
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def generate_file(filename, content)
|
38
|
+
dest = destination_json_path(filename)
|
39
|
+
FileUtils.mkdir_p(File.dirname(dest))
|
40
|
+
File.open(dest, "w") { |file| file.write(content) }
|
41
|
+
@site.keep_files ||= []
|
42
|
+
@site.keep_files << json_path(filename)
|
43
|
+
end
|
44
|
+
|
45
|
+
def destination_json_path(filename)
|
46
|
+
Jekyll.sanitized_path(@site.dest, json_path(filename))
|
47
|
+
end
|
48
|
+
|
49
|
+
def json_path(filename)
|
50
|
+
"_bookshop/#{filename}.json"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module JekyllBookshop
|
2
|
+
class StyleTag < Liquid::Tag
|
3
|
+
def render(context)
|
4
|
+
site = context.registers[:site]
|
5
|
+
|
6
|
+
bookshop_scss_files = []
|
7
|
+
site.config['bookshop_base_locations']&.each do |location|
|
8
|
+
components_loc = Pathname.new(location + "/").cleanpath.to_s
|
9
|
+
scss_files = Dir.glob(components_loc + "/**/*.scss")&.collect do |scss_file|
|
10
|
+
scss_file.sub!(components_loc+"/", '').sub!(".scss", '')
|
11
|
+
end
|
12
|
+
bookshop_scss_files.push(*scss_files)
|
13
|
+
end
|
14
|
+
|
15
|
+
bookshop_scss_files = bookshop_scss_files&.collect do |file|
|
16
|
+
"@import \"#{file}\";"
|
17
|
+
end
|
18
|
+
|
19
|
+
output_css = if Jekyll.env == "production"
|
20
|
+
bookshop_scss_files.join("\n")
|
21
|
+
else
|
22
|
+
"@media all, bookshop {
|
23
|
+
#{bookshop_scss_files.join("\n")}
|
24
|
+
}"
|
25
|
+
end
|
26
|
+
|
27
|
+
output_css
|
28
|
+
end
|
29
|
+
end
|
30
|
+
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.
|
4
|
+
version: 2.0.0.pre.alpha.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CloudCannon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -58,6 +58,12 @@ extensions: []
|
|
58
58
|
extra_rdoc_files: []
|
59
59
|
files:
|
60
60
|
- lib/jekyll-bookshop.rb
|
61
|
+
- lib/jekyll-bookshop/filters.rb
|
62
|
+
- lib/jekyll-bookshop/init-styles.rb
|
63
|
+
- lib/jekyll-bookshop/page-without-a-file.rb
|
64
|
+
- lib/jekyll-bookshop/tags/bookshop-tag.rb
|
65
|
+
- lib/jekyll-bookshop/tags/site-data-tag.rb
|
66
|
+
- lib/jekyll-bookshop/tags/style-tag.rb
|
61
67
|
- lib/jekyll-bookshop/version.rb
|
62
68
|
homepage: https://github.com/cloudcannon/bookshop
|
63
69
|
licenses:
|