cloudcannon-jekyll 1.4.1 → 1.4.2

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: 27fc78b980c8ee16f5bb1f9576d7536a16912d5fb41f4074e6768e88488ccf97
4
- data.tar.gz: fd725b0483c287da1d952f910d1c8b9e451bd221fe58a8dd190cff4d95531d49
3
+ metadata.gz: db495486f69fc156d24ba59209fb5f1627e6692e500d7175daf0f393634339b4
4
+ data.tar.gz: 3baa3ab9dec30d4d2f834c14b6088780f22365a3bece79cf2a70428a225ed67e
5
5
  SHA512:
6
- metadata.gz: 67cee5772f33736f2ec69a99a1c3dd9fef9dd0eeacff28c3fe7ebb9dafc4fe2ddf9d26ffc34f82445bd42f4a659fd49e1cad4d6057a28aa24bb000a79822bb4d
7
- data.tar.gz: b062438425381b74c995c0566f31ef964788ab310a03f74db7918e7bbab22bd73dfba3249ef33e0243c7d48134ad626b029cebb61a01a07fec223c0a4aeab75e
6
+ metadata.gz: 5716ed9e99d8e57681880932c10c2f18eb0cfab47b82bb269ba544e67b4819fee5fe4a20deb03371c160d920b38acdd4356afe79ad5fe76b67c89b2059fd4bb4
7
+ data.tar.gz: cb4af8135d9426e12bf16532835ec31c01081f22ba5cfa9fecd80a7e8643136c5c2d0242cd99eb573f7c55079466ae9c032a93a1be32827cc7e6b0802af8f941
@@ -0,0 +1,6 @@
1
+ detectors:
2
+ LongParameterList:
3
+ max_params: 4 # Matches the Rubocop setting
4
+
5
+ exclude_paths:
6
+ - spec
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.4.2
2
+
3
+ * Added max depth parameter for jsonify filter and increase it for array structures in config output
4
+
1
5
  # 1.4.1
2
6
 
3
7
  * Added JSON handling for integers in hash keys
@@ -10,9 +10,9 @@ require_relative "cloudcannon-jekyll/version"
10
10
 
11
11
  Liquid::Template.register_filter(CloudCannonJekyll::JsonifyFilter)
12
12
 
13
- # Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
14
13
  if Jekyll::VERSION.start_with? "2"
15
14
  module Jekyll
15
+ # Hooks didn't exist in Jekyll 2 so we monkey patch to get an :after_reset hook
16
16
  class Site
17
17
  alias_method :jekyll_reset, :reset
18
18
 
@@ -29,7 +29,7 @@
29
29
  "includes": {{ config.includes_dir | cc_jsonify }},
30
30
  "layouts": {{ config.layouts_dir | cc_jsonify }}
31
31
  },
32
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
32
+ {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
33
33
  {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
34
34
  "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
35
35
  }
@@ -29,7 +29,7 @@
29
29
  "includes": {{ config.includes_dir | cc_jsonify }},
30
30
  "layouts": {{ config.layouts_dir | cc_jsonify }}
31
31
  },
32
- {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify }},{% endif %}
32
+ {% if config._array_structures %}"array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},{% endif %}
33
33
  {% assign select_data = config | cc_select_data_jsonify %}{% if select_data %}"select-data": {{ select_data }},{% endif %}
34
34
  "source": {{ config.source | replace: pwd, "" | cc_jsonify }}
35
35
  }
@@ -48,7 +48,7 @@
48
48
  "layouts": {{ config.layouts_dir | cc_jsonify }}
49
49
  },
50
50
  {% if config._array_structures -%}
51
- "array-structures": {{ config._array_structures | cc_jsonify }},
51
+ "array-structures": {{ config._array_structures | cc_jsonify: nil, 20 }},
52
52
  {%- endif %}
53
53
  {% assign select_data = config | cc_select_data_jsonify -%}
54
54
  {% if select_data -%}
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
+ # Processes Jekyll configuration to enable the plugin is run and fix common issues
4
5
  class Configuration
5
6
  def self.processed?(site)
6
7
  site.instance_variable_get(:@_cloudcannon_jekyll_processed) == true
@@ -4,6 +4,7 @@ require "jekyll"
4
4
  require "fileutils"
5
5
 
6
6
  module CloudCannonJekyll
