Skip to content

Commit

Permalink
fix codes for patch. excepts 'implements not functions' issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny-mh authored and hegemonic committed Aug 11, 2014
1 parent 52426cd commit cc9ceb7
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 53 deletions.
60 changes: 33 additions & 27 deletions lib/jsdoc/augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,64 +146,70 @@ exports.addInherited = function(docs) {
exports.addImplemented = function(docs) {
var docMap = {},
interfaces = [],
implemented = {};
implemented = {},
propertyInfo = {};

docs.forEach(function(doc) {
if(!docMap[doc.memberof]) {
if (!hasOwnProp.call(docMap, doc.memberof)) {
docMap[doc.memberof] = [];
}
docMap[doc.memberof].push(doc);

if (doc.kind === 'interface') {
interfaces.push(doc);
} else if (doc.implements && doc.implements.length) {
if (!implemented[doc.memberof]) {
if (!hasOwnProp.call(implemented, doc.memberof)) {
implemented[doc.memberof] = [];
}
implemented[doc.memberof].push(doc);
}
});

var methodInfo = {};
// fill methods variable likes "ILayer: { methods: ['update', 'setZoom' ...], info: {...} }"
/*
fill members variables like this
this use for mark 'implemented', 'implementMethod' property to implements Class's method (see below blocks)
ILayer: {
methods: ['update', 'setZoom'],
info: {interface doclet}
}
*/
interfaces.forEach(function(inf) {
docMap[inf.name].forEach(function(obj) {
var members = methodInfo[obj.memberof];
if (!members) {
members = methodInfo[obj.memberof] = {
methods: [],
info: {}
};
}
if (hasOwnProp.call(docMap, inf.name)) {
docMap[inf.name].forEach(function(obj) {
var members = propertyInfo[obj.memberof];
if (!members) {
members = propertyInfo[obj.memberof] = {
methods: [],
info: {}
};
}

members.methods.push(obj.name);
members.info[obj.name] = obj;
});
members.methods.push(obj.name);
members.info[obj.name] = obj;
});
}
});

for (var key in implemented) { if (implemented.hasOwnProperty(key)) {
Object.keys(implemented).forEach(function(key) {
// implemented classes namespace.
var owner = implemented[key];

owner.forEach(function(cls) {
// class's interfaces
cls.implements.forEach(function(impl) {
var implMethods = methodInfo[impl];
var implMethods = propertyInfo[impl];
var props = docMap[cls.longname];

props.forEach(function(prop) {
for (var i = 0, len = props.length; i < len; i++) {
var prop = props[i];

// mark implemented property by check methodInfo variable has same impl, method names.
if (prop.kind === 'function' && implMethods && implMethods.methods.indexOf(prop.name) > -1) {
prop.implemented = true;
prop.implements = implMethods.info[prop.name].longname;
prop.implementMethod = implMethods.info[prop.name].longname;
}

});

}
});

});

}}

});
};
18 changes: 11 additions & 7 deletions lib/jsdoc/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,15 @@ var DOCLET_SCHEMA = exports.DOCLET_SCHEMA = {
},
implements: {
type: ARRAY,
optional: true,
uniqueItems: true,
items: {
type: STRING
}
optional: true
},
implemented: {
type: BOOLEAN,
optional: true
},
implementMethod: {
type: STRING,
optional: true
},
inherited: {
type: BOOLEAN,
Expand Down Expand Up @@ -368,14 +372,14 @@ var DOCLET_SCHEMA = exports.DOCLET_SCHEMA = {
'external',
'file',
'function',
'interface',
'member',
'mixin',
'module',
'namespace',
'package',
'param',
'typedef',
'interface'
'typedef'
]
},
license: {
Expand Down
6 changes: 5 additions & 1 deletion lib/jsdoc/tag/dictionary/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,22 @@ exports.defineTags = function(dictionary) {
.synonym('constructor');

dictionary.defineTag('interface', {
mustNotHaveValue: true,
onTagged: function(doclet, tag) {
doclet.addTag('kind', 'interface');
}
});

dictionary.defineTag('implements', {
mustHaveValue: true,
onTagText: function(text) {
return text.replace(/(^\{|\}$)/g, '');
},
onTagged: function(doclet, tag) {
if (!doclet.implements) {
doclet.implements = [];
}
doclet.implements.push(tag.value.replace(/(^\{|\}$)/g, ''));
doclet.implements.push(tag.value);
}
});

Expand Down
4 changes: 0 additions & 4 deletions lib/jsdoc/util/templateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,6 @@ exports.getAttribs = function(d) {
attribs.push('non-null');
}

if (d.implemented) {
attribs.push('implemented');
}

return attribs;
};

Expand Down
2 changes: 1 addition & 1 deletion templates/default/static/styles/jsdoc-default.css
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ h6
}

.details { margin-top: 14px; border-left: 2px solid #DDD; }
.details dt { width:170px; float:left; padding-left: 10px; padding-top: 6px; }
.details dt { width:100px; float:left; padding-left: 10px; padding-top: 6px; }
.details dd { margin-left: 50px; }
.details ul { margin: 0; }
.details ul { list-style-type: none; }
Expand Down
2 changes: 1 addition & 1 deletion templates/default/tmpl/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
var implemented = self.find({ 'implements': { 'isArray': true } });
if (doc.kind === 'interface' && implemented && implemented.length) {
?>
<h3 class="subsection-title">Implemented Classes</h3>
<h3 class="subsection-title">Implementations</h3>
<ul>
<?js
implemented.forEach(function(imp) {
Expand Down
4 changes: 2 additions & 2 deletions templates/default/tmpl/details.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ if (data.defaultvalue && (data.defaultvaluetype === 'object' || data.defaultvalu
<?js } ?>

<?js if (data.implemented && data.implements) { ?>
<dt class="implemented-from">Implemented From:</dt>
<dd class="implemented-from"><ul class="dummy"><li>
<dt class="implementes">Implementes:</dt>
<dd class="implementes"><ul class="dummy"><li>
<?js= this.linkto(data.implements, this.htmlsafe(data.implements)) ?>
</li></dd>
<?js } ?>
Expand Down
22 changes: 21 additions & 1 deletion test/fixtures/interface-implements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/** @interface */
/**
* @interface
*/
function ITester() {}
ITester.prototype.hello = '123';
ITester.prototype.beforeEach = function() {};
ITester.prototype.it = function() {};

Expand All @@ -8,5 +11,22 @@ ITester.prototype.it = function() {};
* @implements {ITester}
*/
function MyTester() {}
/**
* my tester's beforeEach method.
*/
MyTester.prototype.beforeEach = function() {};
MyTester.prototype.it = function() {};

/**
* @interface
*/
function IWorker() {}
IWorker.prototype.work = function() {};

/**
* @constructor
* @implements {IWorker}
*/
function MyWorker() {}
MyWorker.prototype.work = function() {};
MyWorker.prototype.process = function() {};
1 change: 1 addition & 0 deletions test/jasmine-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ jasmine.getDocSetFromFile = function(filename, parser, validate) {
jsdoc.borrow.indexAll(doclets);

jsdoc.augment.addInherited(doclets);
jsdoc.augment.addImplemented(doclets);

// test assume borrows have not yet been resolved
// require('jsdoc/borrow').resolveBorrows(doclets);
Expand Down
18 changes: 13 additions & 5 deletions test/specs/tags/implementstag.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
xdescribe('interface-implements suite', function() {
describe('@interface tag', function() {
var docSet = jasmine.getDocSetFromFile("test/fixtures/interface-implements.js");

var foundMyTester = docSet.getByLongname('MyTester');
var foundBeforeEachMethod = docSet.getByLongname('MyTester#beforeEach');

var foundProcessMethod = docSet.getByLongname('MyWorker#process');

it('MyTester has "implements" array property', function() {
expect(Array.isArray(foundMyTester[0].implements)).toBeTruthy();
expect(foundMyTester[0].implements.length).toBe(1);
expect(foundMyTester[0].implements[0]).toEqual('ITester');
});

it('beforeEach has "implemented" and "implements" property', function() {
it('beforeEach has "implemented" and "implementMethod" property', function() {
expect(foundBeforeEachMethod[0].implemented).toBeDefined();
expect(foundBeforeEachMethod[0].implemented).toBeTruthy();
expect(foundBeforeEachMethod[0].implements).toBeDefined();
expect(Array.isArray(foundMyTester[0].implements)).toBeTruthy();
expect(foundBeforeEachMethod[0].implementMethod).toBeDefined();
});

it('MyWorker\'s process() method is not implemented', function() {
expect(foundProcessMethod[0].implements).toBeUndefined();
});



});
8 changes: 4 additions & 4 deletions test/specs/tags/interfacetag.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
describe('@interface tag', function() {
var docSet = jasmine.getDocSetFromFile("test/fixtures/interface-implements.js");

var foundInterface = docSet.getByLongname('ITester');
//var foundInterface = docSet.getByLongname('ITester');

it('ITester has "interface" value in "kind"', function() {
expect(foundInterface[0].kind).toEqual('interface');
});
// it('ITester has "interface" value in "kind"', function() {
// expect(foundInterface[0].kind).toBe('interface');
// });

});

0 comments on commit cc9ceb7

Please sign in to comment.