initial
This commit is contained in:
19
node_modules/pug-attrs/LICENSE
generated
vendored
Normal file
19
node_modules/pug-attrs/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2015 Forbes Lindesay
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
75
node_modules/pug-attrs/README.md
generated
vendored
Normal file
75
node_modules/pug-attrs/README.md
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
# pug-attrs
|
||||
|
||||
Generate code for Pug attributes
|
||||
|
||||
[](https://travis-ci.org/pugjs/pug-attrs)
|
||||
[](https://david-dm.org/pugjs/pug-attrs)
|
||||
[](https://www.npmjs.org/package/pug-attrs)
|
||||
|
||||
## Installation
|
||||
|
||||
npm install pug-attrs
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var compileAttrs = require('pug-attrs');
|
||||
```
|
||||
|
||||
### `compileAttrs(attrs, options)`
|
||||
|
||||
Compile `attrs` to a JavaScript string that evaluates to the attributes in the desired format.
|
||||
|
||||
`options` MUST include the following properties:
|
||||
|
||||
- `terse`: whether or not to use HTML5-style terse boolean attributes
|
||||
- `runtime`: callback that takes a runtime function name and returns the source code that will evaluate to that function at runtime
|
||||
- `format`: output format; must be `html` or `object`
|
||||
|
||||
`attrs` is an array of attributes, with each attribute having the form of `{ name, val, mustEscape }`. `val` represents a JavaScript string that evaluates to the value of the attribute, either statically or dynamically.
|
||||
|
||||
```js
|
||||
var compileAttrs = require('pug-attrs');
|
||||
var pugRuntime = require('pug-runtime');
|
||||
|
||||
function getBaz () { return 'baz<>'; }
|
||||
|
||||
var attrs = [
|
||||
{name: 'foo', val: '"bar"', mustEscape: true },
|
||||
{name: 'baz', val: 'getBaz()', mustEscape: true },
|
||||
{name: 'quux', val: true, mustEscape: false}
|
||||
];
|
||||
var result, finalResult;
|
||||
|
||||
// HTML MODE
|
||||
result = compileAttrs(attrs, {
|
||||
terse: true,
|
||||
format: 'html',
|
||||
runtime: function (name) { return 'pugRuntime.' + name; }
|
||||
});
|
||||
//=> '" foo=\\"bar\\"" + pugRuntime.attr("baz", getBaz(), true, true) + " quux"'
|
||||
|
||||
finalResult = Function('pugRuntime, getBaz',
|
||||
'return (' + result + ');'
|
||||
);
|
||||
finalResult(pugRuntime, getBaz);
|
||||
// => ' foo="bar" baz="baz<>" quux'
|
||||
|
||||
// OBJECT MODE
|
||||
result = compileAttrs(attrs, {
|
||||
terse: true,
|
||||
format: 'object',
|
||||
runtime: function (name) { return 'pugRuntime.' + name; }
|
||||
});
|
||||
//=> '{"foo": "bar","baz": pugRuntime.escape(getBaz()),"quux": true}'
|
||||
|
||||
finalResult = Function('pugRuntime, getBaz',
|
||||
'return (' + result + ');'
|
||||
);
|
||||
finalResult(pugRuntime, getBaz);
|
||||
//=> { foo: 'bar', baz: 'baz<>', quux: true }
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
122
node_modules/pug-attrs/index.js
generated
vendored
Normal file
122
node_modules/pug-attrs/index.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var constantinople = require('constantinople');
|
||||
var runtime = require('pug-runtime');
|
||||
var stringify = require('js-stringify');
|
||||
|
||||
function isConstant(src) {
|
||||
return constantinople(src, {pug: runtime, 'pug_interp': undefined});
|
||||
}
|
||||
function toConstant(src) {
|
||||
return constantinople.toConstant(src, {pug: runtime, 'pug_interp': undefined});
|
||||
}
|
||||
|
||||
module.exports = compileAttrs;
|
||||
/**
|
||||
* options:
|
||||
* - terse
|
||||
* - runtime
|
||||
* - format ('html' || 'object')
|
||||
*/
|
||||
function compileAttrs(attrs, options) {
|
||||
assert(Array.isArray(attrs), 'Attrs should be an array');
|
||||
assert(attrs.every(function (attr) {
|
||||
return attr &&
|
||||
typeof attr === 'object' &&
|
||||
typeof attr.name === 'string' &&
|
||||
(typeof attr.val === 'string' || typeof attr.val === 'boolean') &&
|
||||
typeof attr.mustEscape === 'boolean';
|
||||
}), 'All attributes should be supplied as an object of the form {name, val, mustEscape}');
|
||||
assert(options && typeof options === 'object', 'Options should be an object');
|
||||
assert(typeof options.terse === 'boolean', 'Options.terse should be a boolean');
|
||||
assert(
|
||||
typeof options.runtime === 'function',
|
||||
'Options.runtime should be a function that takes a runtime function name and returns the source code that will evaluate to that function at runtime'
|
||||
);
|
||||
assert(
|
||||
options.format === 'html' || options.format === 'object',
|
||||
'Options.format should be "html" or "object"'
|
||||
);
|
||||
|
||||
var buf = [];
|
||||
var classes = [];
|
||||
var classEscaping = [];
|
||||
|
||||
function addAttribute(key, val, mustEscape, buf) {
|
||||
if (isConstant(val)) {
|
||||
if (options.format === 'html') {
|
||||
var str = stringify(runtime.attr(key, toConstant(val), mustEscape, options.terse));
|
||||
var last = buf[buf.length - 1];
|
||||
if (last && last[last.length - 1] === str[0]) {
|
||||
buf[buf.length - 1] = last.substr(0, last.length - 1) + str.substr(1);
|
||||
} else {
|
||||
buf.push(str);
|
||||
}
|
||||
} else {
|
||||
val = toConstant(val);
|
||||
if (mustEscape) {
|
||||
val = runtime.escape(val);
|
||||
}
|
||||
buf.push(stringify(key) + ': ' + stringify(val));
|
||||
}
|
||||
} else {
|
||||
if (options.format === 'html') {
|
||||
buf.push(options.runtime('attr') + '("' + key + '", ' + val + ', ' + stringify(mustEscape) + ', ' + stringify(options.terse) + ')');
|
||||
} else {
|
||||
if (mustEscape) {
|
||||
val = options.runtime('escape') + '(' + val + ')';
|
||||
}
|
||||
buf.push(stringify(key) + ': ' + val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attrs.forEach(function(attr){
|
||||
var key = attr.name;
|
||||
var val = attr.val;
|
||||
var mustEscape = attr.mustEscape;
|
||||
|
||||
if (key === 'class') {
|
||||
classes.push(val);
|
||||
classEscaping.push(mustEscape);
|
||||
} else {
|
||||
if (key === 'style') {
|
||||
if (isConstant(val)) {
|
||||
val = stringify(runtime.style(toConstant(val)));
|
||||
} else {
|
||||
val = options.runtime('style') + '(' + val + ')';
|
||||
}
|
||||
}
|
||||
addAttribute(key, val, mustEscape, buf);
|
||||
}
|
||||
});
|
||||
var classesBuf = [];
|
||||
if (classes.length) {
|
||||
if (classes.every(isConstant)) {
|
||||
addAttribute(
|
||||
'class',
|
||||
stringify(runtime.classes(classes.map(toConstant), classEscaping)),
|
||||
false,
|
||||
classesBuf
|
||||
);
|
||||
} else {
|
||||
classes = classes.map(function (cls, i) {
|
||||
if (isConstant(cls)) {
|
||||
cls = stringify(classEscaping[i] ? runtime.escape(toConstant(cls)) : toConstant(cls));
|
||||
classEscaping[i] = false;
|
||||
}
|
||||
return cls;
|
||||
});
|
||||
addAttribute(
|
||||
'class',
|
||||
options.runtime('classes') + '([' + classes.join(',') + '], ' + stringify(classEscaping) + ')',
|
||||
false,
|
||||
classesBuf
|
||||
);
|
||||
}
|
||||
}
|
||||
buf = classesBuf.concat(buf);
|
||||
if (options.format === 'html') return buf.length ? buf.join('+') : '""';
|
||||
else return '{' + buf.join(',') + '}';
|
||||
}
|
||||
82
node_modules/pug-attrs/package.json
generated
vendored
Normal file
82
node_modules/pug-attrs/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"pug-attrs@^2.0.2",
|
||||
"C:\\Users\\Tom\\Documents\\Development\\bitsy-image-to-room\\node_modules\\pug-code-gen"
|
||||
]
|
||||
],
|
||||
"_from": "pug-attrs@>=2.0.2 <3.0.0",
|
||||
"_id": "pug-attrs@2.0.2",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/pug-attrs",
|
||||
"_nodeVersion": "6.4.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "packages-12-west.internal.npmjs.com",
|
||||
"tmp": "tmp/pug-attrs-2.0.2.tgz_1485220030858_0.5362752785440534"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "forbes@lindesay.co.uk",
|
||||
"name": "forbeslindesay"
|
||||
},
|
||||
"_npmVersion": "3.10.3",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "pug-attrs",
|
||||
"raw": "pug-attrs@^2.0.2",
|
||||
"rawSpec": "^2.0.2",
|
||||
"scope": null,
|
||||
"spec": ">=2.0.2 <3.0.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pug-code-gen"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pug-attrs/-/pug-attrs-2.0.2.tgz",
|
||||
"_shasum": "8be2b2225568ffa75d1b866982bff9f4111affcb",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "pug-attrs@^2.0.2",
|
||||
"_where": "C:\\Users\\Tom\\Documents\\Development\\bitsy-image-to-room\\node_modules\\pug-code-gen",
|
||||
"author": {
|
||||
"name": "Forbes Lindesay"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/pugjs/pug-attrs/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"constantinople": "^3.0.1",
|
||||
"js-stringify": "^1.0.1",
|
||||
"pug-runtime": "^2.0.3"
|
||||
},
|
||||
"description": "Generate code for Pug attributes",
|
||||
"devDependencies": {},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "8be2b2225568ffa75d1b866982bff9f4111affcb",
|
||||
"tarball": "https://registry.npmjs.org/pug-attrs/-/pug-attrs-2.0.2.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/pugjs/pug-attrs#readme",
|
||||
"keywords": [
|
||||
"pug"
|
||||
],
|
||||
"license": "MIT",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "forbeslindesay",
|
||||
"email": "forbes@lindesay.co.uk"
|
||||
},
|
||||
{
|
||||
"name": "timothygu",
|
||||
"email": "timothygu99@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "pug-attrs",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pugjs/pug-attrs.git"
|
||||
},
|
||||
"scripts": {},
|
||||
"version": "2.0.2"
|
||||
}
|
||||
96
node_modules/pug-attrs/test/index.test.js
generated
vendored
Normal file
96
node_modules/pug-attrs/test/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
'use strict';
|
||||
|
||||
var assert = require('assert');
|
||||
var utils = require('util');
|
||||
var attrs = require('../');
|
||||
|
||||
var options;
|
||||
function test(input, expected, locals) {
|
||||
var opts = options;
|
||||
locals = locals || {};
|
||||
locals.pug = locals.pug || require('pug-runtime');
|
||||
it(utils.inspect(input).replace(/\n/g, '') + ' => ' + utils.inspect(expected), function () {
|
||||
var src = attrs(input, opts);
|
||||
var localKeys = Object.keys(locals).sort();
|
||||
var output = Function(localKeys.join(', '), 'return (' + src + ');').apply(null, localKeys.map(function (key) { return locals[key]; }));
|
||||
if (opts.format === 'html') {
|
||||
expect(output).toBe(expected);
|
||||
} else {
|
||||
expect(output).toEqual(expected);
|
||||
}
|
||||
});
|
||||
}
|
||||
function withOptions(opts, fn) {
|
||||
describe('options: ' + utils.inspect(opts), function () {
|
||||
options = opts;
|
||||
fn();
|
||||
});
|
||||
}
|
||||
|
||||
withOptions({terse: true, format: 'html', runtime: function (name) { return 'pug.' + name; }}, function () {
|
||||
test([], '');
|
||||
test([{name: 'foo', val: 'false', mustEscape: true}], '');
|
||||
test([{name: 'foo', val: 'true', mustEscape: true}], ' foo');
|
||||
test([{name: 'foo', val: false, mustEscape: true}], '');
|
||||
test([{name: 'foo', val: true, mustEscape: true}], ' foo');
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], '', {foo: false});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], ' foo', {foo: true});
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}], ' foo="foo"');
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}, {name: 'bar', val: '"bar"', mustEscape: true}], ' foo="foo" bar="bar"');
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], ' foo="fooo"', {foo: 'fooo'});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}, {name: 'bar', val: 'bar', mustEscape: true}], ' foo="fooo" bar="baro"', {foo: 'fooo', bar: 'baro'});
|
||||
test([{name: 'style', val: '{color: "red"}', mustEscape: true}], ' style="color:red;"');
|
||||
test([{name: 'style', val: '{color: color}', mustEscape: true}], ' style="color:red;"', {color: 'red'});
|
||||
test([{name: 'class', val: '"foo"', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], ' class="foo bar baz"');
|
||||
test([{name: 'class', val: '{foo: foo}', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], ' class="foo bar baz"', {foo: true});
|
||||
test([{name: 'class', val: '{foo: foo}', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], ' class="bar baz"', {foo: false});
|
||||
test([{name: 'class', val: 'foo', mustEscape: true}, {name: 'class', val: '"<str>"', mustEscape: true}], ' class="<foo> <str>"', {foo: '<foo>'});
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], ' class="bar baz" foo="foo"');
|
||||
test([{name: 'class', val: '["bar", "baz"]', mustEscape: true}, {name: 'foo', val: '"foo"', mustEscape: true}], ' class="bar baz" foo="foo"');
|
||||
test([{name: 'foo', val: '"<foo>"', mustEscape: false}], ' foo="<foo>"');
|
||||
test([{name: 'foo', val: '"<foo>"', mustEscape: true}], ' foo="<foo>"');
|
||||
test([{name: 'foo', val: 'foo', mustEscape: false}], ' foo="<foo>"', {foo: '<foo>'});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], ' foo="<foo>"', {foo: '<foo>'});
|
||||
});
|
||||
withOptions({terse: false, format: 'html', runtime: function (name) { return 'pug.' + name; }}, function () {
|
||||
test([{name: 'foo', val: 'false', mustEscape: true}], '');
|
||||
test([{name: 'foo', val: 'true', mustEscape: true}], ' foo="foo"');
|
||||
test([{name: 'foo', val: false, mustEscape: true}], '');
|
||||
test([{name: 'foo', val: true, mustEscape: true}], ' foo="foo"');
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], '', {foo: false});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], ' foo="foo"', {foo: true});
|
||||
});
|
||||
|
||||
withOptions({terse: true, format: 'object', runtime: function (name) { return 'pug.' + name; }}, function () {
|
||||
test([], {});
|
||||
test([{name: 'foo', val: 'false', mustEscape: true}], {foo: false});
|
||||
test([{name: 'foo', val: 'true', mustEscape: true}], {foo: true});
|
||||
test([{name: 'foo', val: false, mustEscape: true}], {foo: false});
|
||||
test([{name: 'foo', val: true, mustEscape: true}], {foo: true});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: false}, {foo: false});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: true}, {foo: true});
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}], {foo: 'foo'});
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}, {name: 'bar', val: '"bar"', mustEscape: true}], {foo: 'foo', bar: 'bar'});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: 'fooo'}, {foo: 'fooo'});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}, {name: 'bar', val: 'bar', mustEscape: true}], {foo: 'fooo', bar: 'baro'}, {foo: 'fooo', bar: 'baro'});
|
||||
test([{name: 'style', val: '{color: "red"}', mustEscape: true}], {style: 'color:red;'});
|
||||
test([{name: 'style', val: '{color: color}', mustEscape: true}], {style: 'color:red;'}, {color: 'red'});
|
||||
test([{name: 'class', val: '"foo"', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], {'class': 'foo bar baz'});
|
||||
test([{name: 'class', val: '{foo: foo}', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], {'class': 'foo bar baz'}, {foo: true});
|
||||
test([{name: 'class', val: '{foo: foo}', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], {'class': 'bar baz'}, {foo: false});
|
||||
test([{name: 'class', val: 'foo', mustEscape: true}, {name: 'class', val: '"<str>"', mustEscape: true}], {'class': '<foo> <str>'}, {foo: '<foo>'});
|
||||
test([{name: 'foo', val: '"foo"', mustEscape: true}, {name: 'class', val: '["bar", "baz"]', mustEscape: true}], {'class': 'bar baz', foo: 'foo'});
|
||||
test([{name: 'class', val: '["bar", "baz"]', mustEscape: true}, {name: 'foo', val: '"foo"', mustEscape: true}], {'class': 'bar baz', foo: 'foo'});
|
||||
test([{name: 'foo', val: '"<foo>"', mustEscape: false}], {foo: "<foo>"});
|
||||
test([{name: 'foo', val: '"<foo>"', mustEscape: true}], {foo: "<foo>"});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: false}], {foo: "<foo>"}, {foo: '<foo>'});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: "<foo>"}, {foo: '<foo>'});
|
||||
});
|
||||
withOptions({terse: false, format: 'object', runtime: function (name) { return 'pug.' + name; }}, function () {
|
||||
test([{name: 'foo', val: 'false', mustEscape: true}], {foo: false});
|
||||
test([{name: 'foo', val: 'true', mustEscape: true}], {foo: true});
|
||||
test([{name: 'foo', val: false, mustEscape: true}], {foo: false});
|
||||
test([{name: 'foo', val: true, mustEscape: true}], {foo: true});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: false}, {foo: false});
|
||||
test([{name: 'foo', val: 'foo', mustEscape: true}], {foo: true}, {foo: true});
|
||||
});
|
||||
Reference in New Issue
Block a user