jekyll-bookshop 2.0.0.pre.alpha.16 → 2.0.0.pre.alpha.45

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: 21ca731f6c601f6a8a9dcf77961545abc9f2f685bcd35f711ee42417d43e6343
4
- data.tar.gz: b1745066742f5ae58c723c9c080a1872da41218ff64bb8ead5f0ce5bbd070d78
3
+ metadata.gz: c1aa3dc1f5e98a00c8be26493e526cd58c30aebf01299de1f2118bcb2aa4a54f
4
+ data.tar.gz: 3cb7751c63ba626c021007f5555a47938516d8bea754bb7ceb99cd7e358ac0e2
5
5
  SHA512:
6
- metadata.gz: dfb44b01c31a8bc33b3206fd6382e6ca42a90c7295de629d9852f2714275713618d19b4b80928a509a05bd5dcaabb4e016dbf52e362dd86bb6b17f09c4c7a9d7
7
- data.tar.gz: b915ab8df7097692e3891c0c95f8c22b74803c55a24b5b3e2d62028683df159863556bb19f6540cc4a19ec2a146278179c823ca524de76996900af8e6df88e1d
6
+ metadata.gz: eba66e7c82fbd32c83f21c11ad3f3d3a9cad6765722e83650ad32e42dd3ddfbb7855207748b2220c01e293d5e329571e8dbb2e590888918da624789488423a59
7
+ data.tar.gz: 14343996021296ee14d2f4ba112fdbe5accec1def17c8a7b6d0f7446037abed9a0b492f8857818327c47ceb80cc67aac27c97f7e0ab498fd688feeb4f45bdcef
@@ -1,208 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "jekyll"
2
4
  require "pathname"
3
5
  require "dry/inflector"
4
6
 
5
- module JekyllBookshop
6
- class Tag < Jekyll::Tags::IncludeTag
7
-
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
7
+ require_relative "jekyll-bookshop/tags/bookshop-tag"
8
+ require_relative "jekyll-bookshop/tags/style-tag"
9
+ require_relative "jekyll-bookshop/init-styles"
10
+ require_relative "jekyll-bookshop/site-data"
200
11
 
201
12
  Liquid::Template.register_tag("bookshop", JekyllBookshop::Tag)
202
13
  Liquid::Template.register_tag("bookshop_scss", JekyllBookshop::StyleTag)
203
14
 
204
- Liquid::Template.register_filter(JekyllBookshop::Filters)
205
-
206
15
  Jekyll::Hooks.register :site, :after_init do |site|
207
16
  JekyllBookshop::Styles.open_bookshop(site)
