parse and display inherited events

This commit is contained in:
rolux 2012-06-02 14:10:59 +02:00
parent ea08852676
commit e348acee86
2 changed files with 58 additions and 37 deletions

View file

@ -94,17 +94,25 @@ Ox.DocPage = function(options, self) {
sections = ['description'].concat(
item.order || ['returns', 'arguments', 'properties']
).concat(['events', 'tests', 'source']),
index = sections.indexOf('properties') + 1 || 1;
if (item.inherited) {
Array.prototype.splice.apply(sections, [index, 0].concat(
item.inherited.map(function(v, i) {
var section = 'Properties inherited from <code>'
index = {
events: sections.indexOf('events') + 1 + (
item.inheritedproperties ? item.inheritedproperties.length : 0
),
properties: sections.indexOf('properties') + 1 || 1
};
['properties', 'events'].forEach(function(key) {
var key_ = 'inherited' + key;
if (item[key_]) {
Array.prototype.splice.apply(sections, [index[key], 0].concat(
item[key_].map(function(v, i) {
var section = key + ' inherited from <code>'
+ v.name + '</code>';
item[section] = v.properties;
item[section] = v[key];
return section;
})
));
}
});
sections.forEach(function(section) {
var className = 'OxLine' + Ox.uid();
if (item[section]) {
@ -163,7 +171,8 @@ Ox.DocPage = function(options, self) {
})
)
.append('<span class="OxSection">' + (
Ox.startsWith(section, 'Properties') ? section
Ox.contains(section, 'inherited')
? section[0].toUpperCase() + section.slice(1)
: Ox.toTitleCase(
section == 'returns' ? 'usage'
: section == 'tests' ? 'examples'

View file

@ -19,7 +19,10 @@ Ox.doc <f> Generates documentation for annotated JavaScript
events <[o]|u> Events (array of doc objects)
Present if the item fires any events
file <s> File name
inherited <[o]|u> Inherited properties (array of doc objects)
inheritedevents <[o]|u> Inherited events (array of doc objects)
Present if the item has a class, and any item in its inheritance
chain fires events
inheritedproperties <[o]|u> Inherited properties (array of doc objects)
Present if the item has a class, and any item in its inheritance
chain has (unshadowed) properties
line <n> Line number
@ -39,7 +42,7 @@ Ox.doc <f> Generates documentation for annotated JavaScript
Present if the `type` of the item is `"function"`.
summary <s> One-line summary, with some Markdown
See Ox.parseMarkdown for details
tests <[o]> Tests (array of test objects)
tests <[o]|u> Tests (array of test objects)
expected <s> Expected result
statement <s> Statement
types <[s]> Types of the item
@ -97,12 +100,17 @@ Ox.doc = (function() {
var constructors = getConstructors(items), instances = {}, nodes = {};
function hasProperty(item, property) {
var properties = item.properties || [],
inherited = item.inherited ? item.inherited.map(function(v) {
inheritedproperties = item.inheritedproperties
? item.inheritedproperties.map(function(v) {
return v.properties;
}) : [];
return Ox.contains(properties.concat(inherited).map(function(property) {
})
: [];
return Ox.contains(
properties.concat(inheritedproperties).map(function(property) {
return property.name;
}), property.name);
}),
property.name
);
}
var foo = {};
constructors.forEach(function(constructor) {
@ -117,18 +125,23 @@ Ox.doc = (function() {
|| Ox.last(items[Ox.indexOf(items, function(item) {
return item.name == parentName;
})].returns);
parent && parent.properties && parent.properties.forEach(function(property) {
if (!hasProperty(child, property)) {
if (!child.inherited) {
child.inherited = [];
['properties', 'events'].forEach(function(key) {
parent[key] && parent[key].forEach(function(value) {
var key_ = 'inherited' + key;
if (key == 'events' || !hasProperty(child, value)) {
if (!child[key_]) {
child[key_] = [];
}
if (!child.inherited.some(function(v) {
if (!child[key_].some(function(v) {
return v.name == parentName;
})) {
child.inherited.push({name: parentName, properties: []});
child[key_].push(
Ox.extend({name: parentName}, key, [])
);
}
Ox.last(child.inherited).properties.push(property);
Ox.last(child[key_])[key].push(value);
}
})
});
});
});
@ -225,7 +238,6 @@ Ox.doc = (function() {
item.tests = item.tests || [];
item.tests.push(parseTest(line));
} else if ((subitem = parseItem(line))) {
item.name == 'Ox.getset' && Ox.print(line, subitem)
if (subitem.signature) {
item.returns = item.returns || [];
item.returns.push(parseNode(node));