cloudcannon-jekyll-bookshop 2.0.0.pre.alpha.50 → 2.0.0.pre.alpha.51

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: 1290a552703bf872ecc6c91d8e704adbfcd984eee28af72d7154d4e837608728
4
- data.tar.gz: 46e49232296188854d57ab0dcd01233a56ed05953e54d2c73f7785bbc24817d7
3
+ metadata.gz: 9ef366c531882bb8bac078097d5e9cea956f1ebf8987d6ed90b2cc79d9d14905
4
+ data.tar.gz: d41ff47e21fd66b3d95aa55887ed26b37f3bd0f597316adc5859a5f942a17475
5
5
  SHA512:
6
- metadata.gz: c0ea17c7fb415fb08bbbfa0f74ed2a7ceeeb478ce3801088717d98ce4acf6809b3c1719264d02a049570bce258c60f73c8201db71d87e670253bc1ab957c8610
7
- data.tar.gz: 368ec0fee6b6a0f605ee5c14ed889cf0fcf08e67a8d134086b7f7025deea4f618bba9917ec24c2b812524b77394a5634ae9717c36b43c5480991c245fb9b48dc
6
+ metadata.gz: dacddcac6459b59abe23a9c45f349463aed9b6f96b5fb31e158e324e1c186ab8c4ede41657faf3f56dab855a96bc0b377954faa3c57c3bdc8177b9b77a95c88e
7
+ data.tar.gz: 20f366066b80e654d28adaa7fd20bdceb235e9bb72585be7d260315283ce70f3b97d938301980194db41820f4453b2c37569d42dad3a70047bb35685ad001d6e
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.alpha.51)
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
@@ -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.alpha.51"
5
5
  end