7
+ # Generates JSON files containing build config and build output details
7
8
  class Generator < Jekyll::Generator
8
9
  priority :lowest
9
10
 
@@ -27,7 +28,7 @@ module CloudCannonJekyll
27
28
  def generate_file(filename, data)
28
29
  dest = destination_path(filename)
29
30
  FileUtils.mkdir_p(File.dirname(dest))
30
- File.open(dest, "w") { |f| f.write(file_content(filename, data)) }
31
+ File.open(dest, "w") { |file| file.write(file_content(filename, data)) }
31
32
  end
32
33
 
33
34
  def version_path_suffix
@@ -50,13 +51,13 @@ module CloudCannonJekyll
50
51
  end
51
52
 
52
53
  def file_content(filename, data)
53
- json = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", path(filename))
54
- json.content = File.read(source_path(filename))
55
- json.data["layout"] = nil
56
- json.data["sitemap"] = false
57
- json.data["permalink"] = "/#{path(filename)}"
58
- json.render({}, data)
59
- json.output
54
+ page = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", path(filename))
55
+ page.content = File.read(source_path(filename))
56
+ page.data["layout"] = nil
57
+ page.data["sitemap"] = false
58
+ page.data["permalink"] = "/#{path(filename)}"
59
+ page.render({}, data)
60
+ page.output
60
61
  end
61
62
  end
62
63
  end
@@ -3,7 +3,11 @@
3
3
  require "jekyll"
4
4
 
5
5
  module CloudCannonJekyll
6
+ # Filter for converting Jekyll objects into JSON
6
7
  module JsonifyFilter
