cloudcannon-jekyll 2.3.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,214 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
-
5
- module CloudCannonJekyll
6
- # Filter for converting Jekyll objects into JSON
7
- module JsonifyFilter
8
- STATIC_EXTENSIONS = [".html", ".htm"].freeze
9
-
10
- @simple_types = [
11
- String,
12
- Numeric,
13
- Integer,
14
- Float,
15
- Date,
16
- Time,
17
- NilClass,
18
- ].freeze
19
-
20
- @document_types = [
21
- Jekyll::Document,
22
- Jekyll::Page,
23
- Jekyll::VERSION.start_with?("2.") ? Jekyll::Post : nil,
24
- ].compact.freeze
25
-
26
- def self.document_type?(input)
27
- @document_types.include?(input.class)
28
- end
29
-
30
- def self.simple_type?(input)
31
- @simple_types.include?(input.class) || [true, false].include?(input)
32
- end
33
-
34
- def self.static_file_to_json(input, depth, max_depth)
35
- path = input.relative_path.sub(%r!^\/+!, "")
36
- url = Jekyll::VERSION.start_with?("2.") ? "/#{path}" : input.url
37
-
38
- out = [
39
- "\"path\": #{JsonifyFilter.to_json(path, depth, max_depth)}",
40
- "\"url\": #{JsonifyFilter.to_json(url, depth, max_depth)}",
41
- ]
42
-
43
- "{#{out.join(",")}}"
44
- end
45
-
46
- def self.document_data_to_a(data, prevent, depth, max_depth)
47
- prevent += %w(content output next previous excerpt)
48
-
49
- out = data.map do |key, value|
50
- next if prevent.include?(key) || key.nil?
51
-
52
- prevent.push key
53
- next_max_depth = %w(_array_structures _structures).include?(key) ? 20 : max_depth
54
- "#{key.to_json}: #{JsonifyFilter.to_json(value, depth, next_max_depth)}"
55
- end
56
-
57
- out.compact
58
- end
59
-
60
- def self.legacy_post_to_json(input, depth, max_depth)
61
- prevent = %w(dir name path url date id categories tags)
62
-
63
- out = [
64
- "\"name\": #{JsonifyFilter.to_json(input.name, depth, max_depth)}",
65
- "\"path\": #{JsonifyFilter.to_json(input.path, depth, max_depth)}",
66
- "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
67
- "\"date\": #{JsonifyFilter.to_json(input.date, depth, max_depth)}",
68
- "\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}",
69
- "\"categories\": #{JsonifyFilter.to_json(input.categories, depth, max_depth)}",
70
- "\"tags\": #{JsonifyFilter.to_json(input.tags, depth, max_depth)}",
71
- ]
72
-
73
- out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
74
- "{#{out.join(",")}}"
75
- end
76
-
77
- def self.page_to_json(input, depth, max_depth)
78
- prevent = %w(dir name path url)
79
-
80
- out = [
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
- ]
85
-
86
- # Merge Jekyll Defaults into data for pages (missing at v3.8.5)
87
- defaults = input.site.frontmatter_defaults.all(input.relative_path, :pages).tap do |default|
88
- default.delete("date")
89
- end
90
-
91
- data = Jekyll::Utils.deep_merge_hashes(defaults, input.data)
92
-
93
- out += JsonifyFilter.document_data_to_a(data, prevent, depth, max_depth)
94
- "{#{out.join(",")}}"
95
- end
96
-
97
- def self.document_path(input)
98
- collections_dir = input.site.config["collections_dir"] || ""
99
- if input.collection && !collections_dir.empty?
100
- "#{collections_dir}/#{input.relative_path}"
101
- else
102
- input.relative_path
103
- end
104
- end
105
-
106
- def self.document_to_json(input, depth, max_depth)
107
- prevent = %w(dir relative_path url collection)
108
-
109
- out = [
110
- "\"path\": #{JsonifyFilter.to_json(JsonifyFilter.document_path(input), depth, max_depth)}",
111
- "\"url\": #{JsonifyFilter.to_json(input.url, depth, max_depth)}",
112
- ]
113
-
114
- unless input.collection.nil?
115
- collection_json = JsonifyFilter.to_json(input.collection.label, depth, max_depth)
116
- out.push("\"collection\": #{collection_json}")
117
- end
118
-
119
- if input.respond_to? :id
120
- out.push("\"id\": #{JsonifyFilter.to_json(input.id, depth, max_depth)}")
121
- end
122
-
123
- out += JsonifyFilter.document_data_to_a(input.data, prevent, depth, max_depth)
124
- "{#{out.join(",")}}"
125
- end
126
-
127
- def self.array_to_json(input, depth, max_depth)
128
- array = input.map do |value|
129
- JsonifyFilter.to_json(value, depth, max_depth)
130
- end
131
-
132
- "[#{array.join(",")}]"
133
- end
134
-
135
- def self.hash_to_json(input, depth, max_depth)
136
- out = input.map do |key, value|
137
- next_max_depth = %w(_array_structures _structures).include?(key) ? 20 : max_depth
138
- string_key = key.to_s.to_json
139
- "#{string_key}: #{JsonifyFilter.to_json(value, depth, next_max_depth)}"
140
- end
141
-
142
- "{#{out.join(",")}}"
143
- end
144
-
145
- def self.config_to_select_data_json(input, depth)
146
- prevent = %w(source destination collections_dir cache_dir plugins_dir layouts_dir data_dir
147
- includes_dir collections safe include exclude keep_files encoding markdown_ext
148
- strict_front_matter show_drafts limit_posts future unpublished whitelist
149
- plugins markdown highlighter lsi excerpt_separator incremental detach port host
150
- baseurl show_dir_listing permalink paginate_path timezone quiet verbose defaults
151
- liquid kramdown title url description uploads_dir _comments _options _editor
152
- _explore _source_editor _array_structures maruku redcloth rdiscount redcarpet
153
- gems plugins cloudcannon _collection_groups _enabled_editors _instance_values)
154
-
155
- out = input.map do |key, value|
156
- next unless value.is_a?(Array) || value.is_a?(Hash)
157
- next if prevent.include?(key) || key.nil?
158
-
159
- prevent.push key
160
- "#{key.to_s.to_json}: #{JsonifyFilter.to_json(value, depth)}"
161
- end
162
-
163
- out.compact!
164
-
165
- "{#{out.join(",")}}" if out.any?
166
- end
167
-
168
- def self.to_json(input, depth, max_depth = 12)
169
- depth += 1
170
-
171
- if depth > max_depth || (depth > 3 && JsonifyFilter.document_type?(input))
172
- '"MAXIMUM_DEPTH"'
173
- elsif JsonifyFilter.simple_type?(input)
174
- input.to_json
175
- elsif input.is_a?(Jekyll::StaticFile)
176
- JsonifyFilter.static_file_to_json(input, depth, max_depth)
177
- elsif input.is_a?(Jekyll::Page)
178
- JsonifyFilter.page_to_json(input, depth, max_depth)
179
- elsif Jekyll::VERSION.start_with?("2.") && input.is_a?(Jekyll::Post)
180
- JsonifyFilter.legacy_post_to_json(input, depth, max_depth)
181
- elsif input.is_a?(Jekyll::Document)
182
- JsonifyFilter.document_to_json(input, depth, max_depth)
183
- elsif input.is_a?(Array)
184
- JsonifyFilter.array_to_json(input, depth, max_depth)
185
- elsif input.is_a?(Hash)
186
- JsonifyFilter.hash_to_json(input, depth, max_depth)
187
- else
188
- input.class.to_s.prepend("UNSUPPORTED:").to_json
189
- end
190
- end
191
-
192
- def cc_static_files_jsonify(input)
193
- out = input.map do |page|
194
- JsonifyFilter.to_json(page, 1) if STATIC_EXTENSIONS.include?(page.extname)
195
- end
196
-
197
- out.compact!
198
-
199
- "[#{out.join(",")}]"
200
- end
201
-
202
- def cc_select_data_jsonify(input)
203
- if input.key? "_select_data"
204
- JsonifyFilter.to_json(input["_select_data"], 0)
205
- else
206
- JsonifyFilter.config_to_select_data_json(input, 0)
207
- end
208
- end
209
-
210
- def cc_jsonify(input, max_depth = 12)
211
- JsonifyFilter.to_json(input, 0, max_depth)
212
- end
213
- end
214
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CloudCannonJekyll
4
- # Utility class to help generate files with no source file
5
- class PageWithoutAFile < Jekyll::Page
6
- def read_yaml(*)
7
- @data ||= {}
8
- end
9
- end
10
- end
data/script/cibuild DELETED
@@ -1,6 +0,0 @@
1
- #!/bin/sh
2
-
3
- set -ex
4
-
5
- $(dirname "$0")/test
6
- bundle exec gem build cloudcannon-jekyll.gemspec