настройка webpack
This commit is contained in:
125
node_modules/renderkid/lib/AnsiPainter.js
generated
vendored
Normal file
125
node_modules/renderkid/lib/AnsiPainter.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var AnsiPainter, object, styles, tags, tools,
|
||||
hasProp = {}.hasOwnProperty,
|
||||
slice = [].slice;
|
||||
|
||||
tools = require('./tools');
|
||||
|
||||
tags = require('./ansiPainter/tags');
|
||||
|
||||
styles = require('./ansiPainter/styles');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
module.exports = AnsiPainter = (function() {
|
||||
var self;
|
||||
|
||||
function AnsiPainter() {}
|
||||
|
||||
AnsiPainter.tags = tags;
|
||||
|
||||
AnsiPainter.prototype.paint = function(s) {
|
||||
return this._replaceSpecialStrings(this._renderDom(this._parse(s)));
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._replaceSpecialStrings = function(str) {
|
||||
return str.replace(/&sp;/g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/&/g, '&');
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._parse = function(string, injectFakeRoot) {
|
||||
if (injectFakeRoot == null) {
|
||||
injectFakeRoot = true;
|
||||
}
|
||||
if (injectFakeRoot) {
|
||||
string = '<none>' + string + '</none>';
|
||||
}
|
||||
return tools.toDom(string);
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._renderDom = function(dom) {
|
||||
var parentStyles;
|
||||
parentStyles = {
|
||||
bg: 'none',
|
||||
color: 'none'
|
||||
};
|
||||
return this._renderChildren(dom, parentStyles);
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._renderChildren = function(children, parentStyles) {
|
||||
var child, n, ret;
|
||||
ret = '';
|
||||
for (n in children) {
|
||||
if (!hasProp.call(children, n)) continue;
|
||||
child = children[n];
|
||||
ret += this._renderNode(child, parentStyles);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._renderNode = function(node, parentStyles) {
|
||||
if (node.type === 'text') {
|
||||
return this._renderTextNode(node, parentStyles);
|
||||
} else {
|
||||
return this._renderTag(node, parentStyles);
|
||||
}
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._renderTextNode = function(node, parentStyles) {
|
||||
return this._wrapInStyle(node.data, parentStyles);
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._wrapInStyle = function(str, style) {
|
||||
return styles.color(style.color) + styles.bg(style.bg) + str + styles.none();
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._renderTag = function(node, parentStyles) {
|
||||
var currentStyles, tagStyles;
|
||||
tagStyles = this._getStylesForTagName(node.name);
|
||||
currentStyles = this._mixStyles(parentStyles, tagStyles);
|
||||
return this._renderChildren(node.children, currentStyles);
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._mixStyles = function() {
|
||||
var final, i, key, len, style, styles, val;
|
||||
styles = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
final = {};
|
||||
for (i = 0, len = styles.length; i < len; i++) {
|
||||
style = styles[i];
|
||||
for (key in style) {
|
||||
if (!hasProp.call(style, key)) continue;
|
||||
val = style[key];
|
||||
if ((final[key] == null) || val !== 'inherit') {
|
||||
final[key] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return final;
|
||||
};
|
||||
|
||||
AnsiPainter.prototype._getStylesForTagName = function(name) {
|
||||
if (tags[name] == null) {
|
||||
throw Error("Unknown tag name `" + name + "`");
|
||||
}
|
||||
return tags[name];
|
||||
};
|
||||
|
||||
self = AnsiPainter;
|
||||
|
||||
AnsiPainter.getInstance = function() {
|
||||
if (self._instance == null) {
|
||||
self._instance = new self;
|
||||
}
|
||||
return self._instance;
|
||||
};
|
||||
|
||||
AnsiPainter.paint = function(str) {
|
||||
return self.getInstance().paint(str);
|
||||
};
|
||||
|
||||
AnsiPainter.strip = function(s) {
|
||||
return s.replace(/\x1b\[[0-9]+m/g, '');
|
||||
};
|
||||
|
||||
return AnsiPainter;
|
||||
|
||||
})();
|
||||
110
node_modules/renderkid/lib/Layout.js
generated
vendored
Normal file
110
node_modules/renderkid/lib/Layout.js
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Block, Layout, SpecialString, fn, i, len, object, prop, ref, terminalWidth;
|
||||
|
||||
Block = require('./layout/Block');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
SpecialString = require('./layout/SpecialString');
|
||||
|
||||
terminalWidth = require('./tools').getCols();
|
||||
|
||||
module.exports = Layout = (function() {
|
||||
var self;
|
||||
|
||||
self = Layout;
|
||||
|
||||
Layout._rootBlockDefaultConfig = {
|
||||
linePrependor: {
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
lineAppendor: {
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
blockPrependor: {
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
blockAppendor: {
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Layout._defaultConfig = {
|
||||
terminalWidth: terminalWidth
|
||||
};
|
||||
|
||||
function Layout(config, rootBlockConfig) {
|
||||
var rootConfig;
|
||||
if (config == null) {
|
||||
config = {};
|
||||
}
|
||||
if (rootBlockConfig == null) {
|
||||
rootBlockConfig = {};
|
||||
}
|
||||
this._written = [];
|
||||
this._activeBlock = null;
|
||||
this._config = object.append(self._defaultConfig, config);
|
||||
rootConfig = object.append(self._rootBlockDefaultConfig, rootBlockConfig);
|
||||
this._root = new Block(this, null, rootConfig, '__root');
|
||||
this._root._open();
|
||||
}
|
||||
|
||||
Layout.prototype.getRootBlock = function() {
|
||||
return this._root;
|
||||
};
|
||||
|
||||
Layout.prototype._append = function(text) {
|
||||
return this._written.push(text);
|
||||
};
|
||||
|
||||
Layout.prototype._appendLine = function(text) {
|
||||
var s;
|
||||
this._append(text);
|
||||
s = SpecialString(text);
|
||||
if (s.length < this._config.terminalWidth) {
|
||||
this._append('<none>\n</none>');
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Layout.prototype.get = function() {
|
||||
this._ensureClosed();
|
||||
if (this._written[this._written.length - 1] === '<none>\n</none>') {
|
||||
this._written.pop();
|
||||
}
|
||||
return this._written.join("");
|
||||
};
|
||||
|
||||
Layout.prototype._ensureClosed = function() {
|
||||
if (this._activeBlock !== this._root) {
|
||||
throw Error("Not all the blocks have been closed. Please call block.close() on all open blocks.");
|
||||
}
|
||||
if (this._root.isOpen()) {
|
||||
this._root.close();
|
||||
}
|
||||
};
|
||||
|
||||
return Layout;
|
||||
|
||||
})();
|
||||
|
||||
ref = ['openBlock', 'write'];
|
||||
fn = function() {
|
||||
var method;
|
||||
method = prop;
|
||||
return Layout.prototype[method] = function() {
|
||||
return this._root[method].apply(this._root, arguments);
|
||||
};
|
||||
};
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
prop = ref[i];
|
||||
fn();
|
||||
}
|
||||
197
node_modules/renderkid/lib/RenderKid.js
generated
vendored
Normal file
197
node_modules/renderkid/lib/RenderKid.js
generated
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var AnsiPainter, Layout, RenderKid, Styles, blockStyleApplier, inlineStyleApplier, object, stripAnsi, terminalWidth, tools;
|
||||
|
||||
inlineStyleApplier = require('./renderKid/styleApplier/inline');
|
||||
|
||||
blockStyleApplier = require('./renderKid/styleApplier/block');
|
||||
|
||||
AnsiPainter = require('./AnsiPainter');
|
||||
|
||||
Styles = require('./renderKid/Styles');
|
||||
|
||||
Layout = require('./Layout');
|
||||
|
||||
tools = require('./tools');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
stripAnsi = require('strip-ansi');
|
||||
|
||||
terminalWidth = require('./tools').getCols();
|
||||
|
||||
module.exports = RenderKid = (function() {
|
||||
var self;
|
||||
|
||||
self = RenderKid;
|
||||
|
||||
RenderKid.AnsiPainter = AnsiPainter;
|
||||
|
||||
RenderKid.Layout = Layout;
|
||||
|
||||
RenderKid.quote = tools.quote;
|
||||
|
||||
RenderKid.tools = tools;
|
||||
|
||||
RenderKid._defaultConfig = {
|
||||
layout: {
|
||||
terminalWidth: terminalWidth
|
||||
}
|
||||
};
|
||||
|
||||
function RenderKid(config) {
|
||||
if (config == null) {
|
||||
config = {};
|
||||
}
|
||||
this.tools = self.tools;
|
||||
this._config = object.append(self._defaultConfig, config);
|
||||
this._initStyles();
|
||||
}
|
||||
|
||||
RenderKid.prototype._initStyles = function() {
|
||||
return this._styles = new Styles;
|
||||
};
|
||||
|
||||
RenderKid.prototype.style = function() {
|
||||
return this._styles.setRule.apply(this._styles, arguments);
|
||||
};
|
||||
|
||||
RenderKid.prototype._getStyleFor = function(el) {
|
||||
return this._styles.getStyleFor(el);
|
||||
};
|
||||
|
||||
RenderKid.prototype.render = function(input, withColors) {
|
||||
if (withColors == null) {
|
||||
withColors = true;
|
||||
}
|
||||
return this._paint(this._renderDom(this._toDom(input)), withColors);
|
||||
};
|
||||
|
||||
RenderKid.prototype._toDom = function(input) {
|
||||
if (typeof input === 'string') {
|
||||
return this._parse(input);
|
||||
} else if (object.isBareObject(input) || Array.isArray(input)) {
|
||||
return this._objToDom(input);
|
||||
} else {
|
||||
throw Error("Invalid input type. Only strings, arrays and objects are accepted");
|
||||
}
|
||||
};
|
||||
|
||||
RenderKid.prototype._objToDom = function(o, injectFakeRoot) {
|
||||
if (injectFakeRoot == null) {
|
||||
injectFakeRoot = true;
|
||||
}
|
||||
if (injectFakeRoot) {
|
||||
o = {
|
||||
body: o
|
||||
};
|
||||
}
|
||||
return tools.objectToDom(o);
|
||||
};
|
||||
|
||||
RenderKid.prototype._paint = function(text, withColors) {
|
||||
var painted;
|
||||
painted = AnsiPainter.paint(text);
|
||||
if (withColors) {
|
||||
return painted;
|
||||
} else {
|
||||
return stripAnsi(painted);
|
||||
}
|
||||
};
|
||||
|
||||
RenderKid.prototype._parse = function(string, injectFakeRoot) {
|
||||
if (injectFakeRoot == null) {
|
||||
injectFakeRoot = true;
|
||||
}
|
||||
if (injectFakeRoot) {
|
||||
string = '<body>' + string + '</body>';
|
||||
}
|
||||
return tools.stringToDom(string);
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderDom = function(dom) {
|
||||
var bodyTag, layout, rootBlock;
|
||||
bodyTag = dom[0];
|
||||
layout = new Layout(this._config.layout);
|
||||
rootBlock = layout.getRootBlock();
|
||||
this._renderBlockNode(bodyTag, null, rootBlock);
|
||||
return layout.get();
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderChildrenOf = function(parentNode, parentBlock) {
|
||||
var i, len, node, nodes;
|
||||
nodes = parentNode.children;
|
||||
for (i = 0, len = nodes.length; i < len; i++) {
|
||||
node = nodes[i];
|
||||
this._renderNode(node, parentNode, parentBlock);
|
||||
}
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderNode = function(node, parentNode, parentBlock) {
|
||||
if (node.type === 'text') {
|
||||
this._renderText(node, parentNode, parentBlock);
|
||||
} else if (node.name === 'br') {
|
||||
this._renderBr(node, parentNode, parentBlock);
|
||||
} else if (this._isBlock(node)) {
|
||||
this._renderBlockNode(node, parentNode, parentBlock);
|
||||
} else if (this._isNone(node)) {
|
||||
return;
|
||||
} else {
|
||||
this._renderInlineNode(node, parentNode, parentBlock);
|
||||
}
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderText = function(node, parentNode, parentBlock) {
|
||||
var ref, text;
|
||||
text = node.data;
|
||||
text = text.replace(/\s+/g, ' ');
|
||||
if ((parentNode != null ? (ref = parentNode.styles) != null ? ref.display : void 0 : void 0) !== 'inline') {
|
||||
text = text.trim();
|
||||
}
|
||||
if (text.length === 0) {
|
||||
return;
|
||||
}
|
||||
text = text.replace(/&nl;/g, "\n");
|
||||
return parentBlock.write(text);
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderBlockNode = function(node, parentNode, parentBlock) {
|
||||
var after, before, block, blockConfig, ref;
|
||||
ref = blockStyleApplier.applyTo(node, this._getStyleFor(node)), before = ref.before, after = ref.after, blockConfig = ref.blockConfig;
|
||||
block = parentBlock.openBlock(blockConfig);
|
||||
if (before !== '') {
|
||||
block.write(before);
|
||||
}
|
||||
this._renderChildrenOf(node, block);
|
||||
if (after !== '') {
|
||||
block.write(after);
|
||||
}
|
||||
return block.close();
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderInlineNode = function(node, parentNode, parentBlock) {
|
||||
var after, before, ref;
|
||||
ref = inlineStyleApplier.applyTo(node, this._getStyleFor(node)), before = ref.before, after = ref.after;
|
||||
if (before !== '') {
|
||||
parentBlock.write(before);
|
||||
}
|
||||
this._renderChildrenOf(node, parentBlock);
|
||||
if (after !== '') {
|
||||
return parentBlock.write(after);
|
||||
}
|
||||
};
|
||||
|
||||
RenderKid.prototype._renderBr = function(node, parentNode, parentBlock) {
|
||||
return parentBlock.write("\n");
|
||||
};
|
||||
|
||||
RenderKid.prototype._isBlock = function(node) {
|
||||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'block');
|
||||
};
|
||||
|
||||
RenderKid.prototype._isNone = function(node) {
|
||||
return !(node.type === 'text' || node.name === 'br' || this._getStyleFor(node).display !== 'none');
|
||||
};
|
||||
|
||||
return RenderKid;
|
||||
|
||||
})();
|
||||
68
node_modules/renderkid/lib/ansiPainter/styles.js
generated
vendored
Normal file
68
node_modules/renderkid/lib/ansiPainter/styles.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var codes, styles;
|
||||
|
||||
module.exports = styles = {};
|
||||
|
||||
styles.codes = codes = {
|
||||
'none': 0,
|
||||
'black': 30,
|
||||
'red': 31,
|
||||
'green': 32,
|
||||
'yellow': 33,
|
||||
'blue': 34,
|
||||
'magenta': 35,
|
||||
'cyan': 36,
|
||||
'white': 37,
|
||||
'grey': 90,
|
||||
'bright-red': 91,
|
||||
'bright-green': 92,
|
||||
'bright-yellow': 93,
|
||||
'bright-blue': 94,
|
||||
'bright-magenta': 95,
|
||||
'bright-cyan': 96,
|
||||
'bright-white': 97,
|
||||
'bg-black': 40,
|
||||
'bg-red': 41,
|
||||
'bg-green': 42,
|
||||
'bg-yellow': 43,
|
||||
'bg-blue': 44,
|
||||
'bg-magenta': 45,
|
||||
'bg-cyan': 46,
|
||||
'bg-white': 47,
|
||||
'bg-grey': 100,
|
||||
'bg-bright-red': 101,
|
||||
'bg-bright-green': 102,
|
||||
'bg-bright-yellow': 103,
|
||||
'bg-bright-blue': 104,
|
||||
'bg-bright-magenta': 105,
|
||||
'bg-bright-cyan': 106,
|
||||
'bg-bright-white': 107
|
||||
};
|
||||
|
||||
styles.color = function(str) {
|
||||
var code;
|
||||
if (str === 'none') {
|
||||
return '';
|
||||
}
|
||||
code = codes[str];
|
||||
if (code == null) {
|
||||
throw Error("Unknown color `" + str + "`");
|
||||
}
|
||||
return "\x1b[" + code + "m";
|
||||
};
|
||||
|
||||
styles.bg = function(str) {
|
||||
var code;
|
||||
if (str === 'none') {
|
||||
return '';
|
||||
}
|
||||
code = codes['bg-' + str];
|
||||
if (code == null) {
|
||||
throw Error("Unknown bg color `" + str + "`");
|
||||
}
|
||||
return "\x1B[" + code + "m";
|
||||
};
|
||||
|
||||
styles.none = function(str) {
|
||||
return "\x1B[" + codes.none + "m";
|
||||
};
|
||||
35
node_modules/renderkid/lib/ansiPainter/tags.js
generated
vendored
Normal file
35
node_modules/renderkid/lib/ansiPainter/tags.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var color, colors, i, len, tags;
|
||||
|
||||
module.exports = tags = {
|
||||
'none': {
|
||||
color: 'none',
|
||||
bg: 'none'
|
||||
},
|
||||
'bg-none': {
|
||||
color: 'inherit',
|
||||
bg: 'none'
|
||||
},
|
||||
'color-none': {
|
||||
color: 'none',
|
||||
bg: 'inherit'
|
||||
}
|
||||
};
|
||||
|
||||
colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'grey', 'bright-red', 'bright-green', 'bright-yellow', 'bright-blue', 'bright-magenta', 'bright-cyan', 'bright-white'];
|
||||
|
||||
for (i = 0, len = colors.length; i < len; i++) {
|
||||
color = colors[i];
|
||||
tags[color] = {
|
||||
color: color,
|
||||
bg: 'inherit'
|
||||
};
|
||||
tags["color-" + color] = {
|
||||
color: color,
|
||||
bg: 'inherit'
|
||||
};
|
||||
tags["bg-" + color] = {
|
||||
color: 'inherit',
|
||||
bg: color
|
||||
};
|
||||
}
|
||||
253
node_modules/renderkid/lib/layout/Block.js
generated
vendored
Normal file
253
node_modules/renderkid/lib/layout/Block.js
generated
vendored
Normal file
@ -0,0 +1,253 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Block, SpecialString, object, terminalWidth;
|
||||
|
||||
SpecialString = require('./SpecialString');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
terminalWidth = require('../tools').getCols();
|
||||
|
||||
module.exports = Block = (function() {
|
||||
var self;
|
||||
|
||||
self = Block;
|
||||
|
||||
Block.defaultConfig = {
|
||||
blockPrependor: {
|
||||
fn: require('./block/blockPrependor/Default'),
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
blockAppendor: {
|
||||
fn: require('./block/blockAppendor/Default'),
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
linePrependor: {
|
||||
fn: require('./block/linePrependor/Default'),
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
lineAppendor: {
|
||||
fn: require('./block/lineAppendor/Default'),
|
||||
options: {
|
||||
amount: 0
|
||||
}
|
||||
},
|
||||
lineWrapper: {
|
||||
fn: require('./block/lineWrapper/Default'),
|
||||
options: {
|
||||
lineWidth: null
|
||||
}
|
||||
},
|
||||
width: terminalWidth,
|
||||
prefixRaw: '',
|
||||
suffixRaw: ''
|
||||
};
|
||||
|
||||
function Block(_layout, _parent, config, _name) {
|
||||
this._layout = _layout;
|
||||
this._parent = _parent;
|
||||
if (config == null) {
|
||||
config = {};
|
||||
}
|
||||
this._name = _name != null ? _name : '';
|
||||
this._config = object.append(self.defaultConfig, config);
|
||||
this._closed = false;
|
||||
this._wasOpenOnce = false;
|
||||
this._active = false;
|
||||
this._buffer = '';
|
||||
this._didSeparateBlock = false;
|
||||
this._linePrependor = new this._config.linePrependor.fn(this._config.linePrependor.options);
|
||||
this._lineAppendor = new this._config.lineAppendor.fn(this._config.lineAppendor.options);
|
||||
this._blockPrependor = new this._config.blockPrependor.fn(this._config.blockPrependor.options);
|
||||
this._blockAppendor = new this._config.blockAppendor.fn(this._config.blockAppendor.options);
|
||||
}
|
||||
|
||||
Block.prototype._activate = function(deactivateParent) {
|
||||
if (deactivateParent == null) {
|
||||
deactivateParent = true;
|
||||
}
|
||||
if (this._active) {
|
||||
throw Error("This block is already active. This is probably a bug in RenderKid itself");
|
||||
}
|
||||
if (this._closed) {
|
||||
throw Error("This block is closed and cannot be activated. This is probably a bug in RenderKid itself");
|
||||
}
|
||||
this._active = true;
|
||||
this._layout._activeBlock = this;
|
||||
if (deactivateParent) {
|
||||
if (this._parent != null) {
|
||||
this._parent._deactivate(false);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Block.prototype._deactivate = function(activateParent) {
|
||||
if (activateParent == null) {
|
||||
activateParent = true;
|
||||
}
|
||||
this._ensureActive();
|
||||
this._flushBuffer();
|
||||
if (activateParent) {
|
||||
if (this._parent != null) {
|
||||
this._parent._activate(false);
|
||||
}
|
||||
}
|
||||
this._active = false;
|
||||
return this;
|
||||
};
|
||||
|
||||
Block.prototype._ensureActive = function() {
|
||||
if (!this._wasOpenOnce) {
|
||||
throw Error("This block has never been open before. This is probably a bug in RenderKid itself.");
|
||||
}
|
||||
if (!this._active) {
|
||||
throw Error("This block is not active. This is probably a bug in RenderKid itself.");
|
||||
}
|
||||
if (this._closed) {
|
||||
throw Error("This block is already closed. This is probably a bug in RenderKid itself.");
|
||||
}
|
||||
};
|
||||
|
||||
Block.prototype._open = function() {
|
||||
if (this._wasOpenOnce) {
|
||||
throw Error("Block._open() has been called twice. This is probably a RenderKid bug.");
|
||||
}
|
||||
this._wasOpenOnce = true;
|
||||
if (this._parent != null) {
|
||||
this._parent.write(this._whatToPrependToBlock());
|
||||
}
|
||||
this._activate();
|
||||
return this;
|
||||
};
|
||||
|
||||
Block.prototype.close = function() {
|
||||
this._deactivate();
|
||||
this._closed = true;
|
||||
if (this._parent != null) {
|
||||
this._parent.write(this._whatToAppendToBlock());
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Block.prototype.isOpen = function() {
|
||||
return this._wasOpenOnce && !this._closed;
|
||||
};
|
||||
|
||||
Block.prototype.write = function(str) {
|
||||
this._ensureActive();
|
||||
if (str === '') {
|
||||
return;
|
||||
}
|
||||
str = String(str);
|
||||
this._buffer += str;
|
||||
return this;
|
||||
};
|
||||
|
||||
Block.prototype.openBlock = function(config, name) {
|
||||
var block;
|
||||
this._ensureActive();
|
||||
block = new Block(this._layout, this, config, name);
|
||||
block._open();
|
||||
return block;
|
||||
};
|
||||
|
||||
Block.prototype._flushBuffer = function() {
|
||||
var str;
|
||||
if (this._buffer === '') {
|
||||
return;
|
||||
}
|
||||
str = this._buffer;
|
||||
this._buffer = '';
|
||||
this._writeInline(str);
|
||||
};
|
||||
|
||||
Block.prototype._toPrependToLine = function() {
|
||||
var fromParent;
|
||||
fromParent = '';
|
||||
if (this._parent != null) {
|
||||
fromParent = this._parent._toPrependToLine();
|
||||
}
|
||||
return this._linePrependor.render(fromParent);
|
||||
};
|
||||
|
||||
Block.prototype._toAppendToLine = function() {
|
||||
var fromParent;
|
||||
fromParent = '';
|
||||
if (this._parent != null) {
|
||||
fromParent = this._parent._toAppendToLine();
|
||||
}
|
||||
return this._lineAppendor.render(fromParent);
|
||||
};
|
||||
|
||||
Block.prototype._whatToPrependToBlock = function() {
|
||||
return this._blockPrependor.render();
|
||||
};
|
||||
|
||||
Block.prototype._whatToAppendToBlock = function() {
|
||||
return this._blockAppendor.render();
|
||||
};
|
||||
|
||||
Block.prototype._writeInline = function(str) {
|
||||
var i, j, k, l, lineBreaksToAppend, m, ref, ref1, ref2, remaining;
|
||||
if (SpecialString(str).isOnlySpecialChars()) {
|
||||
this._layout._append(str);
|
||||
return;
|
||||
}
|
||||
remaining = str;
|
||||
lineBreaksToAppend = 0;
|
||||
if (m = remaining.match(/^\n+/)) {
|
||||
for (i = j = 1, ref = m[0].length; 1 <= ref ? j <= ref : j >= ref; i = 1 <= ref ? ++j : --j) {
|
||||
this._writeLine('');
|
||||
}
|
||||
remaining = remaining.substr(m[0].length, remaining.length);
|
||||
}
|
||||
if (m = remaining.match(/\n+$/)) {
|
||||
lineBreaksToAppend = m[0].length;
|
||||
remaining = remaining.substr(0, remaining.length - m[0].length);
|
||||
}
|
||||
while (remaining.length > 0) {
|
||||
if (m = remaining.match(/^[^\n]+/)) {
|
||||
this._writeLine(m[0]);
|
||||
remaining = remaining.substr(m[0].length, remaining.length);
|
||||
} else if (m = remaining.match(/^\n+/)) {
|
||||
for (i = k = 1, ref1 = m[0].length; 1 <= ref1 ? k < ref1 : k > ref1; i = 1 <= ref1 ? ++k : --k) {
|
||||
this._writeLine('');
|
||||
}
|
||||
remaining = remaining.substr(m[0].length, remaining.length);
|
||||
}
|
||||
}
|
||||
if (lineBreaksToAppend > 0) {
|
||||
for (i = l = 1, ref2 = lineBreaksToAppend; 1 <= ref2 ? l <= ref2 : l >= ref2; i = 1 <= ref2 ? ++l : --l) {
|
||||
this._writeLine('');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Block.prototype._writeLine = function(str) {
|
||||
var line, lineContent, lineContentLength, remaining, roomLeft, toAppend, toAppendLength, toPrepend, toPrependLength;
|
||||
remaining = SpecialString(str);
|
||||
while (true) {
|
||||
toPrepend = this._toPrependToLine();
|
||||
toPrependLength = SpecialString(toPrepend).length;
|
||||
toAppend = this._toAppendToLine();
|
||||
toAppendLength = SpecialString(toAppend).length;
|
||||
roomLeft = this._layout._config.terminalWidth - (toPrependLength + toAppendLength);
|
||||
lineContentLength = Math.min(this._config.width, roomLeft);
|
||||
lineContent = remaining.cut(0, lineContentLength, true);
|
||||
line = toPrepend + lineContent.str + toAppend;
|
||||
this._layout._appendLine(line);
|
||||
if (remaining.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return Block;
|
||||
|
||||
})();
|
||||
176
node_modules/renderkid/lib/layout/SpecialString.js
generated
vendored
Normal file
176
node_modules/renderkid/lib/layout/SpecialString.js
generated
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var SpecialString, fn, i, len, prop, ref;
|
||||
|
||||
module.exports = SpecialString = (function() {
|
||||
var self;
|
||||
|
||||
self = SpecialString;
|
||||
|
||||
SpecialString._tabRx = /^\t/;
|
||||
|
||||
SpecialString._tagRx = /^<[^>]+>/;
|
||||
|
||||
SpecialString._quotedHtmlRx = /^&(gt|lt|quot|amp|apos|sp);/;
|
||||
|
||||
function SpecialString(str) {
|
||||
if (!(this instanceof self)) {
|
||||
return new self(str);
|
||||
}
|
||||
this._str = String(str);
|
||||
this._len = 0;
|
||||
}
|
||||
|
||||
SpecialString.prototype._getStr = function() {
|
||||
return this._str;
|
||||
};
|
||||
|
||||
SpecialString.prototype.set = function(str) {
|
||||
this._str = String(str);
|
||||
return this;
|
||||
};
|
||||
|
||||
SpecialString.prototype.clone = function() {
|
||||
return new SpecialString(this._str);
|
||||
};
|
||||
|
||||
SpecialString.prototype.isEmpty = function() {
|
||||
return this._str === '';
|
||||
};
|
||||
|
||||
SpecialString.prototype.isOnlySpecialChars = function() {
|
||||
return !this.isEmpty() && this.length === 0;
|
||||
};
|
||||
|
||||
SpecialString.prototype._reset = function() {
|
||||
return this._len = 0;
|
||||
};
|
||||
|
||||
SpecialString.prototype.splitIn = function(limit, trimLeftEachLine) {
|
||||
var buffer, bufferLength, justSkippedSkipChar, lines;
|
||||
if (trimLeftEachLine == null) {
|
||||
trimLeftEachLine = false;
|
||||
}
|
||||
buffer = '';
|
||||
bufferLength = 0;
|
||||
lines = [];
|
||||
justSkippedSkipChar = false;
|
||||
self._countChars(this._str, function(char, charLength) {
|
||||
if (bufferLength > limit || bufferLength + charLength > limit) {
|
||||
lines.push(buffer);
|
||||
buffer = '';
|
||||
bufferLength = 0;
|
||||
}
|
||||
if (bufferLength === 0 && char === ' ' && !justSkippedSkipChar && trimLeftEachLine) {
|
||||
return justSkippedSkipChar = true;
|
||||
} else {
|
||||
buffer += char;
|
||||
bufferLength += charLength;
|
||||
return justSkippedSkipChar = false;
|
||||
}
|
||||
});
|
||||
if (buffer.length > 0) {
|
||||
lines.push(buffer);
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
|
||||
SpecialString.prototype.trim = function() {
|
||||
return new SpecialString(this.str.trim());
|
||||
};
|
||||
|
||||
SpecialString.prototype.trimLeft = function() {
|
||||
return new SpecialString(this.str.replace(/^\s+/, ''));
|
||||
};
|
||||
|
||||
SpecialString.prototype.trimRight = function() {
|
||||
return new SpecialString(this.str.replace(/\s+$/, ''));
|
||||
};
|
||||
|
||||
SpecialString.prototype._getLength = function() {
|
||||
var sum;
|
||||
sum = 0;
|
||||
self._countChars(this._str, function(char, charLength) {
|
||||
sum += charLength;
|
||||
});
|
||||
return sum;
|
||||
};
|
||||
|
||||
SpecialString.prototype.cut = function(from, to, trimLeft) {
|
||||
var after, before, cur, cut;
|
||||
if (trimLeft == null) {
|
||||
trimLeft = false;
|
||||
}
|
||||
if (to == null) {
|
||||
to = this.length;
|
||||
}
|
||||
from = parseInt(from);
|
||||
if (from >= to) {
|
||||
throw Error("`from` shouldn't be larger than `to`");
|
||||
}
|
||||
before = '';
|
||||
after = '';
|
||||
cut = '';
|
||||
cur = 0;
|
||||
self._countChars(this._str, (function(_this) {
|
||||
return function(char, charLength) {
|
||||
if (_this.str === 'ab<tag>') {
|
||||
console.log(charLength, char);
|
||||
}
|
||||
if (cur === from && char.match(/^\s+$/) && trimLeft) {
|
||||
return;
|
||||
}
|
||||
if (cur < from) {
|
||||
before += char;
|
||||
} else if (cur < to || cur + charLength <= to) {
|
||||
cut += char;
|
||||
} else {
|
||||
after += char;
|
||||
}
|
||||
cur += charLength;
|
||||
};
|
||||
})(this));
|
||||
this._str = before + after;
|
||||
this._reset();
|
||||
return SpecialString(cut);
|
||||
};
|
||||
|
||||
SpecialString._countChars = function(text, cb) {
|
||||
var char, charLength, m;
|
||||
while (text.length !== 0) {
|
||||
if (m = text.match(self._tagRx)) {
|
||||
char = m[0];
|
||||
charLength = 0;
|
||||
text = text.substr(char.length, text.length);
|
||||
} else if (m = text.match(self._quotedHtmlRx)) {
|
||||
char = m[0];
|
||||
charLength = 1;
|
||||
text = text.substr(char.length, text.length);
|
||||
} else if (text.match(self._tabRx)) {
|
||||
char = "\t";
|
||||
charLength = 8;
|
||||
text = text.substr(1, text.length);
|
||||
} else {
|
||||
char = text[0];
|
||||
charLength = 1;
|
||||
text = text.substr(1, text.length);
|
||||
}
|
||||
cb.call(null, char, charLength);
|
||||
}
|
||||
};
|
||||
|
||||
return SpecialString;
|
||||
|
||||
})();
|
||||
|
||||
ref = ['str', 'length'];
|
||||
fn = function() {
|
||||
var methodName;
|
||||
methodName = '_get' + prop[0].toUpperCase() + prop.substr(1, prop.length);
|
||||
return SpecialString.prototype.__defineGetter__(prop, function() {
|
||||
return this[methodName]();
|
||||
});
|
||||
};
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
prop = ref[i];
|
||||
fn();
|
||||
}
|
||||
21
node_modules/renderkid/lib/layout/block/blockAppendor/Default.js
generated
vendored
Normal file
21
node_modules/renderkid/lib/layout/block/blockAppendor/Default.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DefaultBlockAppendor, tools,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
tools = require('../../../tools');
|
||||
|
||||
module.exports = DefaultBlockAppendor = (function(superClass) {
|
||||
extend(DefaultBlockAppendor, superClass);
|
||||
|
||||
function DefaultBlockAppendor() {
|
||||
return DefaultBlockAppendor.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
DefaultBlockAppendor.prototype._render = function(options) {
|
||||
return tools.repeatString("\n", this._config.amount);
|
||||
};
|
||||
|
||||
return DefaultBlockAppendor;
|
||||
|
||||
})(require('./_BlockAppendor'));
|
||||
15
node_modules/renderkid/lib/layout/block/blockAppendor/_BlockAppendor.js
generated
vendored
Normal file
15
node_modules/renderkid/lib/layout/block/blockAppendor/_BlockAppendor.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _BlockAppendor;
|
||||
|
||||
module.exports = _BlockAppendor = (function() {
|
||||
function _BlockAppendor(_config) {
|
||||
this._config = _config;
|
||||
}
|
||||
|
||||
_BlockAppendor.prototype.render = function(options) {
|
||||
return this._render(options);
|
||||
};
|
||||
|
||||
return _BlockAppendor;
|
||||
|
||||
})();
|
||||
21
node_modules/renderkid/lib/layout/block/blockPrependor/Default.js
generated
vendored
Normal file
21
node_modules/renderkid/lib/layout/block/blockPrependor/Default.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DefaultBlockPrependor, tools,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
tools = require('../../../tools');
|
||||
|
||||
module.exports = DefaultBlockPrependor = (function(superClass) {
|
||||
extend(DefaultBlockPrependor, superClass);
|
||||
|
||||
function DefaultBlockPrependor() {
|
||||
return DefaultBlockPrependor.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
DefaultBlockPrependor.prototype._render = function(options) {
|
||||
return tools.repeatString("\n", this._config.amount);
|
||||
};
|
||||
|
||||
return DefaultBlockPrependor;
|
||||
|
||||
})(require('./_BlockPrependor'));
|
||||
15
node_modules/renderkid/lib/layout/block/blockPrependor/_BlockPrependor.js
generated
vendored
Normal file
15
node_modules/renderkid/lib/layout/block/blockPrependor/_BlockPrependor.js
generated
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _BlockPrependor;
|
||||
|
||||
module.exports = _BlockPrependor = (function() {
|
||||
function _BlockPrependor(_config) {
|
||||
this._config = _config;
|
||||
}
|
||||
|
||||
_BlockPrependor.prototype.render = function(options) {
|
||||
return this._render(options);
|
||||
};
|
||||
|
||||
return _BlockPrependor;
|
||||
|
||||
})();
|
||||
21
node_modules/renderkid/lib/layout/block/lineAppendor/Default.js
generated
vendored
Normal file
21
node_modules/renderkid/lib/layout/block/lineAppendor/Default.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DefaultLineAppendor, tools,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
tools = require('../../../tools');
|
||||
|
||||
module.exports = DefaultLineAppendor = (function(superClass) {
|
||||
extend(DefaultLineAppendor, superClass);
|
||||
|
||||
function DefaultLineAppendor() {
|
||||
return DefaultLineAppendor.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
DefaultLineAppendor.prototype._render = function(inherited, options) {
|
||||
return inherited + tools.repeatString(" ", this._config.amount);
|
||||
};
|
||||
|
||||
return DefaultLineAppendor;
|
||||
|
||||
})(require('./_LineAppendor'));
|
||||
17
node_modules/renderkid/lib/layout/block/lineAppendor/_LineAppendor.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/layout/block/lineAppendor/_LineAppendor.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _LineAppendor;
|
||||
|
||||
module.exports = _LineAppendor = (function() {
|
||||
function _LineAppendor(_config) {
|
||||
this._config = _config;
|
||||
this._lineNo = 0;
|
||||
}
|
||||
|
||||
_LineAppendor.prototype.render = function(inherited, options) {
|
||||
this._lineNo++;
|
||||
return '<none>' + this._render(inherited, options) + '</none>';
|
||||
};
|
||||
|
||||
return _LineAppendor;
|
||||
|
||||
})();
|
||||
58
node_modules/renderkid/lib/layout/block/linePrependor/Default.js
generated
vendored
Normal file
58
node_modules/renderkid/lib/layout/block/linePrependor/Default.js
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DefaultLinePrependor, SpecialString, tools,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
tools = require('../../../tools');
|
||||
|
||||
SpecialString = require('../../SpecialString');
|
||||
|
||||
module.exports = DefaultLinePrependor = (function(superClass) {
|
||||
var self;
|
||||
|
||||
extend(DefaultLinePrependor, superClass);
|
||||
|
||||
function DefaultLinePrependor() {
|
||||
return DefaultLinePrependor.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
self = DefaultLinePrependor;
|
||||
|
||||
DefaultLinePrependor.pad = function(howMuch) {
|
||||
return tools.repeatString(" ", howMuch);
|
||||
};
|
||||
|
||||
DefaultLinePrependor.prototype._render = function(inherited, options) {
|
||||
var addToLeft, addToRight, alignment, bullet, char, charLen, diff, left, output, space, toWrite;
|
||||
if (this._lineNo === 0 && (bullet = this._config.bullet)) {
|
||||
char = bullet.char;
|
||||
charLen = SpecialString(char).length;
|
||||
alignment = bullet.alignment;
|
||||
space = this._config.amount;
|
||||
toWrite = char;
|
||||
addToLeft = '';
|
||||
addToRight = '';
|
||||
if (space > charLen) {
|
||||
diff = space - charLen;
|
||||
if (alignment === 'right') {
|
||||
addToLeft = self.pad(diff);
|
||||
} else if (alignment === 'left') {
|
||||
addToRight = self.pad(diff);
|
||||
} else if (alignment === 'center') {
|
||||
left = Math.round(diff / 2);
|
||||
addToLeft = self.pad(left);
|
||||
addToRight = self.pad(diff - left);
|
||||
} else {
|
||||
throw Error("Unknown alignment `" + alignment + "`");
|
||||
}
|
||||
}
|
||||
output = addToLeft + char + addToRight;
|
||||
} else {
|
||||
output = self.pad(this._config.amount);
|
||||
}
|
||||
return inherited + output;
|
||||
};
|
||||
|
||||
return DefaultLinePrependor;
|
||||
|
||||
})(require('./_LinePrependor'));
|
||||
17
node_modules/renderkid/lib/layout/block/linePrependor/_LinePrependor.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/layout/block/linePrependor/_LinePrependor.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _LinePrependor;
|
||||
|
||||
module.exports = _LinePrependor = (function() {
|
||||
function _LinePrependor(_config) {
|
||||
this._config = _config;
|
||||
this._lineNo = -1;
|
||||
}
|
||||
|
||||
_LinePrependor.prototype.render = function(inherited, options) {
|
||||
this._lineNo++;
|
||||
return '<none>' + this._render(inherited, options) + '</none>';
|
||||
};
|
||||
|
||||
return _LinePrependor;
|
||||
|
||||
})();
|
||||
17
node_modules/renderkid/lib/layout/block/lineWrapper/Default.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/layout/block/lineWrapper/Default.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DefaultLineWrapper,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
module.exports = DefaultLineWrapper = (function(superClass) {
|
||||
extend(DefaultLineWrapper, superClass);
|
||||
|
||||
function DefaultLineWrapper() {
|
||||
return DefaultLineWrapper.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
DefaultLineWrapper.prototype._render = function() {};
|
||||
|
||||
return DefaultLineWrapper;
|
||||
|
||||
})(require('./_LineWrapper'));
|
||||
13
node_modules/renderkid/lib/layout/block/lineWrapper/_LineWrapper.js
generated
vendored
Normal file
13
node_modules/renderkid/lib/layout/block/lineWrapper/_LineWrapper.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _LineWrapper;
|
||||
|
||||
module.exports = _LineWrapper = (function() {
|
||||
function _LineWrapper() {}
|
||||
|
||||
_LineWrapper.prototype.render = function(str, options) {
|
||||
return this._render(str, options);
|
||||
};
|
||||
|
||||
return _LineWrapper;
|
||||
|
||||
})();
|
||||
76
node_modules/renderkid/lib/renderKid/Styles.js
generated
vendored
Normal file
76
node_modules/renderkid/lib/renderKid/Styles.js
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MixedDeclarationSet, StyleSheet, Styles, terminalWidth;
|
||||
|
||||
StyleSheet = require('./styles/StyleSheet');
|
||||
|
||||
MixedDeclarationSet = require('./styles/rule/MixedDeclarationSet');
|
||||
|
||||
terminalWidth = require('../tools').getCols();
|
||||
|
||||
module.exports = Styles = (function() {
|
||||
var self;
|
||||
|
||||
self = Styles;
|
||||
|
||||
Styles.defaultRules = {
|
||||
'*': {
|
||||
display: 'inline'
|
||||
},
|
||||
'body': {
|
||||
background: 'none',
|
||||
color: 'white',
|
||||
display: 'block',
|
||||
width: terminalWidth + ' !important'
|
||||
}
|
||||
};
|
||||
|
||||
function Styles() {
|
||||
this._defaultStyles = new StyleSheet;
|
||||
this._userStyles = new StyleSheet;
|
||||
this._setDefaultStyles();
|
||||
}
|
||||
|
||||
Styles.prototype._setDefaultStyles = function() {
|
||||
this._defaultStyles.setRule(self.defaultRules);
|
||||
};
|
||||
|
||||
Styles.prototype.setRule = function(selector, rules) {
|
||||
this._userStyles.setRule.apply(this._userStyles, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
Styles.prototype.getStyleFor = function(el) {
|
||||
var styles;
|
||||
styles = el.styles;
|
||||
if (styles == null) {
|
||||
el.styles = styles = this._getComputedStyleFor(el);
|
||||
}
|
||||
return styles;
|
||||
};
|
||||
|
||||
Styles.prototype._getRawStyleFor = function(el) {
|
||||
var def, user;
|
||||
def = this._defaultStyles.getRulesFor(el);
|
||||
user = this._userStyles.getRulesFor(el);
|
||||
return MixedDeclarationSet.mix(def, user).toObject();
|
||||
};
|
||||
|
||||
Styles.prototype._getComputedStyleFor = function(el) {
|
||||
var decs, parent, prop, ref, val;
|
||||
decs = {};
|
||||
parent = el.parent;
|
||||
ref = this._getRawStyleFor(el);
|
||||
for (prop in ref) {
|
||||
val = ref[prop];
|
||||
if (val !== 'inherit') {
|
||||
decs[prop] = val;
|
||||
} else {
|
||||
throw Error("Inherited styles are not supported yet.");
|
||||
}
|
||||
}
|
||||
return decs;
|
||||
};
|
||||
|
||||
return Styles;
|
||||
|
||||
})();
|
||||
35
node_modules/renderkid/lib/renderKid/styleApplier/_common.js
generated
vendored
Normal file
35
node_modules/renderkid/lib/renderKid/styleApplier/_common.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var AnsiPainter, _common;
|
||||
|
||||
AnsiPainter = require('../../AnsiPainter');
|
||||
|
||||
module.exports = _common = {
|
||||
getStyleTagsFor: function(style) {
|
||||
var i, len, ret, tag, tagName, tagsToAdd;
|
||||
tagsToAdd = [];
|
||||
if (style.color != null) {
|
||||
tagName = 'color-' + style.color;
|
||||
if (AnsiPainter.tags[tagName] == null) {
|
||||
throw Error("Unknown color `" + style.color + "`");
|
||||
}
|
||||
tagsToAdd.push(tagName);
|
||||
}
|
||||
if (style.background != null) {
|
||||
tagName = 'bg-' + style.background;
|
||||
if (AnsiPainter.tags[tagName] == null) {
|
||||
throw Error("Unknown background `" + style.background + "`");
|
||||
}
|
||||
tagsToAdd.push(tagName);
|
||||
}
|
||||
ret = {
|
||||
before: '',
|
||||
after: ''
|
||||
};
|
||||
for (i = 0, len = tagsToAdd.length; i < len; i++) {
|
||||
tag = tagsToAdd[i];
|
||||
ret.before = ("<" + tag + ">") + ret.before;
|
||||
ret.after = ret.after + ("</" + tag + ">");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
83
node_modules/renderkid/lib/renderKid/styleApplier/block.js
generated
vendored
Normal file
83
node_modules/renderkid/lib/renderKid/styleApplier/block.js
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _common, blockStyleApplier, object, self;
|
||||
|
||||
_common = require('./_common');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
module.exports = blockStyleApplier = self = {
|
||||
applyTo: function(el, style) {
|
||||
var config, ret;
|
||||
ret = _common.getStyleTagsFor(style);
|
||||
ret.blockConfig = config = {};
|
||||
this._margins(style, config);
|
||||
this._bullet(style, config);
|
||||
this._dims(style, config);
|
||||
return ret;
|
||||
},
|
||||
_margins: function(style, config) {
|
||||
if (style.marginLeft != null) {
|
||||
object.appendOnto(config, {
|
||||
linePrependor: {
|
||||
options: {
|
||||
amount: parseInt(style.marginLeft)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (style.marginRight != null) {
|
||||
object.appendOnto(config, {
|
||||
lineAppendor: {
|
||||
options: {
|
||||
amount: parseInt(style.marginRight)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (style.marginTop != null) {
|
||||
object.appendOnto(config, {
|
||||
blockPrependor: {
|
||||
options: {
|
||||
amount: parseInt(style.marginTop)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if (style.marginBottom != null) {
|
||||
object.appendOnto(config, {
|
||||
blockAppendor: {
|
||||
options: {
|
||||
amount: parseInt(style.marginBottom)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
_bullet: function(style, config) {
|
||||
var after, before, bullet, conf, ref;
|
||||
if ((style.bullet != null) && style.bullet.enabled) {
|
||||
bullet = style.bullet;
|
||||
conf = {};
|
||||
conf.alignment = style.bullet.alignment;
|
||||
ref = _common.getStyleTagsFor({
|
||||
color: bullet.color,
|
||||
background: bullet.background
|
||||
}), before = ref.before, after = ref.after;
|
||||
conf.char = before + bullet.char + after;
|
||||
object.appendOnto(config, {
|
||||
linePrependor: {
|
||||
options: {
|
||||
bullet: conf
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
_dims: function(style, config) {
|
||||
var w;
|
||||
if (style.width != null) {
|
||||
w = parseInt(style.width);
|
||||
config.width = w;
|
||||
}
|
||||
}
|
||||
};
|
||||
26
node_modules/renderkid/lib/renderKid/styleApplier/inline.js
generated
vendored
Normal file
26
node_modules/renderkid/lib/renderKid/styleApplier/inline.js
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _common, inlineStyleApplier, self, tools;
|
||||
|
||||
tools = require('../../tools');
|
||||
|
||||
_common = require('./_common');
|
||||
|
||||
module.exports = inlineStyleApplier = self = {
|
||||
applyTo: function(el, style) {
|
||||
var ret;
|
||||
ret = _common.getStyleTagsFor(style);
|
||||
if (style.marginLeft != null) {
|
||||
ret.before = (tools.repeatString("&sp;", parseInt(style.marginLeft))) + ret.before;
|
||||
}
|
||||
if (style.marginRight != null) {
|
||||
ret.after += tools.repeatString("&sp;", parseInt(style.marginRight));
|
||||
}
|
||||
if (style.paddingLeft != null) {
|
||||
ret.before += tools.repeatString("&sp;", parseInt(style.paddingLeft));
|
||||
}
|
||||
if (style.paddingRight != null) {
|
||||
ret.after = (tools.repeatString("&sp;", parseInt(style.paddingRight))) + ret.after;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
21
node_modules/renderkid/lib/renderKid/styles/Rule.js
generated
vendored
Normal file
21
node_modules/renderkid/lib/renderKid/styles/Rule.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var DeclarationBlock, Rule, Selector;
|
||||
|
||||
Selector = require('./rule/Selector');
|
||||
|
||||
DeclarationBlock = require('./rule/DeclarationBlock');
|
||||
|
||||
module.exports = Rule = (function() {
|
||||
function Rule(selector) {
|
||||
this.selector = new Selector(selector);
|
||||
this.styles = new DeclarationBlock;
|
||||
}
|
||||
|
||||
Rule.prototype.setStyles = function(styles) {
|
||||
this.styles.set(styles);
|
||||
return this;
|
||||
};
|
||||
|
||||
return Rule;
|
||||
|
||||
})();
|
||||
72
node_modules/renderkid/lib/renderKid/styles/StyleSheet.js
generated
vendored
Normal file
72
node_modules/renderkid/lib/renderKid/styles/StyleSheet.js
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Rule, StyleSheet;
|
||||
|
||||
Rule = require('./Rule');
|
||||
|
||||
module.exports = StyleSheet = (function() {
|
||||
var self;
|
||||
|
||||
self = StyleSheet;
|
||||
|
||||
function StyleSheet() {
|
||||
this._rulesBySelector = {};
|
||||
}
|
||||
|
||||
StyleSheet.prototype.setRule = function(selector, styles) {
|
||||
var key, val;
|
||||
if (typeof selector === 'string') {
|
||||
this._setRule(selector, styles);
|
||||
} else if (typeof selector === 'object') {
|
||||
for (key in selector) {
|
||||
val = selector[key];
|
||||
this._setRule(key, val);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
StyleSheet.prototype._setRule = function(s, styles) {
|
||||
var i, len, ref, selector;
|
||||
ref = self.splitSelectors(s);
|
||||
for (i = 0, len = ref.length; i < len; i++) {
|
||||
selector = ref[i];
|
||||
this._setSingleRule(selector, styles);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
StyleSheet.prototype._setSingleRule = function(s, styles) {
|
||||
var rule, selector;
|
||||
selector = self.normalizeSelector(s);
|
||||
if (!(rule = this._rulesBySelector[selector])) {
|
||||
rule = new Rule(selector);
|
||||
this._rulesBySelector[selector] = rule;
|
||||
}
|
||||
rule.setStyles(styles);
|
||||
return this;
|
||||
};
|
||||
|
||||
StyleSheet.prototype.getRulesFor = function(el) {
|
||||
var ref, rule, rules, selector;
|
||||
rules = [];
|
||||
ref = this._rulesBySelector;
|
||||
for (selector in ref) {
|
||||
rule = ref[selector];
|
||||
if (rule.selector.matches(el)) {
|
||||
rules.push(rule);
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
};
|
||||
|
||||
StyleSheet.normalizeSelector = function(selector) {
|
||||
return selector.replace(/[\s]+/g, ' ').replace(/[\s]*([>\,\+]{1})[\s]*/g, '$1').trim();
|
||||
};
|
||||
|
||||
StyleSheet.splitSelectors = function(s) {
|
||||
return s.trim().split(',');
|
||||
};
|
||||
|
||||
return StyleSheet;
|
||||
|
||||
})();
|
||||
65
node_modules/renderkid/lib/renderKid/styles/rule/DeclarationBlock.js
generated
vendored
Normal file
65
node_modules/renderkid/lib/renderKid/styles/rule/DeclarationBlock.js
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Arbitrary, DeclarationBlock, declarationClasses;
|
||||
|
||||
module.exports = DeclarationBlock = (function() {
|
||||
var self;
|
||||
|
||||
self = DeclarationBlock;
|
||||
|
||||
function DeclarationBlock() {
|
||||
this._declarations = {};
|
||||
}
|
||||
|
||||
DeclarationBlock.prototype.set = function(prop, value) {
|
||||
var key, val;
|
||||
if (typeof prop === 'object') {
|
||||
for (key in prop) {
|
||||
val = prop[key];
|
||||
this.set(key, val);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
prop = self.sanitizeProp(prop);
|
||||
this._getDeclarationClass(prop).setOnto(this._declarations, prop, value);
|
||||
return this;
|
||||
};
|
||||
|
||||
DeclarationBlock.prototype._getDeclarationClass = function(prop) {
|
||||
var cls;
|
||||
if (prop[0] === '_') {
|
||||
return Arbitrary;
|
||||
}
|
||||
if (!(cls = declarationClasses[prop])) {
|
||||
throw Error("Unknown property `" + prop + "`. Write it as `_" + prop + "` if you're defining a custom property");
|
||||
}
|
||||
return cls;
|
||||
};
|
||||
|
||||
DeclarationBlock.sanitizeProp = function(prop) {
|
||||
return String(prop).trim();
|
||||
};
|
||||
|
||||
return DeclarationBlock;
|
||||
|
||||
})();
|
||||
|
||||
Arbitrary = require('./declarationBlock/Arbitrary');
|
||||
|
||||
declarationClasses = {
|
||||
color: require('./declarationBlock/Color'),
|
||||
background: require('./declarationBlock/Background'),
|
||||
width: require('./declarationBlock/Width'),
|
||||
height: require('./declarationBlock/Height'),
|
||||
bullet: require('./declarationBlock/Bullet'),
|
||||
display: require('./declarationBlock/Display'),
|
||||
margin: require('./declarationBlock/Margin'),
|
||||
marginTop: require('./declarationBlock/MarginTop'),
|
||||
marginLeft: require('./declarationBlock/MarginLeft'),
|
||||
marginRight: require('./declarationBlock/MarginRight'),
|
||||
marginBottom: require('./declarationBlock/MarginBottom'),
|
||||
padding: require('./declarationBlock/Padding'),
|
||||
paddingTop: require('./declarationBlock/PaddingTop'),
|
||||
paddingLeft: require('./declarationBlock/PaddingLeft'),
|
||||
paddingRight: require('./declarationBlock/PaddingRight'),
|
||||
paddingBottom: require('./declarationBlock/PaddingBottom')
|
||||
};
|
||||
78
node_modules/renderkid/lib/renderKid/styles/rule/MixedDeclarationSet.js
generated
vendored
Normal file
78
node_modules/renderkid/lib/renderKid/styles/rule/MixedDeclarationSet.js
generated
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MixedDeclarationSet,
|
||||
slice = [].slice;
|
||||
|
||||
module.exports = MixedDeclarationSet = (function() {
|
||||
var self;
|
||||
|
||||
self = MixedDeclarationSet;
|
||||
|
||||
MixedDeclarationSet.mix = function() {
|
||||
var i, len, mixed, ruleSets, rules;
|
||||
ruleSets = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
||||
mixed = new self;
|
||||
for (i = 0, len = ruleSets.length; i < len; i++) {
|
||||
rules = ruleSets[i];
|
||||
mixed.mixWithList(rules);
|
||||
}
|
||||
return mixed;
|
||||
};
|
||||
|
||||
function MixedDeclarationSet() {
|
||||
this._declarations = {};
|
||||
}
|
||||
|
||||
MixedDeclarationSet.prototype.mixWithList = function(rules) {
|
||||
var i, len, rule;
|
||||
rules.sort(function(a, b) {
|
||||
return a.selector.priority > b.selector.priority;
|
||||
});
|
||||
for (i = 0, len = rules.length; i < len; i++) {
|
||||
rule = rules[i];
|
||||
this._mixWithRule(rule);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
MixedDeclarationSet.prototype._mixWithRule = function(rule) {
|
||||
var dec, prop, ref;
|
||||
ref = rule.styles._declarations;
|
||||
for (prop in ref) {
|
||||
dec = ref[prop];
|
||||
this._mixWithDeclaration(dec);
|
||||
}
|
||||
};
|
||||
|
||||
MixedDeclarationSet.prototype._mixWithDeclaration = function(dec) {
|
||||
var cur;
|
||||
cur = this._declarations[dec.prop];
|
||||
if ((cur != null) && cur.important && !dec.important) {
|
||||
return;
|
||||
}
|
||||
this._declarations[dec.prop] = dec;
|
||||
};
|
||||
|
||||
MixedDeclarationSet.prototype.get = function(prop) {
|
||||
if (prop == null) {
|
||||
return this._declarations;
|
||||
}
|
||||
if (this._declarations[prop] == null) {
|
||||
return null;
|
||||
}
|
||||
return this._declarations[prop].val;
|
||||
};
|
||||
|
||||
MixedDeclarationSet.prototype.toObject = function() {
|
||||
var dec, obj, prop, ref;
|
||||
obj = {};
|
||||
ref = this._declarations;
|
||||
for (prop in ref) {
|
||||
dec = ref[prop];
|
||||
obj[prop] = dec.val;
|
||||
}
|
||||
return obj;
|
||||
};
|
||||
|
||||
return MixedDeclarationSet;
|
||||
|
||||
})();
|
||||
38
node_modules/renderkid/lib/renderKid/styles/rule/Selector.js
generated
vendored
Normal file
38
node_modules/renderkid/lib/renderKid/styles/rule/Selector.js
generated
vendored
Normal file
@ -0,0 +1,38 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var CSSSelect, Selector;
|
||||
|
||||
CSSSelect = require('css-select');
|
||||
|
||||
module.exports = Selector = (function() {
|
||||
var self;
|
||||
|
||||
self = Selector;
|
||||
|
||||
function Selector(text1) {
|
||||
this.text = text1;
|
||||
this._fn = CSSSelect.compile(this.text);
|
||||
this.priority = self.calculatePriority(this.text);
|
||||
}
|
||||
|
||||
Selector.prototype.matches = function(elem) {
|
||||
return CSSSelect.is(elem, this._fn);
|
||||
};
|
||||
|
||||
Selector.calculatePriority = function(text) {
|
||||
var n, priotrity;
|
||||
priotrity = 0;
|
||||
if (n = text.match(/[\#]{1}/g)) {
|
||||
priotrity += 100 * n.length;
|
||||
}
|
||||
if (n = text.match(/[a-zA-Z]+/g)) {
|
||||
priotrity += 2 * n.length;
|
||||
}
|
||||
if (n = text.match(/\*/g)) {
|
||||
priotrity += 1 * n.length;
|
||||
}
|
||||
return priotrity;
|
||||
};
|
||||
|
||||
return Selector;
|
||||
|
||||
})();
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Arbitrary.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Arbitrary.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Arbitrary, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = Arbitrary = (function(superClass) {
|
||||
extend(Arbitrary, superClass);
|
||||
|
||||
function Arbitrary() {
|
||||
return Arbitrary.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return Arbitrary;
|
||||
|
||||
})(_Declaration);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Background.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Background.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Background, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = Background = (function(superClass) {
|
||||
extend(Background, superClass);
|
||||
|
||||
function Background() {
|
||||
return Background.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return Background;
|
||||
|
||||
})(_Declaration);
|
||||
63
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Bullet.js
generated
vendored
Normal file
63
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Bullet.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Bullet, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = Bullet = (function(superClass) {
|
||||
var self;
|
||||
|
||||
extend(Bullet, superClass);
|
||||
|
||||
function Bullet() {
|
||||
return Bullet.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
self = Bullet;
|
||||
|
||||
Bullet.prototype._set = function(val) {
|
||||
var alignment, bg, char, color, enabled, m, original;
|
||||
val = String(val);
|
||||
original = val;
|
||||
char = null;
|
||||
enabled = false;
|
||||
color = 'none';
|
||||
bg = 'none';
|
||||
if (m = val.match(/\"([^"]+)\"/) || (m = val.match(/\'([^']+)\'/))) {
|
||||
char = m[1];
|
||||
val = val.replace(m[0], '');
|
||||
enabled = true;
|
||||
}
|
||||
if (m = val.match(/(none|left|right|center)/)) {
|
||||
alignment = m[1];
|
||||
val = val.replace(m[0], '');
|
||||
} else {
|
||||
alignment = 'left';
|
||||
}
|
||||
if (alignment === 'none') {
|
||||
enabled = false;
|
||||
}
|
||||
if (m = val.match(/color\:([\w\-]+)/)) {
|
||||
color = m[1];
|
||||
val = val.replace(m[0], '');
|
||||
}
|
||||
if (m = val.match(/bg\:([\w\-]+)/)) {
|
||||
bg = m[1];
|
||||
val = val.replace(m[0], '');
|
||||
}
|
||||
if (val.trim() !== '') {
|
||||
throw Error("Unrecognizable value `" + original + "` for `" + this.prop + "`");
|
||||
}
|
||||
return this.val = {
|
||||
enabled: enabled,
|
||||
char: char,
|
||||
alignment: alignment,
|
||||
background: bg,
|
||||
color: color
|
||||
};
|
||||
};
|
||||
|
||||
return Bullet;
|
||||
|
||||
})(_Declaration);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Color.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Color.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Color, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = Color = (function(superClass) {
|
||||
extend(Color, superClass);
|
||||
|
||||
function Color() {
|
||||
return Color.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return Color;
|
||||
|
||||
})(_Declaration);
|
||||
32
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Display.js
generated
vendored
Normal file
32
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Display.js
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Display, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty,
|
||||
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = Display = (function(superClass) {
|
||||
var self;
|
||||
|
||||
extend(Display, superClass);
|
||||
|
||||
function Display() {
|
||||
return Display.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
self = Display;
|
||||
|
||||
Display._allowed = ['inline', 'block', 'none'];
|
||||
|
||||
Display.prototype._set = function(val) {
|
||||
val = String(val).toLowerCase();
|
||||
if (indexOf.call(self._allowed, val) < 0) {
|
||||
throw Error("Unrecognizable value `" + val + "` for `" + this.prop + "`");
|
||||
}
|
||||
return this.val = val;
|
||||
};
|
||||
|
||||
return Display;
|
||||
|
||||
})(_Declaration);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Height.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Height.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Height, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = Height = (function(superClass) {
|
||||
extend(Height, superClass);
|
||||
|
||||
function Height() {
|
||||
return Height.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return Height;
|
||||
|
||||
})(_Length);
|
||||
64
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Margin.js
generated
vendored
Normal file
64
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Margin.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Margin, MarginBottom, MarginLeft, MarginRight, MarginTop, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
MarginTop = require('./MarginTop');
|
||||
|
||||
MarginLeft = require('./MarginLeft');
|
||||
|
||||
MarginRight = require('./MarginRight');
|
||||
|
||||
MarginBottom = require('./MarginBottom');
|
||||
|
||||
module.exports = Margin = (function(superClass) {
|
||||
var self;
|
||||
|
||||
extend(Margin, superClass);
|
||||
|
||||
function Margin() {
|
||||
return Margin.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
self = Margin;
|
||||
|
||||
Margin.setOnto = function(declarations, prop, originalValue) {
|
||||
var append, val, vals;
|
||||
append = '';
|
||||
val = _Declaration.sanitizeValue(originalValue);
|
||||
if (_Declaration.importantClauseRx.test(String(val))) {
|
||||
append = ' !important';
|
||||
val = val.replace(_Declaration.importantClauseRx, '');
|
||||
}
|
||||
val = val.trim();
|
||||
if (val.length === 0) {
|
||||
return self._setAllDirections(declarations, append, append, append, append);
|
||||
}
|
||||
vals = val.split(" ").map(function(val) {
|
||||
return val + append;
|
||||
});
|
||||
if (vals.length === 1) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]);
|
||||
} else if (vals.length === 2) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]);
|
||||
} else if (vals.length === 3) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]);
|
||||
} else if (vals.length === 4) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]);
|
||||
} else {
|
||||
throw Error("Can't understand value for margin: `" + originalValue + "`");
|
||||
}
|
||||
};
|
||||
|
||||
Margin._setAllDirections = function(declarations, top, right, bottom, left) {
|
||||
MarginTop.setOnto(declarations, 'marginTop', top);
|
||||
MarginTop.setOnto(declarations, 'marginRight', right);
|
||||
MarginTop.setOnto(declarations, 'marginBottom', bottom);
|
||||
MarginTop.setOnto(declarations, 'marginLeft', left);
|
||||
};
|
||||
|
||||
return Margin;
|
||||
|
||||
})(_Declaration);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginBottom.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginBottom.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MarginBottom, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = MarginBottom = (function(superClass) {
|
||||
extend(MarginBottom, superClass);
|
||||
|
||||
function MarginBottom() {
|
||||
return MarginBottom.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return MarginBottom;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginLeft.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginLeft.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MarginLeft, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = MarginLeft = (function(superClass) {
|
||||
extend(MarginLeft, superClass);
|
||||
|
||||
function MarginLeft() {
|
||||
return MarginLeft.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return MarginLeft;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginRight.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginRight.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MarginRight, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = MarginRight = (function(superClass) {
|
||||
extend(MarginRight, superClass);
|
||||
|
||||
function MarginRight() {
|
||||
return MarginRight.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return MarginRight;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginTop.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/MarginTop.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var MarginTop, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = MarginTop = (function(superClass) {
|
||||
extend(MarginTop, superClass);
|
||||
|
||||
function MarginTop() {
|
||||
return MarginTop.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return MarginTop;
|
||||
|
||||
})(_Length);
|
||||
64
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Padding.js
generated
vendored
Normal file
64
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Padding.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Padding, PaddingBottom, PaddingLeft, PaddingRight, PaddingTop, _Declaration,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
PaddingTop = require('./PaddingTop');
|
||||
|
||||
PaddingLeft = require('./PaddingLeft');
|
||||
|
||||
PaddingRight = require('./PaddingRight');
|
||||
|
||||
PaddingBottom = require('./PaddingBottom');
|
||||
|
||||
module.exports = Padding = (function(superClass) {
|
||||
var self;
|
||||
|
||||
extend(Padding, superClass);
|
||||
|
||||
function Padding() {
|
||||
return Padding.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
self = Padding;
|
||||
|
||||
Padding.setOnto = function(declarations, prop, originalValue) {
|
||||
var append, val, vals;
|
||||
append = '';
|
||||
val = _Declaration.sanitizeValue(originalValue);
|
||||
if (_Declaration.importantClauseRx.test(String(val))) {
|
||||
append = ' !important';
|
||||
val = val.replace(_Declaration.importantClauseRx, '');
|
||||
}
|
||||
val = val.trim();
|
||||
if (val.length === 0) {
|
||||
return self._setAllDirections(declarations, append, append, append, append);
|
||||
}
|
||||
vals = val.split(" ").map(function(val) {
|
||||
return val + append;
|
||||
});
|
||||
if (vals.length === 1) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[0], vals[0], vals[0]);
|
||||
} else if (vals.length === 2) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[0], vals[1]);
|
||||
} else if (vals.length === 3) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[1]);
|
||||
} else if (vals.length === 4) {
|
||||
return self._setAllDirections(declarations, vals[0], vals[1], vals[2], vals[3]);
|
||||
} else {
|
||||
throw Error("Can't understand value for padding: `" + originalValue + "`");
|
||||
}
|
||||
};
|
||||
|
||||
Padding._setAllDirections = function(declarations, top, right, bottom, left) {
|
||||
PaddingTop.setOnto(declarations, 'paddingTop', top);
|
||||
PaddingTop.setOnto(declarations, 'paddingRight', right);
|
||||
PaddingTop.setOnto(declarations, 'paddingBottom', bottom);
|
||||
PaddingTop.setOnto(declarations, 'paddingLeft', left);
|
||||
};
|
||||
|
||||
return Padding;
|
||||
|
||||
})(_Declaration);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingBottom.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingBottom.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var PaddingBottom, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = PaddingBottom = (function(superClass) {
|
||||
extend(PaddingBottom, superClass);
|
||||
|
||||
function PaddingBottom() {
|
||||
return PaddingBottom.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return PaddingBottom;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingLeft.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingLeft.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var PaddingLeft, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = PaddingLeft = (function(superClass) {
|
||||
extend(PaddingLeft, superClass);
|
||||
|
||||
function PaddingLeft() {
|
||||
return PaddingLeft.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return PaddingLeft;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingRight.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingRight.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var PaddingRight, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = PaddingRight = (function(superClass) {
|
||||
extend(PaddingRight, superClass);
|
||||
|
||||
function PaddingRight() {
|
||||
return PaddingRight.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return PaddingRight;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingTop.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/PaddingTop.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var PaddingTop, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = PaddingTop = (function(superClass) {
|
||||
extend(PaddingTop, superClass);
|
||||
|
||||
function PaddingTop() {
|
||||
return PaddingTop.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return PaddingTop;
|
||||
|
||||
})(_Length);
|
||||
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Width.js
generated
vendored
Normal file
17
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/Width.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var Width, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Length = require('./_Length');
|
||||
|
||||
module.exports = Width = (function(superClass) {
|
||||
extend(Width, superClass);
|
||||
|
||||
function Width() {
|
||||
return Width.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return Width;
|
||||
|
||||
})(_Length);
|
||||
84
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js
generated
vendored
Normal file
84
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Declaration.js
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _Declaration;
|
||||
|
||||
module.exports = _Declaration = (function() {
|
||||
var self;
|
||||
|
||||
self = _Declaration;
|
||||
|
||||
_Declaration.importantClauseRx = /(\s\!important)$/;
|
||||
|
||||
_Declaration.setOnto = function(declarations, prop, val) {
|
||||
var dec;
|
||||
if (!(dec = declarations[prop])) {
|
||||
return declarations[prop] = new this(prop, val);
|
||||
} else {
|
||||
return dec.set(val);
|
||||
}
|
||||
};
|
||||
|
||||
_Declaration.sanitizeValue = function(val) {
|
||||
return String(val).trim().replace(/[\s]+/g, ' ');
|
||||
};
|
||||
|
||||
_Declaration.inheritAllowed = false;
|
||||
|
||||
function _Declaration(prop1, val) {
|
||||
this.prop = prop1;
|
||||
this.important = false;
|
||||
this.set(val);
|
||||
}
|
||||
|
||||
_Declaration.prototype.get = function() {
|
||||
return this._get();
|
||||
};
|
||||
|
||||
_Declaration.prototype._get = function() {
|
||||
return this.val;
|
||||
};
|
||||
|
||||
_Declaration.prototype._pickImportantClause = function(val) {
|
||||
if (self.importantClauseRx.test(String(val))) {
|
||||
this.important = true;
|
||||
return val.replace(self.importantClauseRx, '');
|
||||
} else {
|
||||
this.important = false;
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
_Declaration.prototype.set = function(val) {
|
||||
val = self.sanitizeValue(val);
|
||||
val = this._pickImportantClause(val);
|
||||
val = val.trim();
|
||||
if (this._handleNullOrInherit(val)) {
|
||||
return this;
|
||||
}
|
||||
this._set(val);
|
||||
return this;
|
||||
};
|
||||
|
||||
_Declaration.prototype._set = function(val) {
|
||||
return this.val = val;
|
||||
};
|
||||
|
||||
_Declaration.prototype._handleNullOrInherit = function(val) {
|
||||
if (val === '') {
|
||||
this.val = '';
|
||||
return true;
|
||||
}
|
||||
if (val === 'inherit') {
|
||||
if (this.constructor.inheritAllowed) {
|
||||
this.val = 'inherit';
|
||||
} else {
|
||||
throw Error("Inherit is not allowed for `" + this.prop + "`");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return _Declaration;
|
||||
|
||||
})();
|
||||
24
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Length.js
generated
vendored
Normal file
24
node_modules/renderkid/lib/renderKid/styles/rule/declarationBlock/_Length.js
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var _Declaration, _Length,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
_Declaration = require('./_Declaration');
|
||||
|
||||
module.exports = _Length = (function(superClass) {
|
||||
extend(_Length, superClass);
|
||||
|
||||
function _Length() {
|
||||
return _Length.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
_Length.prototype._set = function(val) {
|
||||
if (!/^[0-9]+$/.test(String(val))) {
|
||||
throw Error("`" + this.prop + "` only takes an integer for value");
|
||||
}
|
||||
return this.val = parseInt(val);
|
||||
};
|
||||
|
||||
return _Length;
|
||||
|
||||
})(_Declaration);
|
||||
88
node_modules/renderkid/lib/tools.js
generated
vendored
Normal file
88
node_modules/renderkid/lib/tools.js
generated
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
// Generated by CoffeeScript 1.9.3
|
||||
var htmlparser, object, objectToDom, self;
|
||||
|
||||
htmlparser = require('htmlparser2');
|
||||
|
||||
object = require('utila').object;
|
||||
|
||||
objectToDom = require('dom-converter').objectToDom;
|
||||
|
||||
module.exports = self = {
|
||||
repeatString: function(str, times) {
|
||||
var i, j, output, ref;
|
||||
output = '';
|
||||
for (i = j = 0, ref = times; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
||||
output += str;
|
||||
}
|
||||
return output;
|
||||
},
|
||||
toDom: function(subject) {
|
||||
if (typeof subject === 'string') {
|
||||
return self.stringToDom(subject);
|
||||
} else if (object.isBareObject(subject)) {
|
||||
return self._objectToDom(subject);
|
||||
} else {
|
||||
throw Error("tools.toDom() only supports strings and objects");
|
||||
}
|
||||
},
|
||||
stringToDom: function(string) {
|
||||
var handler, parser;
|
||||
handler = new htmlparser.DomHandler;
|
||||
parser = new htmlparser.Parser(handler);
|
||||
parser.write(string);
|
||||
parser.end();
|
||||
return handler.dom;
|
||||
},
|
||||
_fixQuotesInDom: function(input) {
|
||||
var j, len, node;
|
||||
if (Array.isArray(input)) {
|
||||
for (j = 0, len = input.length; j < len; j++) {
|
||||
node = input[j];
|
||||
self._fixQuotesInDom(node);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
node = input;
|
||||
if (node.type === 'text') {
|
||||
return node.data = self._quoteNodeText(node.data);
|
||||
} else {
|
||||
return self._fixQuotesInDom(node.children);
|
||||
}
|
||||
},
|
||||
objectToDom: function(o) {
|
||||
if (!Array.isArray(o)) {
|
||||
if (!object.isBareObject(o)) {
|
||||
throw Error("objectToDom() only accepts a bare object or an array");
|
||||
}
|
||||
}
|
||||
return self._fixQuotesInDom(objectToDom(o));
|
||||
},
|
||||
quote: function(str) {
|
||||
return String(str).replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"').replace(/\ /g, '&sp;').replace(/\n/g, '<br />');
|
||||
},
|
||||
_quoteNodeText: function(text) {
|
||||
return String(text).replace(/\&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/\"/g, '"').replace(/\ /g, '&sp;').replace(/\n/g, "&nl;");
|
||||
},
|
||||
getCols: function() {
|
||||
var cols, tty;
|
||||
tty = require('tty');
|
||||
cols = (function() {
|
||||
try {
|
||||
if (tty.isatty(1) && tty.isatty(2)) {
|
||||
if (process.stdout.getWindowSize) {
|
||||
return process.stdout.getWindowSize(1)[0];
|
||||
} else if (tty.getWindowSize) {
|
||||
return tty.getWindowSize()[1];
|
||||
} else if (process.stdout.columns) {
|
||||
return process.stdout.columns;
|
||||
}
|
||||
}
|
||||
} catch (_error) {}
|
||||
})();
|
||||
if (typeof cols === 'number' && cols > 30) {
|
||||
return cols;
|
||||
} else {
|
||||
return 80;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user