Comparing version 0.1.0 to 0.2.0
@@ -6,2 +6,4 @@ var esprima = require('esprima'); | ||
var transforms = []; | ||
var parse = function(contents, cb) { | ||
@@ -44,3 +46,8 @@ if (arguments.length == 2 && !(typeof cb === 'function')) { | ||
}; | ||
if (typeof cb != 'undefined') { | ||
for (var i = 0; i < transforms.length; ++i) { | ||
transforms[i](block); | ||
} | ||
if (typeof cb !== 'undefined') { | ||
cb(block); | ||
@@ -82,2 +89,8 @@ } | ||
parse: parse, | ||
removeAllTransforms: function() { | ||
transforms = []; | ||
}, | ||
transform: function(callback) { | ||
transforms.push(callback); | ||
}, | ||
trimEachLine: function(str) { | ||
@@ -84,0 +97,0 @@ var lines = str.split('\n'); |
{ | ||
"name": "acquit", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Parse BDD-style tests (Mocha, Jasmine) to generate documentation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,3 +17,3 @@ # acquit | ||
```javascript | ||
var contents = | ||
@@ -55,18 +55,22 @@ '/**\n' + | ||
assert.equal(0, ret[0].blocks[1].comments.length); | ||
``` | ||
#### Acquit can also take a callback as second parameter | ||
#### It can call user function on `code` block and save return value | ||
Acquit can also take a callback as second parameter. This callback gets | ||
executed on every block and can transform the block however you want. | ||
```javascript | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var cb = function(block) { | ||
block.code = 'return value from callback'; | ||
block.code = 'return value from callback'; | ||
}; | ||
@@ -77,4 +81,37 @@ | ||
assert.equal('return value from callback', ret[0].blocks[0].code); | ||
``` | ||
#### It can define transforms | ||
Want to chain multiple callbacks together and/or develop re-usable | ||
plugins? `acquit.transform()` allows you to add transformations that | ||
are executed each time you call `.parse()`. | ||
Transform functions are executed in order **before** the callback | ||
function passed to `.parse()`. | ||
```javascript | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var cb = function(block) { | ||
block.code = 'my transformed code'; | ||
}; | ||
acquit.transform(cb); | ||
var ret = acquit.parse(contents); | ||
assert.equal('my transformed code', ret[0].blocks[0].code); | ||
acquit.removeAllTransforms(); | ||
``` | ||
#### It can parse the ES6 `yield` keyword | ||
@@ -85,3 +122,3 @@ | ||
```javascript | ||
var contents = | ||
@@ -106,3 +143,3 @@ 'describe(\'ES6\', function() {\n' + | ||
assert.ok(ret[0].blocks[0].code); | ||
``` | ||
@@ -118,3 +155,3 @@ | ||
```javascript | ||
var str = ' * This comment looks like a \n' + | ||
@@ -125,3 +162,3 @@ ' * parsed JSdoc-style comment'; | ||
'parsed JSdoc-style comment'); | ||
``` | ||
@@ -135,3 +172,3 @@ | ||
```javascript | ||
var str = 'This comment looks like a \n' + | ||
@@ -142,3 +179,4 @@ ' * parsed JSdoc-style comment'; | ||
'parsed JSdoc-style comment'); | ||
``` | ||
``` |
@@ -51,3 +51,4 @@ var assert = require('assert'); | ||
/** | ||
* Acquit can also take a callback as second parameter | ||
* Acquit can also take a callback as second parameter. This callback gets | ||
* executed on every block and can transform the block however you want. | ||
*/ | ||
@@ -73,2 +74,31 @@ it('can call user function on `code` block and save return value', function() { | ||
/** | ||
* Want to chain multiple callbacks together and/or develop re-usable | ||
* plugins? `acquit.transform()` allows you to add transformations that | ||
* are executed each time you call `.parse()`. | ||
* | ||
* Transform functions are executed in order **before** the callback | ||
* function passed to `.parse()`. | ||
*/ | ||
it('can define transforms', function() { | ||
var contents = | ||
'describe(\'ES6\', function() {\n' + | ||
' // ES6 has a `yield` keyword\n' + | ||
' it(\'should be able to yield\', function() {\n' + | ||
' // some code\n' + | ||
' });\n' + | ||
'});'; | ||
var cb = function(block) { | ||
block.code = 'my transformed code'; | ||
}; | ||
acquit.transform(cb); | ||
var ret = acquit.parse(contents); | ||
assert.equal('my transformed code', ret[0].blocks[0].code); | ||
acquit.removeAllTransforms(); | ||
}); | ||
/** | ||
* Acquit can also parse ES6 code | ||
@@ -75,0 +105,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
26843
11
249
174