Comparing version 2.0.0 to 2.1.0
@@ -155,14 +155,25 @@ /*global window*/ | ||
MagicPen.prototype.callOnClone = function (callback) { | ||
var clone = this.clone(); | ||
callback.call(clone); | ||
return clone; | ||
MagicPen.prototype.getContentFromArguments = function (args) { | ||
var clone; | ||
if (args[0].isMagicPen) { | ||
return args[0]; | ||
} else if (typeof args[0] === 'function') { | ||
clone = this.clone(); | ||
args[0].call(clone, clone); | ||
return clone; | ||
} else if (typeof args[0] === 'string') { | ||
clone = this.clone(); | ||
clone[args[0]].apply(clone, Array.prototype.slice.call(args, 1)); | ||
return clone; | ||
} else { | ||
throw new Error('Requires the arguments to be:\n' + | ||
'a pen or\n' + | ||
'a callback append content to a penor\n' + | ||
'a style and arguments for that style'); | ||
} | ||
}; | ||
MagicPen.prototype.block = function () { | ||
var pen = this.getContentFromArguments(arguments); | ||
MagicPen.prototype.block = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.block(this.callOnClone(pen)); | ||
} | ||
var blockOutput = pen.output.map(function (line) { | ||
@@ -174,6 +185,4 @@ return [].concat(line); | ||
MagicPen.prototype.append = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.append(this.callOnClone(pen)); | ||
} | ||
MagicPen.prototype.append = function () { | ||
var pen = this.getContentFromArguments(arguments); | ||
@@ -193,3 +202,3 @@ if (pen.output.length === 0) { | ||
MagicPen.prototype.prependLinesWith = function (pen) { | ||
MagicPen.prototype.prependLinesWith = function () { | ||
if (this.output.length === 0) { | ||
@@ -199,5 +208,3 @@ return this; | ||
if (typeof pen === 'function') { | ||
return this.prependLinesWith(this.callOnClone(pen)); | ||
} | ||
var pen = this.getContentFromArguments(arguments); | ||
@@ -204,0 +211,0 @@ if (pen.output.length === 0) { |
@@ -398,14 +398,25 @@ /*! | ||
MagicPen.prototype.callOnClone = function (callback) { | ||
var clone = this.clone(); | ||
callback.call(clone); | ||
return clone; | ||
MagicPen.prototype.getContentFromArguments = function (args) { | ||
var clone; | ||
if (args[0].isMagicPen) { | ||
return args[0]; | ||
} else if (typeof args[0] === 'function') { | ||
clone = this.clone(); | ||
args[0].call(clone, clone); | ||
return clone; | ||
} else if (typeof args[0] === 'string') { | ||
clone = this.clone(); | ||
clone[args[0]].apply(clone, Array.prototype.slice.call(args, 1)); | ||
return clone; | ||
} else { | ||
throw new Error('Requires the arguments to be:\n' + | ||
'a pen or\n' + | ||
'a callback append content to a penor\n' + | ||
'a style and arguments for that style'); | ||
} | ||
}; | ||
MagicPen.prototype.block = function () { | ||
var pen = this.getContentFromArguments(arguments); | ||
MagicPen.prototype.block = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.block(this.callOnClone(pen)); | ||
} | ||
var blockOutput = pen.output.map(function (line) { | ||
@@ -417,6 +428,4 @@ return [].concat(line); | ||
MagicPen.prototype.append = function (pen) { | ||
if (typeof pen === 'function') { | ||
return this.append(this.callOnClone(pen)); | ||
} | ||
MagicPen.prototype.append = function () { | ||
var pen = this.getContentFromArguments(arguments); | ||
@@ -436,3 +445,3 @@ if (pen.output.length === 0) { | ||
MagicPen.prototype.prependLinesWith = function (pen) { | ||
MagicPen.prototype.prependLinesWith = function () { | ||
if (this.output.length === 0) { | ||
@@ -442,5 +451,3 @@ return this; | ||
if (typeof pen === 'function') { | ||
return this.prependLinesWith(this.callOnClone(pen)); | ||
} | ||
var pen = this.getContentFromArguments(arguments); | ||
@@ -447,0 +454,0 @@ if (pen.output.length === 0) { |
{ | ||
"name": "magicpen", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
@@ -242,3 +242,3 @@ # MagicPen | ||
### block(pen), block(function) | ||
### block(pen), block(function), block(style, arg...) | ||
@@ -272,4 +272,12 @@ Appends the content of the given pen to the end of this pen in an | ||
### prependLinesWith(pen), prependLinesWith(function) | ||
```js | ||
var pen = magicpen(); | ||
pen.red('Hello').block('text', ' // This is a\n // multiline comment'); | ||
expect(pen.toString(), 'to equal', | ||
'Hello // This is a\n' + | ||
' // multiline comment'); | ||
``` | ||
### prependLinesWith(pen), prependLinesWith(function), prependLinesWith(style, arg...) | ||
Prepends each line of this pen with the content of the given pen. | ||
@@ -306,2 +314,14 @@ | ||
```js | ||
var pen = magicpen(); | ||
pen.text('Line').nl() | ||
.text('after line').nl() | ||
.text('after line') | ||
.prependLinesWith('grey', '> '); | ||
expect(pen.toString(), 'to equal', | ||
'> Line\n' + | ||
'> after line\n' + | ||
'> after line'); | ||
``` | ||
### size() | ||
@@ -308,0 +328,0 @@ |
@@ -109,2 +109,9 @@ /*global describe, it, beforeEach*/ | ||
}); | ||
it('can be called with style arguments', function () { | ||
pen.red('Hello').block('text', ' // This is a\n // multiline comment'); | ||
expect(pen.toString(), 'to equal', | ||
'Hello // This is a\n' + | ||
' // multiline comment'); | ||
}); | ||
}); | ||
@@ -128,2 +135,8 @@ | ||
}); | ||
it('can be called with style arguments', function () { | ||
pen.text('Hello').sp().append('red', 'world!'); | ||
expect(pen.toString(), 'to equal', | ||
'Hello world!'); | ||
}); | ||
}); | ||
@@ -159,2 +172,25 @@ | ||
}); | ||
it('can be called with style arguments', function () { | ||
pen.text('First line').nl() | ||
.text('Second line').nl() | ||
.indentLines() | ||
.indent().text('Third line') | ||
.prependLinesWith('gray', ' // '); | ||
expect(pen.toString(), 'to equal', | ||
' // First line\n' + | ||
' // Second line\n' + | ||
' // Third line'); | ||
}); | ||
it.skip('works with blocks', function () { | ||
pen.block(function () { | ||
this.text('Hello\nworld'); | ||
}).prependLinesWith(function () { | ||
this.text('> '); | ||
}); | ||
expect(pen.toString(), 'to equal', '> Hello\n> world'); | ||
}); | ||
}); | ||
@@ -161,0 +197,0 @@ |
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
448686
2231
485