@jaredwray/fumanchu 2.0.0 → 3.0.0

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.
package/lib/html.js DELETED
@@ -1,218 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var util = require('handlebars-utils');
5
- var html = require('./utils/html');
6
- var utils = require('./utils');
7
- var parseAttr = html.parseAttributes;
8
- var helpers = module.exports;
9
-
10
- /**
11
- * Stringify attributes on the options `hash`.
12
- *
13
- * ```handlebars
14
- * <!-- value = 'bar' -->
15
- * <div{{attr foo=value}}></div>
16
- * <!-- results in: <div foo="bar"></div>
17
- * ```
18
- * @param {Object} `options`
19
- * @return {String}
20
- * @api public
21
- */
22
-
23
- helpers.attr = function(options) {
24
- var val = parseAttr((options && options.hash) || {});
25
- return val.trim() ? ' ' + val : '';
26
- };
27
-
28
- /**
29
- * Add an array of `<link>` tags. Automatically resolves
30
- * relative paths to `options.assets` if passed on the context.
31
- *
32
- * ```handlebars
33
- * <!-- {stylesheets: ['foo.css', 'bar.css']} -->
34
- * {{css stylesheets}}
35
- *
36
- * <!-- results in: -->
37
- * <!-- <link type="text/css" rel="stylesheet" href="foo.css"> -->
38
- * <!-- <link type="text/css" rel="stylesheet" href="bar.css"> -->
39
- * ```
40
- * @param {String|Array} `list` One or more stylesheet urls.
41
- * @return {String}
42
- * @api public
43
- */
44
-
45
- helpers.css = function(list, options) {
46
- if (arguments.length < 2) {
47
- options = list;
48
- list = [];
49
- }
50
-
51
- var styles = util.arrayify(list);
52
- var assets = '';
53
-
54
- if (this && this.options) {
55
- assets = this.options.assets || '';
56
- }
57
-
58
- if (options.hash.href) {
59
- styles = util.arrayify(options.hash.href);
60
- }
61
-
62
- return styles.map(function(item) {
63
- var ext = path.extname(item);
64
- var fp = item;
65
-
66
- if (!/(^\/\/)|(:\/\/)/.test(item)) {
67
- fp = path.posix.join(assets, item);
68
- }
69
-
70
- if (ext === '.less') {
71
- return '<link type="text/css" rel="stylesheet/less" href="' + fp + '">';
72
- }
73
- return '<link type="text/css" rel="stylesheet" href="' + fp + '">';
74
- }).join('\n');
75
- };
76
-
77
- /**
78
- * Generate one or more `<script></script>` tags with paths/urls to
79
- * javascript or coffeescript files.
80
- *
81
- * ```handlebars
82
- * {{js scripts}}
83
- * ```
84
- * @param {Object} `context`
85
- * @return {String}
86
- * @api public
87
- */
88
-
89
- helpers.js = function(context) {
90
- if (utils.typeOf(context) === 'object') {
91
- var attr = parseAttr(context.hash);
92
- return '<script' + (attr ? ' ' + attr : '') + '></script>';
93
- }
94
-
95
- if (utils.typeOf(context) === 'string') {
96
- return '<script src="' + context + '"></script>';
97
- }
98
-
99
- context = util.arrayify(context);
100
- return context.map(function(fp) {
101
- return (path.extname(fp) === '.coffee')
102
- ? utils.tag('script', {type: 'text/coffeescript', src: fp})
103
- : utils.tag('script', {src: fp});
104
- }).join('\n');
105
- };
106
-
107
- /**
108
- * Strip HTML tags from a string, so that only the text nodes
109
- * are preserved.
110
- *
111
- * ```handlebars
112
- * {{sanitize "<span>foo</span>"}}
113
- * <!-- results in: 'foo' -->
114
- * ```
115
- *
116
- * @param {String} `str` The string of HTML to sanitize.
117
- * @return {String}
118
- * @api public
119
- */
120
-
121
- helpers.sanitize = function(str) {
122
- return html.sanitize(str);
123
- };
124
-
125
- /**
126
- * Block helper for creating unordered lists (`<ul></ul>`)
127
- *
128
- * @param {Object} `context`
129
- * @param {Object} `options`
130
- * @return {String}
131
- * @block
132
- * @api public
133
- */
134
-
135
- helpers.ul = function(context, options) {
136
- return ('<ul ' + (parseAttr(options.hash)) + '>') + context.map(function(item) {
137
- if (typeof item !== 'string') {
138
- item = options.fn(item);
139
- }
140
- return '<li>' + item + '</li>';
141
- }).join('\n') + '</ul>';
142
- };
143
-
144
- /**
145
- * Block helper for creating ordered lists (`<ol></ol>`)
146
- *
147
- * @param {Object} `context`
148
- * @param {Object} `options`
149
- * @return {String}
150
- * @block
151
- * @api public
152
- */
153
-
154
- helpers.ol = function(context, options) {
155
- return ('<ol ' + (parseAttr(options.hash)) + '>') + context.map(function(item) {
156
- if (typeof item !== 'string') {
157
- item = options.fn(item);
158
- }
159
- return '<li>' + item + '</li>';
160
- }).join('\n') + '</ol>';
161
- };
162
-
163
- /**
164
- * Returns a `<figure>` with a thumbnail linked to a full picture
165
- *
166
- * @param {Object} `context` Object with values/attributes to add to the generated elements:
167
- * @param {String} `context.alt`
168
- * @param {String} `context.src`
169
- * @param {Number} `context.width`
170
- * @param {Number} `context.height`
171
- * @return {String} HTML `<figure>` element with image and optional caption/link.
172
- * @contributor: Marie Hogebrandt <https://github.com/Melindrea>
173
- * @api public
174
- */
175
-
176
- helpers.thumbnailImage = function(context) {
177
- var figure = '';
178
- var image = '';
179
-
180
- var link = context.full || false;
181
- var imageAttributes = {
182
- alt: context.alt,
183
- src: context.thumbnail,
184
- width: context.size.width,
185
- height: context.size.height
186
- };
187
-
188
- var figureAttributes = { id: 'image-' + context.id };
189
- var linkAttributes = { href: link, rel: 'thumbnail' };
190
-
191
- if (context.classes) {
192
- if (context.classes.image) {
193
- imageAttributes.class = context.classes.image.join(' ');
194
- }
195
- if (context.classes.figure) {
196
- figureAttributes.class = context.classes.figure.join(' ');
197
- }
198
- if (context.classes.link) {
199
- linkAttributes.class = context.classes.link.join(' ');
200
- }
201
- }
202
-
203
- figure += '<figure ' + parseAttr(figureAttributes) + '>\n';
204
- image += '<img ' + parseAttr(imageAttributes) + '>\n';
205
-
206
- if (link) {
207
- figure += '<a ' + parseAttr(linkAttributes) + '>\n' + image + '</a>\n';
208
- } else {
209
- figure += image;
210
- }
211
-
212
- if (context.caption) {
213
- figure += '<figcaption>' + context.caption + '</figcaption>\n';
214
- }
215
-
216
- figure += '</figure>';
217
- return figure;
218
- };
package/lib/i18n.js DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('handlebars-utils');
4
- var utils = require('./utils');
5
- var helpers = module.exports;
6
-
7
- /**
8
- * i18n helper. See [button-i18n](https://github.com/assemble/buttons)
9
- * for a working example.
10
- *
11
- * @contributor Laurent Goderre <https://github.com/LaurentGoderrre>
12
- * @param {String} `key`
13
- * @param {Object} `options`
14
- * @return {String}
15
- * @api public
16
- */
17
-
18
- helpers.i18n = function(prop, locals, options) {
19
- if (util.isOptions(locals)) {
20
- options = locals;
21
- locals = {};
22
- }
23
-
24
- if (!util.isString(prop)) {
25
- throw new Error('{{i18n}} helper expected "key" to be a string');
26
- }
27
-
28
- var opts = util.options(this, locals, options);
29
- var context = Object.assign({}, this, opts);
30
-
31
- var lang = context.language || context.lang;
32
-
33
- if (!util.isString(lang)) {
34
- throw new TypeError('{{i18n}} helper expected "language" to be a string');
35
- }
36
-
37
- var cache = context[lang];
38
- if (typeof cache === 'undefined') {
39
- throw new Error('{{i18n}} helper cannot find language "' + lang + '"');
40
- }
41
-
42
- var result = utils.get(cache, prop);
43
- if (typeof result === 'undefined') {
44
- throw new Error('{{i18n}} helper cannot find property "' + prop + '" for language "' + lang + '"');
45
- }
46
-
47
- return result;
48
- };
package/lib/index.js DELETED
@@ -1,24 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- array: require('./array'),
5
- code: require('./code'),
6
- collection: require('./collection'),
7
- comparison: require('./comparison'),
8
- date: require('./date'),
9
- fs: require('./fs'),
10
- html: require('./html'),
11
- i18n: require('./i18n'),
12
- inflection: require('./inflection'),
13
- logging: require('./logging'),
14
- markdown: require('./markdown'),
15
- match: require('./match'),
16
- math: require('./math'),
17
- misc: require('./misc'),
18
- number: require('./number'),
19
- object: require('./object'),
20
- path: require('./path'),
21
- regex: require('./regex'),
22
- string: require('./string'),
23
- url: require('./url')
24
- };
package/lib/inflection.js DELETED
@@ -1,78 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('handlebars-utils');
4
- var helpers = module.exports;
5
-
6
- /**
7
- * Returns either the `singular` or `plural` inflection of a word based on
8
- * the given `count`.
9
- *
10
- * ```handlebars
11
- * {{inflect 0 "string" "strings"}}
12
- * <!-- "strings" -->
13
- * {{inflect 1 "string" "strings"}}
14
- * <!-- "string" -->
15
- * {{inflect 1 "string" "strings" true}}
16
- * <!-- "1 string" -->
17
- * {{inflect 2 "string" "strings"}}
18
- * <!-- "strings" -->
19
- * {{inflect 2 "string" "strings" true}}
20
- * <!-- "2 strings" -->
21
- * ```
22
- * @param {Number} `count`
23
- * @param {String} `singular` The singular form
24
- * @param {String} `plural` The plural form
25
- * @param {String} `includeCount`
26
- * @return {String}
27
- * @api public
28
- */
29
-
30
- helpers.inflect = function(count, singular, plural, includeCount) {
31
- var word = (count > 1 || count === 0) ? plural : singular;
32
- if (includeCount === true) {
33
- return String(count) + ' ' + word;
34
- } else {
35
- return word;
36
- }
37
- };
38
-
39
- /**
40
- * Returns an ordinalized number as a string.
41
- *
42
- * ```handlebars
43
- * {{ordinalize 1}}
44
- * <!-- '1st' -->
45
- * {{ordinalize 21}}
46
- * <!-- '21st' -->
47
- * {{ordinalize 29}}
48
- * <!-- '29th' -->
49
- * {{ordinalize 22}}
50
- * <!-- '22nd' -->
51
- * ```
52
- *
53
- * @param {String} `val` The value to ordinalize.
54
- * @return {String} The ordinalized number
55
- * @api public
56
- */
57
-
58
- helpers.ordinalize = function(val) {
59
- var num = Math.abs(Math.round(val));
60
- var str = String(val);
61
- var res = num % 100;
62
-
63
- if (util.indexOf([11, 12, 13], res) >= 0) {
64
- return str + 'th';
65
- }
66
-
67
- switch (num % 10) {
68
- case 1:
69
- return str + 'st';
70
- case 2:
71
- return str + 'nd';
72
- case 3:
73
- return str + 'rd';
74
- default: {
75
- return str + 'th';
76
- }
77
- }
78
- };
package/lib/logging.js DELETED
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * [logging-helpers](https://github.com/helpers/logging-helpers).
5
- * @api public
6
- */
7
-
8
- module.exports = require('logging-helpers');
package/lib/markdown.js DELETED
@@ -1,99 +0,0 @@
1
- 'use strict';
2
- const hljs = require('highlight.js');
3
- const utils = require('handlebars-utils');
4
- const {Remarkable} = require('remarkable');
5
-
6
- /**
7
- * Expose markdown `helpers` (for performance we're using getters so
8
- * that the helpers are only loaded if called)
9
- */
10
-
11
- var helpers = module.exports;
12
- var markdown;
13
-
14
- /**
15
- * Block helper that converts a string of inline markdown to HTML.
16
- *
17
- * ```handlebars
18
- * {{#markdown}}
19
- * # Foo
20
- * {{/markdown}}
21
- * <!-- results in: <h1>Foo</h1> -->
22
- * ```
23
- * @name .markdown
24
- * @param {Object} `context`
25
- * @param {Object} `options`
26
- * @return {String}
27
- * @block
28
- * @api public
29
- */
30
-
31
- Object.defineProperty(helpers, 'markdown', {
32
- configurable: true,
33
- enumerable: true,
34
- set: function(val) {
35
- markdown = val;
36
- },
37
- get: function() {
38
- // this is defined as a getter to avoid calling this function
39
- // unless the helper is actually used
40
- return markdown || (markdown = this.helpersForMarkdown());
41
- }
42
- });
43
-
44
- /**
45
- * Read a markdown file from the file system and inject its contents after
46
- * converting it to HTML.
47
- *
48
- * ```handlebars
49
- * {{md "foo/bar.md"}}
50
- * ```
51
- * @param {Object} `context`
52
- * @param {Object} `options`
53
- * @return {String}
54
- * @block
55
- * @api public
56
- */
57
-
58
- helpers.md = require('./md.js');
59
-
60
-
61
- helpers.helpersForMarkdown = function(config) {
62
- const defaults = { html: true, breaks: true, highlight: helpers.highlightFormMarkdown };
63
- if (typeof config === 'string' || utils.isOptions(config)) {
64
- return markdown.apply(defaults, arguments);
65
- }
66
-
67
- function markdown(str, locals, options) {
68
- if (typeof str !== 'string') {
69
- options = locals;
70
- locals = str;
71
- str = true;
72
- }
73
-
74
- if (utils.isOptions(locals)) {
75
- options = locals;
76
- locals = {};
77
- }
78
-
79
- const ctx = utils.context(this, locals, options);
80
- let opts = utils.options(this, locals, options);
81
- opts = Object.assign({}, defaults, config, opts);
82
-
83
- if (opts.hasOwnProperty('lang')) {
84
- opts.langPrefix = opts.lang;
85
- }
86
-
87
- const md = new Remarkable(opts);
88
- const val = utils.value(str, ctx, options);
89
- return md.render(val);
90
- }
91
- return markdown;
92
- };
93
-
94
- helpers.highlightFormMarkdown = function(code, lang) {
95
- if(lang) {
96
- return hljs.highlight(code, {language: lang}).value;
97
- }
98
- return hljs.highlightAuto(code).value;
99
- }
package/lib/match.js DELETED
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('handlebars-utils');
4
- var utils = require('./utils');
5
- var helpers = module.exports;
6
-
7
- /**
8
- * Returns an array of strings that match the given glob pattern(s).
9
- * Options may be passed on the options hash or locals.
10
- *
11
- * ```handlebars
12
- * {{match (readdir "foo") "*.js"}}
13
- * {{match (readdir "foo") (toRegex "\\.js$")}}
14
- * ```
15
- * @param {Array|String} `files`
16
- * @param {Array|String} `patterns` One or more glob patterns.
17
- * @param {Object} `locals`
18
- * @param {Object} `options`
19
- * @return {Array} Array of matches
20
- * @api public
21
- */
22
-
23
- helpers.match = function(files, patterns, locals, options) {
24
- var opts = util.options(this, locals, options);
25
- if (typeof patterns === 'string') {
26
- patterns = patterns.split(/, */);
27
- }
28
- return utils.mm(files, patterns, opts);
29
- };
30
-
31
- /**
32
- * Returns true if a filepath contains the given pattern.
33
- * Options may be passed on the options hash or locals.
34
- *
35
- * ```handlebars
36
- * {{isMatch "foo.md" "*.md"}}
37
- * <!-- results in: true -->
38
- * ```
39
- *
40
- * @param {String} `filepath`
41
- * @param {String} `pattern`
42
- * @param {Object} `options`
43
- * @return {Boolean}
44
- * @api public
45
- */
46
-
47
- helpers.isMatch = function(files, patterns, locals, options) {
48
- var opts = util.options(this, locals, options);
49
- return utils.mm.isMatch(files, patterns, opts);
50
- };
51
-
52
- /**
53
- * Alias for micromatch helper. Deprecated in v0.9.0.
54
- */
55
-
56
- helpers.mm = function() {
57
- console.log('the {{mm}} helper is depcrecated and will be removed');
58
- console.log('in handlebars-helpers v1.0.0, please use the {{match}}');
59
- console.log('helper instead.');
60
- return helpers.match.apply(this, arguments);
61
- };