fix(ngdoc): extract keywords from properties/methods.

This commit is contained in:
Misko Hevery 2012-02-13 21:59:10 -08:00
parent 292a5dae07
commit 22c1db1744
2 changed files with 28 additions and 10 deletions

View file

@ -23,6 +23,13 @@ describe('ngdoc', function() {
expect(new Doc('The `ng:class-odd` and').keywords()).toEqual('and ng:class-odd the');
});
it('should get property and methods', function() {
var doc = new Doc('Document');
doc.properties.push(new Doc('Proprety'));
doc.properties.push(new Doc('Method'));
expect(doc.keywords()).toEqual('document method proprety');
});
it('should have shortName', function() {
var d1 = new Doc('@name a.b.c').parse();
var d2 = new Doc('@name a.b.ng:c').parse();

View file

@ -46,18 +46,29 @@ Doc.METADATA_IGNORE = (function() {
Doc.prototype = {
keywords: function keywords() {
var keywords = {};
Doc.METADATA_IGNORE.forEach(function(ignore){ keywords[ignore] = true; });
var words = [];
var tokens = this.text.toLowerCase().split(/[,\.\`\'\"\s]+/mg);
tokens.forEach(function(key){
var match = key.match(/^(([\$\_a-z]|ng\:)[\w\_\-]{2,})/);
if (match){
key = match[1];
if (!keywords[key]) {
keywords[key] = true;
words.push(key);
Doc.METADATA_IGNORE.forEach(function(ignore){ keywords[ignore] = true; });
function extractWords(text) {
var tokens = text.toLowerCase().split(/[,\.\`\'\"\s]+/mg);
tokens.forEach(function(key){
var match = key.match(/^(([\$\_a-z]|ng\:)[\w\_\-]{2,})/);
if (match){
key = match[1];
if (!keywords[key]) {
keywords[key] = true;
words.push(key);
}
}
}
});
}
extractWords(this.text);
this.properties.forEach(function(prop) {
extractWords(prop.text || prop.description || '');
});
this.methods.forEach(function(method) {
extractWords(method.text || method.description || '');
});
words.sort();
return words.join(' ');