8
+ STATIC_EXTENSIONS = [".html", ".htm"].freeze
9
+ STATIC_PATHS = ["/robots.txt", "/sitemap.xml"].freeze
10
+
7
11
  CC_JSONIFY_KEY_SWAPS = {
8
12
  "collections" => {
9
13
  "_sort_key" => "_sort-key",
@@ -41,103 +45,113 @@ module CloudCannonJekyll
41
45
  @simple_types.include?(input.class) || [true, false].include?(input)
42
46
  end
43
47
 
44
- def self.static_file_to_json(input, depth)
48
+ def self.static_file_to_json(input, depth, max_depth)
45
49
  out = [
46
- "\"extname\": #{JsonifyFilter.to_json(input.extname, depth + 1)}",
47
- "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
50
+ "\"extname\": #{JsonifyFilter.to_json(input.extname, depth, max_depth)}",
51
+ "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth, max_depth)}",
48
52
  ]
49
53
 
50
54
  # modified_time isn't defined in Jekyll 2.4.0
51
55
  if input.respond_to? :modified_time
52
- out.push("\"modified_time\": #{JsonifyFilter.to_json(input.modified_time, depth + 1)}")
56
+ file_json = JsonifyFilter.to_json(input.modified_time, depth, max_depth)
57
+ out.push("\"modified_time\": #{file_json}")
53
58
  end
54
59
 
55
60
  "{#{out.join(",")}}"
56
61
  end
57
62
 
58
- def self.document_data_to_json(data, out, prevent, depth)
63
+ def self.document_data_to_a(data, prevent, depth, max_depth)
59
64
  prevent += %w(content output next previous excerpt)
60
65
 
61
- data.each do |key, value|
66
+ out = data.map do |key, value|
62
67
  next if prevent.include? key
63
68
 
64
69
  prevent.push key
65
- out.push("#{key.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}")
70
+ "#{key.to_json}: #{JsonifyFilter.to_json(value, depth, max_depth)}"
66
71
  end
67
72
 
68
- "{#{out.join(",")}}"
73
+ out.compact
69
74
  end
70
75
 
71
- def self.legacy_post_to_json(input, depth)
76
+ def self.legacy_post_to_json(input, depth, max_depth)
72
77
  prevent = %w(dir name path url date id categories tags)
73
78
 
74
79
  out = [
75
- "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
76
- "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
77
- "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
78
- "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
79
- "\"date\": #{JsonifyFilter.to_json(input.date, depth + 1)}",
80
- "\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}",
81
- "\"categories\": #{JsonifyFilter.to_json(input.categories, depth + 1)}",
82
- "\"tags\": #{JsonifyFilter.to_json(input.tags, depth + 1)}",
80
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
81
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
82
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
83
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
84
+ "\"date\": #{JsonifyFilter.to_json(input.date, depth, max_depth)}",
85
+ "\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}",
86
+ "\"categories\": #{JsonifyFilter.to_json(input.categories, depth, max_depth)}",
87
+ "\"tags\": #{JsonifyFilter.to_json(input.tags, depth, max_depth)}",
83
88
  ]
84
89
 
85
- JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
90
+ out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
91
+ "{#{out.join(",")}}"
86
92
  end
87
93
 
88
- def self.page_to_json(input, depth)
94
+ def self.page_to_json(input, depth, max_depth)
89
95
  prevent = %w(dir name path url)
90
96
 
91
97
  out = [
92
- "\"dir\": #{JsonifyFilter.to_json(input.dir, depth + 1)}",
93
- "\"name\": #{JsonifyFilter.to_json(input.name, depth + 1)}",
94
- "\"path\": #{JsonifyFilter.to_json(input.path, depth + 1)}",
95
- "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
98
+ "\"dir\": #{JsonifyFilter.to_json(input.dir, depth, max_depth)}",
99
+ "\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
100
+ "\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
101
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
96
102
  ]
97
103
 
98
104
  # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
99
- defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |h|
100
- h.delete("date")
105
+ defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |default|
106
+ default.delete("date")
101
107
  end
102
108
 
103
109
  data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
104
- JsonifyFilter.document_data_to_json(data, out, prevent, depth)
110
+
111
+ out += JsonifyFilter.document_data_to_a(data, prevent, depth, max_depth)
112
+ "{#{out.join(",")}}"
105
113
  end
106
114
 
107
- def self.document_to_json(input, depth)
115
+ def self.document_to_json(input, depth, max_depth)
108
116
  prevent = %w(dir id relative_path url collection)
117
+ path_json = JsonifyFilter.to_json(input.relative_path, depth, max_depth)
109
118
 
110
119
  out = [
111
- "\"path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
112
- "\"relative_path\": #{JsonifyFilter.to_json(input.relative_path, depth + 1)}",
113
- "\"url\": #{JsonifyFilter.to_json(input.url, depth + 1)}",
120
+ "\"path\": #{path_json}",
121
+ "\"relative_path\": #{path_json}",
122
+ "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
114
123
  ]
115
124
 
116
- unless input.collection.nil?
117
- out.push("\"collection\": #{JsonifyFilter.to_json(input.collection.label, depth + 1)}")
125
+ collection = input.collection
126
+ unless collection.nil?
127
+ collection_json = JsonifyFilter.to_json(collection.label, depth, max_depth)
128
+ out.push("\"collection\": #{collection_json}")
118
129
  end
119
130
 
120
131
  # id isn't defined in Jekyll 2.4.0
121
- out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth + 1)}") if input.respond_to? :id
132
+ if input.respond_to? :id
133
+ out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
134
+ end
122
135
 
123
- JsonifyFilter.document_data_to_json(input.data, out, prevent, depth)
136
+ out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
137
+ "{#{out.join(",")}}"
124
138
  end
125
139
 
126
- def self.array_to_json(input, depth, key_swaps = {})
140
+ def self.array_to_json(input, depth, max_depth, key_swaps = {})
127
141
  array = input.map do |value|
128
- JsonifyFilter.to_json(value, depth + 1, key_swaps)
142
+ JsonifyFilter.to_json(value, depth, max_depth, key_swaps)
129
143
  end
130
144
 
131
145
  "[#{array.join(",")}]"
132
146
  end
133
147
 
134
- def self.hash_to_json(input, depth, key_swaps = {})
135
- hash = input.map do |key, value|
148
+ def self.hash_to_json(input, depth, max_depth, key_swaps = {})
149
+ out = input.map do |key, value|
136
150
  string_key = (key_swaps[key] || key).to_s.to_json
137
- "#{string_key}: #{JsonifyFilter.to_json(value, depth + 1, key_swaps)}"
151
+ "#{string_key}: #{JsonifyFilter.to_json(value, depth, max_depth, key_swaps)}"
138
152
  end
139
153
 
140
- "{#{hash.join(",")}}"
154
+ "{#{out.join(",")}}"
141
155
  end
142
156
 
143
157
  def self.config_to_select_data_json(input, depth)
@@ -155,7 +169,7 @@ module CloudCannonJekyll
155
169
  next if prevent.include? key
