cloudcannon-jekyll-bookshop 2.0.0.pre.alpha.50 → 2.0.0.pre.beta.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1290a552703bf872ecc6c91d8e704adbfcd984eee28af72d7154d4e837608728
4
- data.tar.gz: 46e49232296188854d57ab0dcd01233a56ed05953e54d2c73f7785bbc24817d7
3
+ metadata.gz: bd8c2ba588f6b89fcf9cb861edf99800e194f5934d27f73d9d15dc2088d3913f
4
+ data.tar.gz: 4d8cd72ed22f8fe5906f46d4883be86b4f024aa3cbafc3df42e39d0133324e98
5
5
  SHA512:
6
- metadata.gz: c0ea17c7fb415fb08bbbfa0f74ed2a7ceeeb478ce3801088717d98ce4acf6809b3c1719264d02a049570bce258c60f73c8201db71d87e670253bc1ab957c8610
7
- data.tar.gz: 368ec0fee6b6a0f605ee5c14ed889cf0fcf08e67a8d134086b7f7025deea4f618bba9917ec24c2b812524b77394a5634ae9717c36b43c5480991c245fb9b48dc
6
+ metadata.gz: 5f6397f010efe1ce2a280cd9acb06646a685dfbb2c7ca6ed8037d3fd901ac58b577319683c3f653bbbfd67646d7bd553be9eb0a775583f168569313d80c5bf39
7
+ data.tar.gz: f87628966e928f57f30973a3fa99bf512fd603bc48e29a4a468f10e2a4a6dd9c68b5fe1df5a133c2739038efc0f81b796a67831e4c5ef6d8d6fadc19580d1194
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudcannon-jekyll-bookshop (2.0.0.pre.alpha.50)
4
+ cloudcannon-jekyll-bookshop (2.0.0.pre.beta.1)
5
5
  dry-inflector (>= 0.1, < 1.0)
6
6
  jekyll (>= 3.7, < 5.0)
7
7
  node-runner (>= 1.0, < 2.0)
@@ -13,10 +13,8 @@ Gem::Specification.new do |spec|
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
14
 
15
15
  # Specify which files should be added to the gem when it is released.
16
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- end
16
+ spec.files = Dir['**/*'].reject { |f| f.match(%r{^(test|spec|features)}) }
17
+
20
18
  spec.bindir = "exe"
21
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
20
  spec.require_paths = ["lib"]
@@ -30,7 +30,7 @@ module CloudCannonJekyllBookshop
30
30
  component = parse_bookshop_toml(path)
31
31
  rescue StandardError => e
32
32
  Jekyll.logger.error "Bookshop:",
33
- "❌ Error Parsing Story: #{f}"
33
+ "❌ Error Parsing Story: #{e}"
34
34
  Jekyll.logger.error "",
35
35
  e.message
36
36
  end
@@ -76,8 +76,8 @@ module CloudCannonJekyllBookshop
76
76
  @inflector = Dry::Inflector.new
77
77
  @node_bookshop = NodeRunner.new(
78
78
  <<~JAVASCRIPT
79
- const {Version: TNVersion, RewriteTOML} = require('@bookshop/toml-narrator');
80
- const {Version: CSVersion, TransformComponent, GetComponentKey, NiceLabel} = require('@bookshop/cloudcannon-structures');
79
+ const {Version: TNVersion, RewriteTOML} = require('#{__dir__}/../../node_modules/@bookshop/toml-narrator');
80
+ const {Version: CSVersion, TransformComponent, GetComponentKey, NiceLabel} = require('#{__dir__}/../../node_modules/@bookshop/cloudcannon-structures');
81
81
  JAVASCRIPT
82
82
  )
83
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CloudCannonJekyllBookshop
4
- VERSION = "2.0.0.pre.alpha.50"
4
+ VERSION = "2.0.0.pre.beta.1"
5
5
  end
