Default.js
1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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'));