156
170
 
157
171
  prevent.push key
158
- "#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth + 1)}"
172
+ "#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth)}"
159
173
  end
160
174
 
161
175
  out.compact!
@@ -163,39 +177,39 @@ module CloudCannonJekyll
163
177
  "{#{out.join(",")}}" if out.any?
164
178
  end
165
179
 
166
- def self.to_json(input, depth, key_swaps = {})
167
- if depth > 8 || (depth > 2 && JsonifyFilter.document_type?(input))
180
+ def self.to_json(input, depth, max_depth = 9, key_swaps = {})
181
+ depth += 1
182
+
183
+ if depth > max_depth || (depth > 2 && JsonifyFilter.document_type?(input))
168
184
  '"MAXIMUM_DEPTH"'
169
185
  elsif JsonifyFilter.simple_type?(input)
170
186
  input.to_json
171
187
  elsif input.is_a?(Jekyll::StaticFile)
172
- JsonifyFilter.static_file_to_json(input, depth)
188
+ JsonifyFilter.static_file_to_json(input, depth, max_depth)
173
189
  elsif input.is_a?(Jekyll::Page)
174
- JsonifyFilter.page_to_json(input, depth)
190
+ JsonifyFilter.page_to_json(input, depth, max_depth)
175
191
  elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
176
- JsonifyFilter.legacy_post_to_json(input, depth)
192
+ JsonifyFilter.legacy_post_to_json(input, depth, max_depth)
177
193
  elsif input.is_a?(Jekyll::Document)
178
- JsonifyFilter.document_to_json(input, depth)
194
+ JsonifyFilter.document_to_json(input, depth, max_depth)
179
195
  elsif input.is_a?(Array)
180
- JsonifyFilter.array_to_json(input, depth, key_swaps)
196
+ JsonifyFilter.array_to_json(input, depth, max_depth, key_swaps)
181
197
  elsif input.is_a?(Hash)
182
- JsonifyFilter.hash_to_json(input, depth, key_swaps)
198
+ JsonifyFilter.hash_to_json(input, depth, max_depth, key_swaps)
183
199
  else
184
200
  input.class.to_s.prepend("UNSUPPORTED:").to_json
185
201
  end
186
202
  end
187
203
 
188
204
  def cc_static_files_jsonify(input)
189
- out = []
190
- input.each do |page|
191
- next if page.extname != ".html" &&
192
- page.extname != ".htm" &&
193
- page.path != "/robots.txt" &&
194
- page.path != "/sitemap.xml"
195
-
196
- out.push(JsonifyFilter.to_json(page, 1))
205
+ out = input.map do |page|
206
+ next unless STATIC_EXTENSIONS.include?(page.extname) || STATIC_PATHS.include?(page.path)
207
+
208
+ JsonifyFilter.to_json(page, 1)
197
209
  end
198
210
 
211
+ out.compact!
212
+
199
213
  "[#{out.join(",")}]"
200
214
  end
201
215
 
@@ -207,11 +221,11 @@ module CloudCannonJekyll
207
221
  end
208
222
  end
209
223
 
210
- def cc_jsonify(input, key_swaps_key = nil)
224
+ def cc_jsonify(input, key_swaps_key = nil, max_depth = 8)
211
225
  if CC_JSONIFY_KEY_SWAPS.key? key_swaps_key
212
- JsonifyFilter.to_json(input, 0, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
226
+ JsonifyFilter.to_json(input, 0, max_depth, CC_JSONIFY_KEY_SWAPS[key_swaps_key])
213
227
  else
214
- JsonifyFilter.to_json(input, 0)
228
+ JsonifyFilter.to_json(input, 0, max_depth)
215
229
  end
216
230
  end
217
231
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
+ # Utility class to help generate files with no source file
4
5
  class PageWithoutAFile < Jekyll::Page
5
6
  def read_yaml(*)
6
7
  @data ||= {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyll
4
- VERSION = "1.4.1"
4
+ VERSION = "1.4.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudcannon-jekyll
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CloudCannon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-22 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -108,6 +108,7 @@ extensions: []
108
108
  extra_rdoc_files: []
109
109
  files:
110
110
  - ".gitignore"
111
+ - ".reek.yml"
111
112
  - ".rspec"
112
113
  - ".rubocop.yml"
113
114
  - ".travis.yml"