jekyll-bookshop 2.0.0.pre.alpha.18 → 2.0.0.pre.alpha.50

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: 8c3d3183ce166b15c38e0d9e1793e88599dc902fc99258280204b5a6c0c1b18d
4
- data.tar.gz: 02d080f0a87d077dee57680aac65c1b376f58bff5303f4d21bbc6023290c8bd7
3
+ metadata.gz: 986c96d3e958c3967551379041a88a4e8934dbc0ad6025900436e042094ea602
4
+ data.tar.gz: c9393a58731595e9cac2dbf86ec85c805347a320faf25d24a909059546a92b73
5
5
  SHA512:
6
- metadata.gz: aeb9360603c8868495fafe4565f735998d8fbcaf49f0e9fd3e88371eada64b5d95028337fda8fe4a1732a6dd4db735be1258d69f47d1a5311712f44c7e9fb74c
7
- data.tar.gz: 81ba28a2dd8f280cec34fbb8b1077616da99b457fac696f314016db13caceb100b4fa17297deb354fd8e01bb86730b1d18c4585cde14273ff09f4277e36460d5
6
+ metadata.gz: ce11ff41268cde9ac8e726770d6d6fa187d1333f0f71296cdf1a4bc44a42f7fb32147d3a60a93e46d0dbe6117b13e30f8887b04d7c9c96fed77675917b7840e9
7
+ data.tar.gz: 5b5e99a60c73885749a90a108edb81eb6ca52b237cd67e6ab8cb3c1ce902db2b7db8213ba2daeff2751b66202f3b3d1ac38839f1125f465376c3e8f46c79f350
@@ -1,20 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "jekyll"
2
4
  require "pathname"
3
5
  require "dry/inflector"
4
6
 
5
7
  require_relative "jekyll-bookshop/tags/bookshop-tag"
6
8
  require_relative "jekyll-bookshop/tags/style-tag"
7
- require_relative "jekyll-bookshop/tags/site-data-tag"
8
9
  require_relative "jekyll-bookshop/init-styles"
9
- require_relative "jekyll-bookshop/filters"
10
-
10
+ require_relative "jekyll-bookshop/site-data"
11
11
 
12
12
  Liquid::Template.register_tag("bookshop", JekyllBookshop::Tag)
13
13
  Liquid::Template.register_tag("bookshop_scss", JekyllBookshop::StyleTag)
14
- Liquid::Template.register_tag("bookshop_site_data", JekyllBookshop::SiteDataTag)
15
-
16
- Liquid::Template.register_filter(JekyllBookshop::Filters)
17
14
 
18
15
  Jekyll::Hooks.register :site, :after_init do |site|
19
16
  JekyllBookshop::Styles.open_bookshop(site)
20
- end
17
+ end
18
+
19
+ Jekyll::Hooks.register :site, :post_render do |site|
20
+ JekyllBookshop::SiteData.extract(site)
21
+ end
@@ -1,30 +1,41 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllBookshop
2
4
  class Styles
3
-
4
5
  # Add the paths to find bookshop's styles
5
6
  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
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
8
24
  end
9
- bookshop_base_locations = bookshop_base_locations.select do |location|
25
+ mapped_locations.select do |location|
10
26
  Dir.exist?(location)
11
27
  end
12
- bookshop_component_locations = bookshop_base_locations&.collect do |location|
28
+ end
29
+
30
+ def self.bookshop_component_locations(locations)
31
+ locations&.collect do |location|
13
32
  Pathname.new("#{location}/components/").cleanpath.to_s
14
33
  end
34
+ end
15
35
 
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)
36
+ def self.apply_array(hash, key, arr)
37
+ hash[key] ||= []
38
+ hash[key].push(*arr)
28
39
  end
29
40
  end
30
- 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
@@ -1,64 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllBookshop
2
4
  class Tag < Jekyll::Tags::IncludeTag
3
-
4
5
  # Look for includes in the built bookshop directory
5
6
  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
7
+ context["site"]["bookshop_component_locations"].freeze
62
8
  end
63
9
 
64
10
  # Support the bind syntax, spreading an object into params
@@ -66,17 +12,14 @@ module JekyllBookshop
66
12
  params = super
67
13
 
68
14
  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
15
+ next unless key == "bind" && value.is_a?(Hash)
16
+
17
+ value_hash = {}.merge(value)
18
+ params = value_hash.merge(params)
19
+ next
74
20
  end
75
21
 
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()
22
+ params.delete("bind")
80
23
 
81
24
  params
82
25
  end
@@ -86,9 +29,7 @@ module JekyllBookshop
86
29
  site = context.registers[:site]
87
30
 
88
31
  file = render_variable(context) || @file
89
- is_template = file.end_with? "__template"
90
32
 
91
- file = file.gsub(".__template", "")
92
33
  cname = file.strip.split("/").last
93
34
  file = "#{file}/#{cname}.jekyll.html"
94
35
  validate_file_name(file)
@@ -110,7 +51,6 @@ module JekyllBookshop
110
51
  raise e
111
52
  end
112
53
  end
113
-
114
54
  end
115
55
  end
116
- end
56
+ end
@@ -1,30 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllBookshop
2
4
  class StyleTag < Liquid::Tag
3
5
  def render(context)
4
6
  site = context.registers[:site]
5
-
7
+
6
8
  bookshop_scss_files = []
7
- site.config['bookshop_base_locations']&.each do |location|
9
+ site.config["bookshop_base_locations"]&.each do |location|
8
10
  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
+ scss_files = Dir.glob(components_loc + "/**/*.scss")&.sort&.collect do |scss_file|
12
+ scss_file.sub!(components_loc + "/", "").sub!(".scss", "")
11
13
  end
12
14
  bookshop_scss_files.push(*scss_files)
13
15
  end
14
-
16
+
15
17
  bookshop_scss_files = bookshop_scss_files&.collect do |file|
16
18
  "@import \"#{file}\";"
17
19
  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
20
+
21
+ "@media all, bookshop {#{bookshop_scss_files.join("\n")}}"
28
22
  end
29
23
  end
30
- end
24
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllBookshop
2
- VERSION = "2.0.0.pre.alpha.18"
3
- end
4
+ VERSION = "2.0.0.pre.alpha.50"
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.18
4
+ version: 2.0.0.pre.alpha.50
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-14 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,11 +86,9 @@ extensions: []
58
86
  extra_rdoc_files: []
59
87
  files:
60
88
  - lib/jekyll-bookshop.rb
61
- - lib/jekyll-bookshop/filters.rb
62
89
  - lib/jekyll-bookshop/init-styles.rb
63
- - lib/jekyll-bookshop/page-without-a-file.rb
90
+ - lib/jekyll-bookshop/site-data.rb
64
91
  - lib/jekyll-bookshop/tags/bookshop-tag.rb
65
- - lib/jekyll-bookshop/tags/site-data-tag.rb
66
92
  - lib/jekyll-bookshop/tags/style-tag.rb
67
93
  - lib/jekyll-bookshop/version.rb
68
94
  homepage: https://github.com/cloudcannon/bookshop
@@ -1,22 +0,0 @@
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
@@ -1,8 +0,0 @@
1
- module JekyllBookshop
2
- # Utility class to help generate files with no source file
3
- class PageWithoutAFile < Jekyll::Page
4
- def read_yaml(*)
5
- @data ||= {}
6
- end
7
- end
8
- end
@@ -1,53 +0,0 @@
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