@@ -0,0 +1,152 @@
1
+ var pkg = require('./package.json');
2
+ // Pluralize is vendored for distribution to the generator plugins
3
+ const pluralize = require('./vendored-pluralize.js');
4
+
5
+ // Generates the bookshop key used to reference this component
6
+ // Turns "a/b/b.bookshop.toml" into "a/b"
7
+ const GetComponentKey = (componentPath) => {
8
+ let base = componentPath.replace(/^.*components\//, '').split(".")[0];
9
+ let parts = base.split("/");
10
+ const l = parts.length;
11
+ if (l >= 2 && parts[l-1] === parts[l-2]) {
12
+ parts.pop();
13
+ base = parts.join("/");
14
+ }
15
+ return base;
16
+ }
17
+
18
+ const NiceLabel = (key) => {
19
+ return key.split(/-|_|\//)
20
+ .filter(part => part.length)
21
+ .map(part => part[0].toUpperCase() + part.slice(1)).join(" ");
22
+ }
23
+
24
+ // Main function that takes in an entire Bookshop component structure
25
+ // and returns a set of structures to add to CloudCannon
26
+ const TransformComponent = (path, component) => {
27
+ const result = {
28
+ value: {
29
+ _bookshop_name: GetComponentKey(path)
30
+ },
31
+ label: NiceLabel(GetComponentKey(path)), // Used as a fallback when no label is supplied inside [component]
32
+ array_structures: [],
33
+ ...component["component"]
34
+ }
35
+ if (component["props"]) {
36
+ TransformComponentProps(component["props"], result, null);
37
+ }
38
+ if (!result["_hidden"] && !result["array_structures"].includes("bookshop_components")) {
39
+ result["array_structures"].push("bookshop_components");
40
+ }
41
+
42
+ const results = [result];
43
+
44
+ delete result["_hidden"];
45
+ delete result["raw_fields"];
46
+
47
+ return results;
48
+ }
49
+
50
+ // Recursive function for processing the [props] section of a bookshop component spec,
51
+ // and populating sub-structures, comments, select data, et cetera.
52
+ const TransformComponentProps = (props, structure, value_context) => {
53
+ ["_select_data","_array_structures","_comments","value"].forEach(k => {
54
+ structure[k] = structure[k] || {};
55
+ });
56
+
57
+ value_context = value_context || structure["value"];
58
+ Object.entries(props).forEach(([key, value]) => {
59
+ if (Object.hasOwnProperty.call(value_context, key)) return;
60
+
61
+ if (Array.isArray(value)) {
62
+ TransformArray(key, value, structure, value_context);
63
+ return;
64
+ }
65
+
66
+ if (value && typeof value === "object") {
67
+ TransformObject(key, value, structure, value_context);
68
+ return;
69
+ }
70
+
71
+ if (value === true || value === false) {
72
+ value_context[key] = value;
73
+ return;
74
+ }
75
+
76
+ if (/--bookshop_comment/.test(key)) {
77
+ const base_key = key.split(/--bookshop_comment/)[0];
78
+ if (!base_key.length) return;
79
+ structure["_comments"][base_key] = value;
80
+ return;
81
+ }
82
+
83
+ value_context[key] = null;
84
+ });
85
+ }
86
+
87
+ // Handle an object somewhere within the large props object
88
+ // If reserved bookshop keys lie within, the object is treated as a value
89
+ // Otherwise, recurse into it as a normal object
90
+ const TransformObject = (key, obj, structure, value_context) => {
91
+ const comment = GetCommentFromObject(obj);
92
+ if (comment) {
93
+ structure["_comments"][key] = comment;
94
+ }
95
+
96
+ if (Object.hasOwnProperty.call(obj, "select")) {
97
+ value_context[key] = obj["default"] ?? null;
98
+ structure["_select_data"][pluralize(key)] = obj["select"]
99
+ return
100
+ }
101
+
102
+ if (Object.hasOwnProperty.call(obj, "preview") || Object.hasOwnProperty.call(obj, "default")) {
103
+ value_context[key] = obj["default"] ?? null;
104
+ return
105
+ }
106
+
107
+ value_context[key] = {};
108
+ TransformComponentProps(obj, structure, value_context[key]);
109
+ }
110
+
111
+ // Handle an array somewhere within the large props object
112
+ // If it is an object array, create a sub-structure based on the first array item
113
+ const TransformArray = (key, array, structure, value_context) => {
114
+ if (array[0] && typeof array[0] === "object") {
115
+ if (array[0]["--bookshop_comment"]) {
116
+ structure["_comments"][key] = array[0]["--bookshop_comment"];
117
+ }
118
+
119
+ if (Array.isArray(structure["raw_fields"]) && structure["raw_fields"].includes(key)) {
120
+ value_context[key] = null;
121
+ return
122
+ }
123
+
124
+ const singular_title = NiceLabel(pluralize.singular(key));
125
+ structure["_array_structures"][key] = {
126
+ values: [{
127
+ label: singular_title,
128
+ icon: "add_box",
129
+ value: {}
130
+ }]
131
+ }
132
+
133
+ TransformComponentProps(array[0],
134
+ structure["_array_structures"][key]["values"][0],
135
+ structure["_array_structures"][key]["values"][0]["value"]);
136
+ }
137
+ value_context[key] = [];
138
+ }
139
+
140
+ const GetCommentFromObject = (object) => {
141
+ return object["--bookshop_comment"]
142
+ || object["select--bookshop_comment"]
143
+ || object["preview--bookshop_comment"]
144
+ || object["default--bookshop_comment"]
145
+ }
146
+
147
+ module.exports = {
148
+ Version: () => pkg.version,
149
+ TransformComponent,
150
+ GetComponentKey,
151
+ NiceLabel,
152
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@bookshop/cloudcannon-structures",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Convert a Bookshop object into a CloudCannon structure",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "ava -v"
8
+ },
9
+ "files": [
10
+ "main.js",
11
+ "vendored-pluralize.js"
12
+ ],
13
+ "author": "@bglw",
14
+ "license": "MIT",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "devDependencies": {
19
+ "@bookshop/toml-narrator": "file:../toml-narrator",
20
+ "@ltd/j-toml": "^1.12.2",
21
+ "ava": "^3.15.0",
22
+ "pluralize": "^8.0.0"
23
+ },
24
+ "engines": {
25
+ "npm": "please-use-yarn"
26
+ }
27
+ }
@@ -0,0 +1,503 @@
1
+ /* global define */
2
+
3
+ (function (root, pluralize) {
4
+ /* istanbul ignore else */
5
+ if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
6
+ // Node.
7
+ module.exports = pluralize();
8
+ } else if (typeof define === 'function' && define.amd) {
9
+ // AMD, registers as an anonymous module.
10
+ define(function () {
11
+ return pluralize();
12
+ });
13
+ } else {
14
+ // Browser global.
15
+ root.pluralize = pluralize();
16
+ }
17
+ })(this, function () {
18
+ // Rule storage - pluralize and singularize need to be run sequentially,
19
+ // while other rules can be optimized using an object for instant lookups.
20
+ var pluralRules = [];
21
+ var singularRules = [];
22
+ var uncountables = {};
23
+ var irregularPlurals = {};
24
+ var irregularSingles = {};
25
+
26
+ /**
27
+ * Sanitize a pluralization rule to a usable regular expression.
28
+ *
29
+ * @param {(RegExp|string)} rule
30
+ * @return {RegExp}
31
+ */
32
+ function sanitizeRule (rule) {
33
+ if (typeof rule === 'string') {
34
+ return new RegExp('^' + rule + '$', 'i');
35
+ }
36
+
37
+ return rule;
38
+ }
39
+
40
+ /**
41
+ * Pass in a word token to produce a function that can replicate the case on
42
+ * another word.
43
+ *
44
+ * @param {string} word
45
+ * @param {string} token
46
+ * @return {Function}
47
+ */
48
+ function restoreCase (word, token) {
49
+ // Tokens are an exact match.
50
+ if (word === token) return token;
51
+
52
+ // Lower cased words. E.g. "hello".
53
+ if (word === word.toLowerCase()) return token.toLowerCase();
54
+
55
+ // Upper cased words. E.g. "WHISKY".
56
+ if (word === word.toUpperCase()) return token.toUpperCase();
57
+
58
+ // Title cased words. E.g. "Title".
59
+ if (word[0] === word[0].toUpperCase()) {
60
+ return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
61
+ }
62
+
63
+ // Lower cased words. E.g. "test".
64
+ return token.toLowerCase();
65
+ }
66
+
67
+ /**
68
+ * Interpolate a regexp string.
69
+ *
70
+ * @param {string} str
71
+ * @param {Array} args
72
+ * @return {string}
73
+ */
74
+ function interpolate (str, args) {
75
+ return str.replace(/\$(\d{1,2})/g, function (match, index) {
76
+ return args[index] || '';
77
+ });
78
+ }
79
+
80
+ /**
81
+ * Replace a word using a rule.
82
+ *
83
+ * @param {string} word
84
+ * @param {Array} rule
85
+ * @return {string}
86
+ */
87
+ function replace (word, rule) {
88
+ return word.replace(rule[0], function (match, index) {
89
+ var result = interpolate(rule[1], arguments);
90
+
91
+ if (match === '') {
92
+ return restoreCase(word[index - 1], result);
93
+ }
94
+
95
+ return restoreCase(match, result);
96
+ });
97
+ }
98
+
99
+ /**
100
+ * Sanitize a word by passing in the word and sanitization rules.
101
+ *
102
+ * @param {string} token
103
+ * @param {string} word
104
+ * @param {Array} rules
105
+ * @return {string}
106
+ */
107
+ function sanitizeWord (token, word, rules) {
108
+ // Empty string or doesn't need fixing.
109
+ if (!token.length || uncountables.hasOwnProperty(token)) {
110
+ return word;
111
+ }
112
+
113
+ var len = rules.length;
114
+
115
+ // Iterate over the sanitization rules and use the first one to match.
116
+ while (len--) {
117
+ var rule = rules[len];
118
+
119
+ if (rule[0].test(word)) return replace(word, rule);
120
+ }
121
+
122
+ return word;
123
+ }
124
+
125
+ /**
126
+ * Replace a word with the updated word.
127
+ *
128
+ * @param {Object} replaceMap
129
+ * @param {Object} keepMap
130
+ * @param {Array} rules
131
+ * @return {Function}
132
+ */
133
+ function replaceWord (replaceMap, keepMap, rules) {
134
+ return function (word) {
135
+ // Get the correct token and case restoration functions.
136
+ var token = word.toLowerCase();
137
+
138
+ // Check against the keep object map.
139
+ if (keepMap.hasOwnProperty(token)) {
140
+ return restoreCase(word, token);
141
+ }
142
+
143
+ // Check against the replacement map for a direct word replacement.
144
+ if (replaceMap.hasOwnProperty(token)) {
145
+ return restoreCase(word, replaceMap[token]);
146
+ }
147
+
148
+ // Run all the rules against the word.
149
+ return sanitizeWord(token, word, rules);
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Check if a word is part of the map.
155
+ */
156
+ function checkWord (replaceMap, keepMap, rules, bool) {
157
+ return function (word) {
158
+ var token = word.toLowerCase();
159
+
160
+ if (keepMap.hasOwnProperty(token)) return true;
161
+ if (replaceMap.hasOwnProperty(token)) return false;
162
+
163
+ return sanitizeWord(token, token, rules) === token;
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Pluralize or singularize a word based on the passed in count.
169
+ *
170
+ * @param {string} word The word to pluralize
171
+ * @param {number} count How many of the word exist
172
+ * @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
173
+ * @return {string}
174
+ */
175
+ function pluralize (word, count, inclusive) {
176
+ var pluralized = count === 1
177
+ ? pluralize.singular(word) : pluralize.plural(word);
178
+
179
+ return (inclusive ? count + ' ' : '') + pluralized;
180
+ }
181
+
182
+ /**
183
+ * Pluralize a word.
184
+ *
185
+ * @type {Function}
186
+ */
187
+ pluralize.plural = replaceWord(
188
+ irregularSingles, irregularPlurals, pluralRules
189
+ );
190
+
191
+ /**
192
+ * Check if a word is plural.
193
+ *
194
+ * @type {Function}
195
+ */
196
+ pluralize.isPlural = checkWord(
197
+ irregularSingles, irregularPlurals, pluralRules
198
+ );
199
+
200
+ /**
201
+ * Singularize a word.
202
+ *
203
+ * @type {Function}
204
+ */
205
+ pluralize.singular = replaceWord(
206
+ irregularPlurals, irregularSingles, singularRules
207
+ );
208
+
209
+ /**
210
+ * Check if a word is singular.
211
+ *
212
+ * @type {Function}
213
+ */
214
+ pluralize.isSingular = checkWord(
215
+ irregularPlurals, irregularSingles, singularRules
216
+ );
217
+
218
+ /**
219
+ * Add a pluralization rule to the collection.
220
+ *
221
+ * @param {(string|RegExp)} rule
222
+ * @param {string} replacement
223
+ */
224
+ pluralize.addPluralRule = function (rule, replacement) {
225
+ pluralRules.push([sanitizeRule(rule), replacement]);
226
+ };
227
+
228
+ /**
229
+ * Add a singularization rule to the collection.
230
+ *
231
+ * @param {(string|RegExp)} rule
232
+ * @param {string} replacement
233
+ */
234
+ pluralize.addSingularRule = function (rule, replacement) {
235
+ singularRules.push([sanitizeRule(rule), replacement]);
236
+ };
237
+
238
+ /**
239
+ * Add an uncountable word rule.
240
+ *
241
+ * @param {(string|RegExp)} word
242
+ */
243
+ pluralize.addUncountableRule = function (word) {
244
+ if (typeof word === 'string') {
245
+ uncountables[word.toLowerCase()] = true;
246
+ return;
247
+ }
248
+
249
+ // Set singular and plural references for the word.
250
+ pluralize.addPluralRule(word, '$0');
251
+ pluralize.addSingularRule(word, '$0');
252
+ };
253
+
254
+ /**
255
+ * Add an irregular word definition.
256
+ *
257
+ * @param {string} single
258
+ * @param {string} plural
259
+ */
260
+ pluralize.addIrregularRule = function (single, plural) {
261
+ plural = plural.toLowerCase();
262
+ single = single.toLowerCase();
263
+
264
+ irregularSingles[single] = plural;
265
+ irregularPlurals[plural] = single;
266
+ };
267
+
268
+ /**
269
+ * Irregular rules.
270
+ */
271
+ [
272
+ // Pronouns.
273
+ ['I', 'we'],
274
+ ['me', 'us'],
275
+ ['he', 'they'],
276
+ ['she', 'they'],
277
+ ['them', 'them'],
278
+ ['myself', 'ourselves'],
279
+ ['yourself', 'yourselves'],
280
+ ['itself', 'themselves'],
281
+ ['herself', 'themselves'],
282
+ ['himself', 'themselves'],
283
+ ['themself', 'themselves'],
284
+ ['is', 'are'],
285
+ ['was', 'were'],
286
+ ['has', 'have'],
287
+ ['this', 'these'],
288
+ ['that', 'those'],
289
+ // Words ending in with a consonant and `o`.
290
+ ['echo', 'echoes'],
291
+ ['dingo', 'dingoes'],
292
+ ['volcano', 'volcanoes'],
293
+ ['tornado', 'tornadoes'],
294
+ ['torpedo', 'torpedoes'],
295
+ // Ends with `us`.
296
+ ['genus', 'genera'],
297
+ ['viscus', 'viscera'],
298
+ // Ends with `ma`.
299
+ ['stigma', 'stigmata'],
300
+ ['stoma', 'stomata'],
301
+ ['dogma', 'dogmata'],
302
+ ['lemma', 'lemmata'],
303
+ ['schema', 'schemata'],
304
+ ['anathema', 'anathemata'],
305
+ // Other irregular rules.
306
+ ['ox', 'oxen'],
307
+ ['axe', 'axes'],
308
+ ['die', 'dice'],
309
+ ['yes', 'yeses'],
310
+ ['foot', 'feet'],
311
+ ['eave', 'eaves'],
312
+ ['goose', 'geese'],
313
+ ['tooth', 'teeth'],
314
+ ['quiz', 'quizzes'],
315
+ ['human', 'humans'],
316
+ ['proof', 'proofs'],
317
+ ['carve', 'carves'],
318
+ ['valve', 'valves'],
319
+ ['looey', 'looies'],
320
+ ['thief', 'thieves'],
321
+ ['groove', 'grooves'],
322
+ ['pickaxe', 'pickaxes'],
323
+ ['passerby', 'passersby']
324
+ ].forEach(function (rule) {
325
+ return pluralize.addIrregularRule(rule[0], rule[1]);
326
+ });
327
+
328
+ /**
329
+ * Pluralization rules.
330
+ */
331
+ [
332
+ [/s?$/i, 's'],
333
+ [/[^\u0000-\u007F]$/i, '$0'],
334
+ [/([^aeiou]ese)$/i, '$1'],
335
+ [/(ax|test)is$/i, '$1es'],
336
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
337
+ [/(e[mn]u)s?$/i, '$1s'],
338
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
339
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
340
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
341
+ [/(seraph|cherub)(?:im)?$/i, '$1im'],
342
+ [/(her|at|gr)o$/i, '$1oes'],
343
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
344
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
345
+ [/sis$/i, 'ses'],
346
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
347
+ [/([^aeiouy]|qu)y$/i, '$1ies'],
348
+ [/([^ch][ieo][ln])ey$/i, '$1ies'],
349
+ [/(x|ch|ss|sh|zz)$/i, '$1es'],
350
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
351
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
352
+ [/(pe)(?:rson|ople)$/i, '$1ople'],
353
+ [/(child)(?:ren)?$/i, '$1ren'],
354
+ [/eaux$/i, '$0'],
355
+ [/m[ae]n$/i, 'men'],
356
+ ['thou', 'you']
357
+ ].forEach(function (rule) {
358
+ return pluralize.addPluralRule(rule[0], rule[1]);
359
+ });
360
+
361
+ /**
362
+ * Singularization rules.
363
+ */
364
+ [
365
+ [/s$/i, ''],
366
+ [/(ss)$/i, '$1'],
367
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
368
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
369
+ [/ies$/i, 'y'],
370
+ [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
371
+ [/\b(mon|smil)ies$/i, '$1ey'],
372
+ [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
373
+ [/(seraph|cherub)im$/i, '$1'],
374
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
375
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
376
+ [/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
377
+ [/(test)(?:is|es)$/i, '$1is'],
378
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
379
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
380
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
381
+ [/(alumn|alg|vertebr)ae$/i, '$1a'],
382
+ [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
383
+ [/(matr|append)ices$/i, '$1ix'],
384
+ [/(pe)(rson|ople)$/i, '$1rson'],
385
+ [/(child)ren$/i, '$1'],
386
+ [/(eau)x?$/i, '$1'],
387
+ [/men$/i, 'man']
388
+ ].forEach(function (rule) {
389
+ return pluralize.addSingularRule(rule[0], rule[1]);
390
+ });
391
+
392
+ /**
393
+ * Uncountable rules.
394
+ */
395
+ [
396
+ // Singular words with no plurals.
397
+ 'adulthood',
398
+ 'advice',
399
+ 'agenda',
400
+ 'aid',
401
+ 'aircraft',
402
+ 'alcohol',
403
+ 'ammo',
404
+ 'analytics',
405
+ 'anime',
406
+ 'athletics',
407
+ 'audio',
408
+ 'bison',
409
+ 'blood',
410
+ 'bream',
411
+ 'buffalo',
412
+ 'butter',
413
+ 'carp',
414
+ 'cash',
415
+ 'chassis',
416
+ 'chess',
417
+ 'clothing',
418
+ 'cod',
419
+ 'commerce',
420
+ 'cooperation',
421
+ 'corps',
422
+ 'debris',
423
+ 'diabetes',
424
+ 'digestion',
425
+ 'elk',
426
+ 'energy',
427
+ 'equipment',
428
+ 'excretion',
429
+ 'expertise',
430
+ 'firmware',
431
+ 'flounder',
432
+ 'fun',
433
+ 'gallows',
434
+ 'garbage',
435
+ 'graffiti',
436
+ 'hardware',
437
+ 'headquarters',
438
+ 'health',
439
+ 'herpes',
440
+ 'highjinks',
441
+ 'homework',
442
+ 'housework',
443
+ 'information',
444
+ 'jeans',
445
+ 'justice',
446
+ 'kudos',
447
+ 'labour',
448
+ 'literature',
449
+ 'machinery',
450
+ 'mackerel',
451
+ 'mail',
452
+ 'media',
453
+ 'mews',
454
+ 'moose',
455
+ 'music',
456
+ 'mud',
457
+ 'manga',
458
+ 'news',
459
+ 'only',
460
+ 'personnel',
461
+ 'pike',
462
+ 'plankton',
463
+ 'pliers',
464
+ 'police',
465
+ 'pollution',
466
+ 'premises',
467
+ 'rain',
468
+ 'research',
469
+ 'rice',
470
+ 'salmon',
471
+ 'scissors',
472
+ 'series',
473
+ 'sewage',
474
+ 'shambles',
475
+ 'shrimp',
476
+ 'software',
477
+ 'species',
478
+ 'staff',
479
+ 'swine',
480
+ 'tennis',
481
+ 'traffic',
482
+ 'transportation',
483
+ 'trout',
484
+ 'tuna',
485
+ 'wealth',
486
+ 'welfare',
487
+ 'whiting',
488
+ 'wildebeest',
489
+ 'wildlife',
490
+ 'you',
491
+ /pok[eé]mon$/i,
492
+ // Regexes.
493
+ /[^aeiou]ese$/i, // "chinese", "japanese"
494
+ /deer$/i, // "deer", "reindeer"
495
+ /fish$/i, // "fish", "blowfish", "angelfish"
496
+ /measles$/i,
497
+ /o[iu]s$/i, // "carnivorous"
498
+ /pox$/i, // "chickpox", "smallpox"
499
+ /sheep$/i
500
+ ].forEach(pluralize.addUncountableRule);
501
+
502
+ return pluralize;
503
+ });
@@ -0,0 +1,30 @@
1
+ var pkg = require('./package.json');
2
+ module.exports = {
3
+ Version: () => pkg.version,
4
+ RewriteTOML: (input_toml) => {
5
+ return input_toml.split(`\n`).map(line => {
6
+ // some_variable.etc = "some value" #: Some comment
7
+ const isVariableComment = /^[a-z0-9\-_\.\s]+=.*?#.+?$/i;
8
+ // [some_section] #: Some comment
9
+ const isBlockComment = /^\s*?\[.*?#.+?$/i;
10
+
11
+ const extractComment = /#:([^#]+)$/i;
12
+ const extractVariable = /^\s*?([a-z0-9\-_\.]+)\s?=/i;
13
+
14
+ if (isVariableComment.test(line)) {
15
+ const [, comment] = extractComment.exec(line) || [];
16
+ const [, variable_name] = extractVariable.exec(line) || [];
17
+ if (!comment || !variable_name) return line;
18
+
19
+ return `${variable_name}--bookshop_comment = "${comment.trim()}"\n${line}`
20
+ } else if (isBlockComment.test(line)) {
21
+ const [, comment] = extractComment.exec(line) || [];
22
+ if (!comment) return line;
23
+
24
+ return `${line}\n--bookshop_comment = "${comment.trim()}"`
25
+ } else {
26
+ return line;
27
+ }
28
+ }).join(`\n`);
29
+ }
30
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@bookshop/toml-narrator",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Rewrite Bookshop TOML files to preserve comments",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "ava -v"
8
+ },
9
+ "files": [
10
+ "main.js"
11
+ ],
12
+ "author": "@bglw",
13
+ "license": "MIT",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "devDependencies": {
18
+ "ava": "^3.15.0"
19
+ },
20
+ "engines": {
21
+ "npm": "please-use-yarn"
22
+ }
23
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudcannon-jekyll-bookshop
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.50
4
+ version: 2.0.0.pre.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Bigelow
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-26 00:00:00.000000000 Z
11
+ date: 2021-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -145,7 +145,6 @@ executables: []
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
- - ".rubocop.yml"
149
148
  - Gemfile
150
149
  - Gemfile.lock
151
150
  - Rakefile
@@ -155,6 +154,11 @@ files:
155
154
  - lib/cloudcannon-jekyll-bookshop/page-without-a-file.rb
156
155
  - lib/cloudcannon-jekyll-bookshop/structures.rb
157
156
  - lib/cloudcannon-jekyll-bookshop/version.rb
157
+ - node_modules/@bookshop/cloudcannon-structures/main.js
158
+ - node_modules/@bookshop/cloudcannon-structures/package.json
159
+ - node_modules/@bookshop/cloudcannon-structures/vendored-pluralize.js
160
+ - node_modules/@bookshop/toml-narrator/main.js
161
+ - node_modules/@bookshop/toml-narrator/package.json
158
162
  homepage: https://github.com/cloudcannon/bookshop
159
163
  licenses:
160
164
  - MIT
data/.rubocop.yml DELETED
@@ -1,27 +0,0 @@
1
- require: rubocop-jekyll
2
-
3
- inherit_gem:
4
- rubocop-jekyll: .rubocop.yml
5
-
6
- AllCops:
7
- TargetRubyVersion: 2.4
8
- Include:
9
- - lib/**/*.rb
10
- - spec/**/*.rb
11
-
12
- Exclude:
13
- - .gitignore
14
- - .rspec
15
- - .rubocop.yml
16
- - .travis.yml
17
- - Gemfile.lock
18
- - HISTORY.md
19
- - LICENSE.txt
20
- - README.md
21
- - script/**/*
22
- - vendor/**/*
23
- - gemfiles/**/*
24
-
25
- Naming/MemoizedInstanceVariableName:
26
- Exclude:
27
- - lib/cloudcannon-jekyll-bookshop/page-without-a-file.rb