@@ -0,0 +1,151 @@
1
+ var pkg = require('./package.json');
2
+ const pluralize = require('pluralize');
3
+
4
+ // Generates the bookshop key used to reference this component
5
+ // Turns "a/b/b.bookshop.toml" into "a/b"
6
+ const GetComponentKey = (componentPath) => {
7
+ let base = componentPath.split(".")[0];
8
+ let parts = base.split("/");
9
+ const l = parts.length;
10
+ if (l >= 2 && parts[l-1] === parts[l-2]) {
11
+ parts.pop();
12
+ base = parts.join("/");
13
+ }
14
+ return base;
15
+ }
16
+
17
+ const NiceLabel = (key) => {
18
+ return key.split(/-|_|\//)
19
+ .filter(part => part.length)
20
+ .map(part => part[0].toUpperCase() + part.slice(1)).join(" ");
21
+ }
22
+
23
+ // Main function that takes in an entire Bookshop component structure
24
+ // and returns a set of structures to add to CloudCannon
25
+ const TransformComponent = (path, component) => {
26
+ const result = {
27
+ value: {
28
+ _bookshop_name: GetComponentKey(path)
29
+ },
30
+ label: NiceLabel(GetComponentKey(path)), // Used as a fallback when no label is supplied inside [component]
31
+ array_structures: [],
32
+ ...component["component"]
33
+ }
34
+ if (component["props"]) {
35
+ TransformComponentProps(component["props"], result, null);
36
+ }
37
+ if (!result["_hidden"] && !result["array_structures"].includes("bookshop_components")) {
38
+ result["array_structures"].push("bookshop_components");
39
+ }
40
+
41
+ const results = [result];
42
+
43
+ delete result["_hidden"];
44
+ delete result["raw_fields"];
45
+
46
+ return results;
47
+ }
48
+
49
+ // Recursive function for processing the [props] section of a bookshop component spec,
50
+ // and populating sub-structures, comments, select data, et cetera.
51
+ const TransformComponentProps = (props, structure, value_context) => {
52
+ ["_select_data","_array_structures","_comments","value"].forEach(k => {
53
+ structure[k] = structure[k] || {};
54
+ });
55
+
56
+ value_context = value_context || structure["value"];
57
+ Object.entries(props).forEach(([key, value]) => {
58
+ if (Object.hasOwnProperty.call(value_context, key)) return;
59
+
60
+ if (Array.isArray(value)) {
61
+ TransformArray(key, value, structure, value_context);
62
+ return;
63
+ }
64
+
65
+ if (value && typeof value === "object") {
66
+ TransformObject(key, value, structure, value_context);
67
+ return;
68
+ }
69
+
70
+ if (value === true || value === false) {
71
+ value_context[key] = value;
72
+ return;
73
+ }
74
+
75
+ if (/--bookshop_comment/.test(key)) {
76
+ const base_key = key.split(/--bookshop_comment/)[0];
77
+ if (!base_key.length) return;
78
+ structure["_comments"][base_key] = value;
79
+ return;
80
+ }
81
+
82
+ value_context[key] = null;
83
+ });
84
+ }
85
+
86
+ // Handle an object somewhere within the large props object
87
+ // If reserved bookshop keys lie within, the object is treated as a value
88
+ // Otherwise, recurse into it as a normal object
89
+ const TransformObject = (key, obj, structure, value_context) => {
90
+ const comment = GetCommentFromObject(obj);
91
+ if (comment) {
92
+ structure["_comments"][key] = comment;
93
+ }
94
+
95
+ if (Object.hasOwnProperty.call(obj, "select")) {
96
+ value_context[key] = obj["default"] ?? null;
97
+ structure["_select_data"][pluralize(key)] = obj["select"]
98
+ return
99
+ }
100
+
101
+ if (Object.hasOwnProperty.call(obj, "preview") || Object.hasOwnProperty.call(obj, "default")) {
102
+ value_context[key] = obj["default"] ?? null;
103
+ return
104
+ }
105
+
106
+ value_context[key] = {};
107
+ TransformComponentProps(obj, structure, value_context[key]);
108
+ }
109
+
110
+ // Handle an array somewhere within the large props object
111
+ // If it is an object array, create a sub-structure based on the first array item
112
+ const TransformArray = (key, array, structure, value_context) => {
113
+ if (array[0] && typeof array[0] === "object") {
114
+ if (array[0]["--bookshop_comment"]) {
115
+ structure["_comments"][key] = array[0]["--bookshop_comment"];
116
+ }
117
+
118
+ if (Array.isArray(structure["raw_fields"]) && structure["raw_fields"].includes(key)) {
119
+ value_context[key] = null;
120
+ return
121
+ }
122
+
123
+ const singular_title = NiceLabel(pluralize.singular(key));
124
+ structure["_array_structures"][key] = {
125
+ values: [{
126
+ label: singular_title,
127
+ icon: "add_box",
128
+ value: {}
129
+ }]
130
+ }
131
+
132
+ TransformComponentProps(array[0],
133
+ structure["_array_structures"][key]["values"][0],
134
+ structure["_array_structures"][key]["values"][0]["value"]);
135
+ }
136
+ value_context[key] = [];
137
+ }
138
+
139
+ const GetCommentFromObject = (object) => {
140
+ return object["--bookshop_comment"]
141
+ || object["select--bookshop_comment"]
142
+ || object["preview--bookshop_comment"]
143
+ || object["default--bookshop_comment"]
144
+ }
145
+
146
+ module.exports = {
147
+ Version: () => pkg.version,
148
+ TransformComponent,
149
+ GetComponentKey,
150
+ NiceLabel,
151
+ }
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Blake Embrey (hello@blakeembrey.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,100 @@
1
+ # Pluralize
2
+
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![NPM downloads][downloads-image]][downloads-url]
5
+ [![Build status][travis-image]][travis-url]
6
+ [![Test coverage][coveralls-image]][coveralls-url]
7
+ ![File Size][filesize-url]
8
+ [![CDNJS][cdnjs-image]][cdnjs-url]
9
+
10
+ > Pluralize and singularize any word.
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ npm install pluralize --save
16
+ yarn add pluralize
17
+ bower install pluralize --save
18
+ ```
19
+
20
+ ### Node
21
+
22
+ ```javascript
23
+ var pluralize = require('pluralize')
24
+ ```
25
+
26
+ ### AMD
27
+
28
+ ```javascript
29
+ define(function (require, exports, module) {
30
+ var pluralize = require('pluralize')
31
+ })
32
+ ```
33
+
34
+ ### `<script>` tag
35
+
36
+ ```html
37
+ <script src="pluralize.js"></script>
38
+ ```
39
+
40
+ ## Why?
41
+
42
+ This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.
43
+
44
+ ## Usage
45
+
46
+ * `word: string` The word to pluralize
47
+ * `count: number` How many of the word exist
48
+ * `inclusive: boolean` Whether to prefix with the number (e.g. 3 ducks)
49
+
50
+ Examples:
51
+
52
+ ```javascript
53
+ pluralize('test') //=> "tests"
54
+ pluralize('test', 0) //=> "tests"
55
+ pluralize('test', 1) //=> "test"
56
+ pluralize('test', 5) //=> "tests"
57
+ pluralize('test', 1, true) //=> "1 test"
58
+ pluralize('test', 5, true) //=> "5 tests"
59
+ pluralize('蘋果', 2, true) //=> "2 蘋果"
60
+
61
+ // Example of new plural rule:
62
+ pluralize.plural('regex') //=> "regexes"
63
+ pluralize.addPluralRule(/gex$/i, 'gexii')
64
+ pluralize.plural('regex') //=> "regexii"
65
+
66
+ // Example of new singular rule:
67
+ pluralize.singular('singles') //=> "single"
68
+ pluralize.addSingularRule(/singles$/i, 'singular')
69
+ pluralize.singular('singles') //=> "singular"
70
+
71
+ // Example of new irregular rule, e.g. "I" -> "we":
72
+ pluralize.plural('irregular') //=> "irregulars"
73
+ pluralize.addIrregularRule('irregular', 'regular')
74
+ pluralize.plural('irregular') //=> "regular"
75
+
76
+ // Example of uncountable rule (rules without singular/plural in context):
77
+ pluralize.plural('paper') //=> "papers"
78
+ pluralize.addUncountableRule('paper')
79
+ pluralize.plural('paper') //=> "paper"
80
+
81
+ // Example of asking whether a word looks singular or plural:
82
+ pluralize.isPlural('test') //=> false
83
+ pluralize.isSingular('test') //=> true
84
+ ```
85
+
86
+ ## License
87
+
88
+ MIT
89
+
90
+ [npm-image]: https://img.shields.io/npm/v/pluralize.svg?style=flat
91
+ [npm-url]: https://npmjs.org/package/pluralize
92
+ [downloads-image]: https://img.shields.io/npm/dm/pluralize.svg?style=flat
93
+ [downloads-url]: https://npmjs.org/package/pluralize
94
+ [travis-image]: https://img.shields.io/travis/blakeembrey/pluralize.svg?style=flat
95
+ [travis-url]: https://travis-ci.org/blakeembrey/pluralize
96
+ [coveralls-image]: https://img.shields.io/coveralls/blakeembrey/pluralize.svg?style=flat
97
+ [coveralls-url]: https://coveralls.io/r/blakeembrey/pluralize?branch=master
98
+ [filesize-url]: https://img.shields.io/github/size/blakeembrey/pluralize/pluralize.js.svg?style=flat
99
+ [cdnjs-image]: https://img.shields.io/cdnjs/v/pluralize.svg
100
+ [cdnjs-url]: https://cdnjs.com/libraries/pluralize
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "pluralize",
3
+ "version": "8.0.0",
4
+ "description": "Pluralize and singularize any word",
5
+ "main": "pluralize.js",
6
+ "files": [
7
+ "pluralize.js"
8
+ ],
9
+ "scripts": {
10
+ "lint": "semistandard",
11
+ "test-spec": "mocha -R spec --bail",
12
+ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec --bail",
13
+ "test": "npm run lint && npm run test-cov"
14
+ },
15
+ "repository": "https://github.com/blakeembrey/pluralize.git",
16
+ "keywords": [
17
+ "plural",
18
+ "plurals",
19
+ "pluralize",
20
+ "singular",
21
+ "singularize",
22
+ "inflection"
23
+ ],
24
+ "author": {
25
+ "name": "Blake Embrey",
26
+ "email": "hello@blakeembrey.com",
27
+ "url": "http://blakeembrey.me"
28
+ },
29
+ "license": "MIT",
30
+ "readmeFilename": "Readme.md",
31
+ "engines": {
32
+ "node": ">=4"
33
+ },
34
+ "devDependencies": {
35
+ "chai": "^4.0.0",
36
+ "istanbul": "^0.4.5",
37
+ "mocha": "^5.0.0",
38
+ "semistandard": "^12.0.0"
39
+ }
40
+ }
@@ -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,33 @@
1
+ {
2
+ "name": "@bookshop/cloudcannon-structures",
3
+ "version": "2.0.0-alpha.51",
4
+ "description": "Convert a Bookshop object into a CloudCannon structure",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "files": [
10
+ "main.js"
11
+ ],
12
+ "author": "@bglw",
13
+ "license": "MIT",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "devDependencies": {
18
+ "@bookshop/toml-narrator": "file:../toml-narrator",
19
+ "@ltd/j-toml": "^1.12.2",
20
+ "jest": "^27.0.6"
21
+ },
22
+ "jest": {
23
+ "setupFiles": [
24
+ "./util/test-helpers.js"
25
+ ]
26
+ },
27
+ "dependencies": {
28
+ "pluralize": "^8.0.0"
29
+ },
30
+ "bundledDependencies": [
31
+ "pluralize"
32
+ ]
33
+ }
@@ -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,25 @@
1
+ {
2
+ "name": "@bookshop/toml-narrator",
3
+ "version": "2.0.0-alpha.51",
4
+ "description": "Rewrite Bookshop TOML files to preserve comments",
5
+ "main": "main.js",
6
+ "scripts": {
7
+ "test": "jest"
8
+ },
9
+ "files": [
10
+ "main.js"
11
+ ],
12
+ "author": "@bglw",
13
+ "license": "MIT",
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "devDependencies": {
18
+ "jest": "^27.0.6"
19
+ },
20
+ "jest": {
21
+ "setupFiles": [
22
+ "./util/test-helpers.js"
23
+ ]
24
+ }
25
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
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.alpha.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Bigelow
@@ -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,14 @@ 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/node_modules/pluralize/LICENSE
159
+ - node_modules/@bookshop/cloudcannon-structures/node_modules/pluralize/Readme.md
160
+ - node_modules/@bookshop/cloudcannon-structures/node_modules/pluralize/package.json
161
+ - node_modules/@bookshop/cloudcannon-structures/node_modules/pluralize/pluralize.js
162
+ - node_modules/@bookshop/cloudcannon-structures/package.json
163
+ - node_modules/@bookshop/toml-narrator/main.js
164
+ - node_modules/@bookshop/toml-narrator/package.json
158
165
  homepage: https://github.com/cloudcannon/bookshop
159
166
  licenses:
160
167
  - 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