mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-25 06:13:44 +00:00
fix(ngdoc): extract keywords from properties/methods.
This commit is contained in:
parent
292a5dae07
commit
22c1db1744
2 changed files with 28 additions and 10 deletions
|
|
@ -23,6 +23,13 @@ describe('ngdoc', function() {
|
||||||
expect(new Doc('The `ng:class-odd` and').keywords()).toEqual('and ng:class-odd the');
|
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() {
|
it('should have shortName', function() {
|
||||||
var d1 = new Doc('@name a.b.c').parse();
|
var d1 = new Doc('@name a.b.c').parse();
|
||||||
var d2 = new Doc('@name a.b.ng:c').parse();
|
var d2 = new Doc('@name a.b.ng:c').parse();
|
||||||
|
|
|
||||||
|
|
@ -46,18 +46,29 @@ Doc.METADATA_IGNORE = (function() {
|
||||||
Doc.prototype = {
|
Doc.prototype = {
|
||||||
keywords: function keywords() {
|
keywords: function keywords() {
|
||||||
var keywords = {};
|
var keywords = {};
|
||||||
Doc.METADATA_IGNORE.forEach(function(ignore){ keywords[ignore] = true; });
|
|
||||||
var words = [];
|
var words = [];
|
||||||
var tokens = this.text.toLowerCase().split(/[,\.\`\'\"\s]+/mg);
|
Doc.METADATA_IGNORE.forEach(function(ignore){ keywords[ignore] = true; });
|
||||||
tokens.forEach(function(key){
|
|
||||||
var match = key.match(/^(([\$\_a-z]|ng\:)[\w\_\-]{2,})/);
|
function extractWords(text) {
|
||||||
if (match){
|
var tokens = text.toLowerCase().split(/[,\.\`\'\"\s]+/mg);
|
||||||
key = match[1];
|
tokens.forEach(function(key){
|
||||||
if (!keywords[key]) {
|
var match = key.match(/^(([\$\_a-z]|ng\:)[\w\_\-]{2,})/);
|
||||||
keywords[key] = true;
|
if (match){
|
||||||
words.push(key);
|
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();
|
words.sort();
|
||||||
return words.join(' ');
|
return words.join(' ');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue