Default.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Generated by CoffeeScript 1.9.3
  2. var DefaultLinePrependor, SpecialString, tools,
  3. 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; },
  4. hasProp = {}.hasOwnProperty;
  5. tools = require('../../../tools');
  6. SpecialString = require('../../SpecialString');
  7. module.exports = DefaultLinePrependor = (function(superClass) {
  8. var self;
  9. extend(DefaultLinePrependor, superClass);
  10. function DefaultLinePrependor() {
  11. return DefaultLinePrependor.__super__.constructor.apply(this, arguments);
  12. }
  13. self = DefaultLinePrependor;
  14. DefaultLinePrependor.pad = function(howMuch) {
  15. return tools.repeatString(" ", howMuch);
  16. };
  17. DefaultLinePrependor.prototype._render = function(inherited, options) {
  18. var addToLeft, addToRight, alignment, bullet, char, charLen, diff, left, output, space, toWrite;
  19. if (this._lineNo === 0 && (bullet = this._config.bullet)) {
  20. char = bullet.char;
  21. charLen = SpecialString(char).length;
  22. alignment = bullet.alignment;
  23. space = this._config.amount;
  24. toWrite = char;
  25. addToLeft = '';
  26. addToRight = '';
  27. if (space > charLen) {
  28. diff = space - charLen;
  29. if (alignment === 'right') {
  30. addToLeft = self.pad(diff);
  31. } else if (alignment === 'left') {
  32. addToRight = self.pad(diff);
  33. } else if (alignment === 'center') {
  34. left = Math.round(diff / 2);
  35. addToLeft = self.pad(left);
  36. addToRight = self.pad(diff - left);
  37. } else {
  38. throw Error("Unkown alignment `" + alignment + "`");
  39. }
  40. }
  41. output = addToLeft + char + addToRight;
  42. } else {
  43. output = self.pad(this._config.amount);
  44. }
  45. return inherited + output;
  46. };
  47. return DefaultLinePrependor;
  48. })(require('./_LinePrependor'));