Comparing version 0.3.4 to 0.4.0
@@ -144,3 +144,14 @@ var shim = require('./shim'); | ||
MagicPen.prototype.callOnClone = function (callback) { | ||
var clone = this.clone(); | ||
callback.call(clone); | ||
return clone; | ||
}; | ||
MagicPen.prototype.block = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.block(this.callOnClone(pen)); | ||
} | ||
var blockOutput = map(pen.output, function (line) { | ||
@@ -153,2 +164,6 @@ return [].concat(line); | ||
MagicPen.prototype.append = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.append(this.callOnClone(pen)); | ||
} | ||
if (pen.output.length === 0) { | ||
@@ -168,2 +183,6 @@ return this; | ||
MagicPen.prototype.prependLinesWith = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.prependLinesWith(this.callOnClone(pen)); | ||
} | ||
if (pen.output.length === 0 || this.output.length === 0) { | ||
@@ -170,0 +189,0 @@ return this; |
@@ -350,3 +350,14 @@ /*! | ||
MagicPen.prototype.callOnClone = function (callback) { | ||
var clone = this.clone(); | ||
callback.call(clone); | ||
return clone; | ||
}; | ||
MagicPen.prototype.block = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.block(this.callOnClone(pen)); | ||
} | ||
var blockOutput = map(pen.output, function (line) { | ||
@@ -359,2 +370,6 @@ return [].concat(line); | ||
MagicPen.prototype.append = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.append(this.callOnClone(pen)); | ||
} | ||
if (pen.output.length === 0) { | ||
@@ -374,2 +389,6 @@ return this; | ||
MagicPen.prototype.prependLinesWith = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.prependLinesWith(this.callOnClone(pen)); | ||
} | ||
if (pen.output.length === 0 || this.output.length === 0) { | ||
@@ -376,0 +395,0 @@ return this; |
{ | ||
"name": "magicpen", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
@@ -125,8 +125,14 @@ # MagicPen | ||
*Text properties*: `bold`, `dim`, `italic`, `underline`, `inverse`, `hidden`, `strikeThrough`. | ||
*Text properties*: | ||
*Foreground colors*: `#bada55`, `#eee`, `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`, `gray`. | ||
![Text properties: bold, dim, italic, underline, inverse, hidden, strikeThrough.](images/text_properties.png) | ||
*Background colors*: `bg#bada55`, `bg#eee`, `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`. | ||
*Foreground colors*: | ||
![Foreground colors: #bada55, #eee, black, red, green, yellow, blue, magenta, cyan, white, gray.](images/text_colors.png) | ||
*Background colors*: | ||
![Background colors: bg#bada55, bg#eee, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite.](images/background_colors.png) | ||
#### Example: | ||
@@ -208,3 +214,3 @@ | ||
### append(pen) | ||
### append(pen), append(function()) | ||
@@ -222,4 +228,12 @@ Appends the content of the given pen to the end of this pen. | ||
### block(pen) | ||
```js | ||
var pen = magicpen(); | ||
pen.text('Hello').sp().append(function () { | ||
this.text('world!'); | ||
}); | ||
expect(pen.toString(), 'to equal', 'Hello world!'); | ||
``` | ||
### block(pen), block(function) | ||
Appends the content of the given pen to the end of this pen in an | ||
@@ -241,4 +255,15 @@ inline block. | ||
### prependLinesWith(pen) | ||
```js | ||
var pen = magicpen(); | ||
pen.text('Text before block').block(function () { | ||
this.text(' // This is a').nl() | ||
.text(' // multiline block'); | ||
}); | ||
expect(pen.toString(), 'to equal', | ||
'Text before block // This is a\n' + | ||
' // multiline block'); | ||
``` | ||
### prependLinesWith(pen), prependLinesWith(function) | ||
Prepends each line of this pen with the content of the given pen. | ||
@@ -253,3 +278,4 @@ | ||
.text('after line').nl() | ||
.text('after line'); | ||
.text('after line') | ||
.prependLinesWith(otherPen); | ||
expect(pen.toString(), 'to equal', | ||
@@ -261,2 +287,16 @@ '> Line\n' + | ||
```js | ||
var pen = magicpen(); | ||
pen.text('Line').nl() | ||
.text('after line').nl() | ||
.text('after line') | ||
.prependLinesWith(function () { | ||
this.text('> '); | ||
}); | ||
expect(pen.toString(), 'to equal', | ||
'> Line\n' + | ||
'> after line\n' + | ||
'> after line'); | ||
``` | ||
### size() | ||
@@ -263,0 +303,0 @@ |
@@ -10,2 +10,6 @@ /*global describe, it, beforeEach*/ | ||
beforeEach(function () { | ||
pen = magicpen(); | ||
}); | ||
function forEach(arr, callback, that) { | ||
@@ -84,7 +88,75 @@ for (var i = 0, n = arr.length; i < n; i += 1) | ||
describe('in text mode', function () { | ||
beforeEach(function () { | ||
pen = magicpen(); | ||
describe('block', function () { | ||
it('all lines in the block are indented', function () { | ||
pen.red('Hello').block( | ||
pen.clone() | ||
.gray(' // ').text('This is a').nl() | ||
.indentLines() | ||
.gray(' // ').indent().text('multiline comment')); | ||
expect(pen.toString(), 'to equal', | ||
'Hello // This is a\n' + | ||
' // multiline comment'); | ||
}); | ||
it('can be called with a function as argument', function () { | ||
pen.red('Hello').block(function () { | ||
this.gray(' // ').text('This is a').nl() | ||
.indentLines() | ||
.gray(' // ').indent().text('multiline comment'); | ||
}); | ||
expect(pen.toString(), 'to equal', | ||
'Hello // This is a\n' + | ||
' // multiline comment'); | ||
}); | ||
}); | ||
describe('append', function () { | ||
it('appends the given pen to the end of the output', function () { | ||
pen.text('Hello').sp().append( | ||
pen.clone() | ||
.red('world!')); | ||
expect(pen.toString(), 'to equal', | ||
'Hello world!'); | ||
}); | ||
it('can be called with a function as argument', function () { | ||
pen.text('Hello').sp().append(function () { | ||
this.red('world!'); | ||
}); | ||
expect(pen.toString(), 'to equal', | ||
'Hello world!'); | ||
}); | ||
}); | ||
describe('prependLinesWith', function () { | ||
it('prepends all lines with the the content of the given pen', function () { | ||
pen.text('First line').nl() | ||
.text('Second line').nl() | ||
.indentLines() | ||
.indent().text('Third line') | ||
.prependLinesWith(pen.clone().gray(' // ')); | ||
expect(pen.toString(), 'to equal', | ||
' // First line\n' + | ||
' // Second line\n' + | ||
' // Third line'); | ||
}); | ||
it('can be called with a function as argument', function () { | ||
pen.text('First line').nl() | ||
.text('Second line').nl() | ||
.indentLines() | ||
.indent().text('Third line') | ||
.prependLinesWith(function () { | ||
this.gray(' // '); | ||
}); | ||
expect(pen.toString(), 'to equal', | ||
' // First line\n' + | ||
' // Second line\n' + | ||
' // Third line'); | ||
}); | ||
}); | ||
describe('in text mode', function () { | ||
it('ignores unknown styles', function () { | ||
@@ -91,0 +163,0 @@ pen.text('>').write('test', 'text').text('<'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
149413
26
2185
457