208
- end
17
+ end
18
+
19
+ Jekyll::Hooks.register :site, :post_render do |site|
20
+ JekyllBookshop::SiteData.extract(site)
21
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class Styles
5
+ # Add the paths to find bookshop's styles
6
+ def self.open_bookshop(site)
7
+ return unless site.config["bookshop_locations"]
8
+
9
+ bookshop_base_locations = filter_bookshops(site.source, site.config["bookshop_locations"])
10
+ bookshop_component_locations = bookshop_component_locations(bookshop_base_locations)
11
+
12
+ site.config["sass"] ||= {}
13
+
14
+ apply_array(site.config["sass"], "load_paths", bookshop_base_locations)
15
+ # Paired with CloudCannon/jekyll-watch
16
+ apply_array(site.config, "watch_dirs", bookshop_base_locations)
17
+ apply_array(site.config, "bookshop_base_locations", bookshop_base_locations)
18
+ apply_array(site.config, "bookshop_component_locations", bookshop_component_locations)
19
+ end
20
+
21
+ def self.filter_bookshops(src, locations)
22
+ mapped_locations = locations&.collect do |location|
23
+ Pathname.new("#{src}/#{location}/").cleanpath.to_s
24
+ end
25
+ mapped_locations.select do |location|
26
+ Dir.exist?(location)
27
+ end
28
+ end
29
+
30
+ def self.bookshop_component_locations(locations)
31
+ locations&.collect do |location|
32
+ Pathname.new("#{location}/components/").cleanpath.to_s
33
+ end
34
+ end
35
+
36
+ def self.apply_array(hash, key, arr)
37
+ hash[key] ||= []
38
+ hash[key].push(*arr)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class SiteData
5
+ def self.extract(site)
6
+ @site = site
7
+
8
+ payload_collections = {}
9
+ @site.collections.each_pair do |collection, items|
10
+ payload_collections[collection] = items.docs.map do |doc|
11
+ doc.data.merge(hydrate_document_fields(doc))
12
+ end
13
+ end
14
+
15
+ payload_collections["data"] = {}
16
+ @site.data.each_pair do |key, value|
17
+ next if key.to_s.start_with?("_bookshop")
18
+
19
+ payload_collections["data"][key] = value
20
+ end
21
+
22
+ @site.data["_bookshop_site_data"] = { "site" => payload_collections }
23
+ Jekyll.logger.info "Bookshop:",
24
+ "Bookshop site data generated"
25
+ end
26
+
27
+ def self.hydrate_document_fields(document)
28
+ keys = %w(content url date relative_path permalink)
29
+ hydrated_doc = {}
30
+ keys.each { |key| hydrated_doc[key] = document.send(key) }
31
+ hydrate_document_excerpt(document, hydrated_doc)
32
+ end
33
+
34
+ def self.hydrate_document_excerpt(document, hydrated_doc)
35
+ hydrated_doc.merge!({
36
+ "excerpt" => document.data["excerpt"].output,
37
+ })
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class Tag < Jekyll::Tags::IncludeTag
5
+ # Look for includes in the built bookshop directory
6
+ def tag_includes_dirs(context)
7
+ context["site"]["bookshop_component_locations"].freeze
8
+ end
9
+
10
+ # Support the bind syntax, spreading an object into params
11
+ def parse_params(context)
12
+ params = super
13
+
14
+ params.each do |key, value|
15
+ next unless key == "bind" && value.is_a?(Hash)
16
+
17
+ value_hash = {}.merge(value)
18
+ params = value_hash.merge(params)
19
+ next
20
+ end
21
+
22
+ params.delete("bind")
23
+
24
+ params
25
+ end
26
+
27
+ # Map component names to the .jekyll.html files found in bookshop
28
+ def render(context)
29
+ site = context.registers[:site]
30
+
31
+ file = render_variable(context) || @file
32
+
33
+ cname = file.strip.split("/").last
34
+ file = "#{file}/#{cname}.jekyll.html"
35
+ validate_file_name(file)
36
+
37
+ path = locate_include_file(context, file, site.safe)
38
+ return unless path
39
+
40
+ add_include_to_dependency(site, path, context)
41
+
42
+ partial = load_cached_partial(path, context)
43
+
44
+ context.stack do
45
+ context["include"] = parse_params(context) if @params
46
+ begin
47
+ partial.render!(context)
48
+ rescue Liquid::Error => e
49
+ e.template_name = path
50
+ e.markup_context = "included " if e.markup_context.nil?
51
+ raise e
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllBookshop
4
+ class StyleTag < Liquid::Tag
5
+ def render(context)
6
+ site = context.registers[:site]
7
+
8
+ bookshop_scss_files = []
9
+ site.config["bookshop_base_locations"]&.each do |location|
10
+ components_loc = Pathname.new(location + "/").cleanpath.to_s
11
+ scss_files = Dir.glob(components_loc + "/**/*.scss")&.collect do |scss_file|
12
+ scss_file.sub!(components_loc + "/", "").sub!(".scss", "")
13
+ end
14
+ bookshop_scss_files.push(*scss_files)
15
+ end
16
+
17
+ bookshop_scss_files = bookshop_scss_files&.collect do |file|
18
+ "@import \"#{file}\";"
19
+ end
20
+
21
+ output_css = if site.config["safe_scss"] == true
22
+ bookshop_scss_files.join("\n")
23
+ else
24
+ "@media all, bookshop {
25
+ #{bookshop_scss_files.join("\n")}
26
+ }"
27
+ end
28
+
29
+ output_css
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllBookshop
2
- VERSION = "2.0.0.pre.alpha.16"
3
- end
4
+ VERSION = "2.0.0.pre.alpha.45"
5
+ 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.16
4
+ version: 2.0.0.pre.alpha.45
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-07 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -50,6 +50,34 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '1.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.80'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '0.80'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rubocop-jekyll
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.11'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.11'
53
81
  description:
54
82
  email:
55
83
  - support@cloudcannon.com
@@ -58,6 +86,10 @@ extensions: []
58
86
  extra_rdoc_files: []
59
87
  files:
60
88
  - lib/jekyll-bookshop.rb
89
+ - lib/jekyll-bookshop/init-styles.rb
90
+ - lib/jekyll-bookshop/site-data.rb
91
+ - lib/jekyll-bookshop/tags/bookshop-tag.rb
92
+ - lib/jekyll-bookshop/tags/style-tag.rb
61
93
  - lib/jekyll-bookshop/version.rb
62
94
  homepage: https://github.com/cloudcannon/bookshop
63
95
  licenses: