cdocparser
Advanced tools
Comparing version 0.4.0-rc1 to 0.4.0-rc2
44
index.js
@@ -125,4 +125,10 @@ 'use strict'; | ||
var shouldAutofill = function(name, comment){ | ||
return !comment.allowExtend || comment.allowExtend[0].indexOf(name) > -1; | ||
var shouldAutofill = function(name, config){ | ||
if (config.autofill === undefined || config.autofill === true ){ | ||
return true; | ||
} | ||
if (Array.isArray(config.autofill)){ | ||
return config.autofill.indexOf(name) !== -1; | ||
} | ||
return false; | ||
}; | ||
@@ -137,11 +143,6 @@ | ||
function CommentParser (annotations) { | ||
function CommentParser (annotations, config) { | ||
EventEmitter.call(this); | ||
this.annotations = annotations; | ||
// Always add the autofill annotation | ||
this.annotations.autofill = { | ||
parse : function(text){ | ||
return text.split(' '); | ||
} | ||
}; | ||
this.config = config || {}; | ||
} | ||
@@ -151,3 +152,3 @@ | ||
var parseComment = function (comment, annotations, emitter, posterComment) { | ||
var parseComment = function (comment, annotations, posterComment) { | ||
var parsedComment = { | ||
@@ -182,3 +183,3 @@ description: '', | ||
} else { | ||
emitter.emit( | ||
this.emit( | ||
'warning', | ||
@@ -190,3 +191,3 @@ new Error('Annotation "' + name + '" is not allowed on comment from type "' + comment.context.type + '"') | ||
} else { | ||
emitter.emit('warning', new Error('Parser for annotation `' + match[1] + '` not found.')); | ||
this.emit('warning', new Error('Parser for annotation `' + match[1] + '` not found.')); | ||
} | ||
@@ -198,3 +199,3 @@ } | ||
} | ||
}); | ||
}, this); | ||
@@ -209,3 +210,3 @@ | ||
} else { | ||
emitter.emit('warning', new Error('You can\'t have more than one poster comment.')); | ||
this.emit('warning', new Error('You can\'t have more than one poster comment.')); | ||
} | ||
@@ -228,3 +229,3 @@ // Don't add poster comments to the output | ||
var defaultFunc = annotations[name].default; | ||
var extendFunc = annotations[name].extend; | ||
var autofillFunc = annotations[name].autofill; | ||
if ( isAnnotationAllowed(comment, annotations[name]) ) { | ||
@@ -240,6 +241,6 @@ | ||
if (extendFunc && shouldAutofill(name, parsedComment)) { | ||
var extendedValue = extendFunc(parsedComment); | ||
if (extendedValue !== undefined) { | ||
parsedComment[name] = extendedValue; | ||
if (autofillFunc && shouldAutofill(name, this.config)) { | ||
var autofillValue = autofillFunc(parsedComment); | ||
if (autofillValue !== undefined) { | ||
parsedComment[name] = autofillValue; | ||
} | ||
@@ -249,3 +250,3 @@ } | ||
} | ||
}); | ||
}, this); | ||
@@ -262,5 +263,6 @@ return parsedComment; | ||
var posterComment = {}; | ||
var thisParseComment = parseComment.bind(this); | ||
comments.forEach(function (comment) { | ||
var parsedComment = parseComment(comment, this.annotations, this, posterComment); | ||
var parsedComment = thisParseComment(comment, this.annotations, posterComment); | ||
if (parsedComment !== null){ | ||
@@ -267,0 +269,0 @@ var type = comment.context.type; |
{ | ||
"name": "cdocparser", | ||
"version": "0.4.0-rc1", | ||
"version": "0.4.0-rc2", | ||
"description": "Extract C style comments and extract context from source", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -74,3 +74,3 @@ CDocParser | ||
#### `new CommentParser(annotations)` | ||
#### `new CommentParser(annotations, config)` | ||
@@ -211,3 +211,2 @@ Create a new `CommentParser` where `annotaions` is an object like: | ||
* Remove the array wrapping of `default` values. | ||
* Always have a `@allowExtend` annotation that is used to enable extending on a per annotation feature | ||
@@ -214,0 +213,0 @@ #### 0.3.8 |
@@ -236,23 +236,23 @@ var fs = require('fs'); | ||
describe('# Default and extended values', function(){ | ||
beforeEach(function(){ | ||
parser = new docParser.CommentParser({ | ||
_ : { | ||
alias : {}, | ||
var annotations = { | ||
_ : { | ||
alias : {}, | ||
}, | ||
test : { | ||
parse : function(line){ | ||
return line; | ||
}, | ||
test : { | ||
parse : function(line){ | ||
return line; | ||
}, | ||
default : function(parsedComment){ | ||
return ['default']; | ||
}, | ||
extend : function(parsedComment){ | ||
parsedComment.test.push('extended'); | ||
} | ||
default : function(parsedComment){ | ||
return ['default']; | ||
}, | ||
autofill : function(parsedComment){ | ||
parsedComment.test.push('extended'); | ||
} | ||
}); | ||
}); | ||
} | ||
}; | ||
it('should extend correctly', function(){ | ||
parser = new docParser.CommentParser(annotations); | ||
var extendedResult = parser.parse ([{ | ||
@@ -275,16 +275,39 @@ lines : ['@test hello'], | ||
it('should respsect @autofill', function(){ | ||
var autofillResult = parser.parse ([{ | ||
lines : ['@autofill none', 'Just a description'], | ||
it('should respect the config', function(){ | ||
parser = new docParser.CommentParser(annotations, { | ||
autofill : true | ||
}); | ||
var extendedResult = parser.parse ([{ | ||
lines : ['@test hello'], | ||
context : { type : 'demo' } | ||
}]); | ||
assert.deepEqual(autofillResult.demo[0].test, ['default']); | ||
assert.deepEqual(extendedResult.demo[0].test, ['hello', 'extended']); | ||
var autofillTestResult = parser.parse ([{ | ||
lines : ['@autofill test', 'Just a description'], | ||
parser = new docParser.CommentParser(annotations, { | ||
autofill : false | ||
}); | ||
var defaultResult = parser.parse ([{ | ||
lines : ['Just a description'], | ||
context : { type : 'demo' } | ||
}]); | ||
assert.deepEqual(autofillTestResult.demo[0].test, ['default', 'extended']); | ||
assert.deepEqual(defaultResult.demo[0].test, ['default']); | ||
parser = new docParser.CommentParser(annotations, { | ||
autofill : ['test'] | ||
}); | ||
var defaultTestResult = parser.parse ([{ | ||
lines : ['Just a description'], | ||
context : { type : 'demo' } | ||
}]); | ||
assert.deepEqual(defaultTestResult.demo[0].test, ['default', 'extended']); | ||
}); | ||
@@ -291,0 +314,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
25135
479
262