parse and display inherited events
This commit is contained in:
parent
ea08852676
commit
e348acee86
2 changed files with 58 additions and 37 deletions
|
@ -94,17 +94,25 @@ Ox.DocPage = function(options, self) {
|
||||||
sections = ['description'].concat(
|
sections = ['description'].concat(
|
||||||
item.order || ['returns', 'arguments', 'properties']
|
item.order || ['returns', 'arguments', 'properties']
|
||||||
).concat(['events', 'tests', 'source']),
|
).concat(['events', 'tests', 'source']),
|
||||||
index = sections.indexOf('properties') + 1 || 1;
|
index = {
|
||||||
if (item.inherited) {
|
events: sections.indexOf('events') + 1 + (
|
||||||
Array.prototype.splice.apply(sections, [index, 0].concat(
|
item.inheritedproperties ? item.inheritedproperties.length : 0
|
||||||
item.inherited.map(function(v, i) {
|
),
|
||||||
var section = 'Properties inherited from <code>'
|
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>';
|
+ v.name + '</code>';
|
||||||
item[section] = v.properties;
|
item[section] = v[key];
|
||||||
return section;
|
return section;
|
||||||
})
|
})
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
sections.forEach(function(section) {
|
sections.forEach(function(section) {
|
||||||
var className = 'OxLine' + Ox.uid();
|
var className = 'OxLine' + Ox.uid();
|
||||||
if (item[section]) {
|
if (item[section]) {
|
||||||
|
@ -163,7 +171,8 @@ Ox.DocPage = function(options, self) {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.append('<span class="OxSection">' + (
|
.append('<span class="OxSection">' + (
|
||||||
Ox.startsWith(section, 'Properties') ? section
|
Ox.contains(section, 'inherited')
|
||||||
|
? section[0].toUpperCase() + section.slice(1)
|
||||||
: Ox.toTitleCase(
|
: Ox.toTitleCase(
|
||||||
section == 'returns' ? 'usage'
|
section == 'returns' ? 'usage'
|
||||||
: section == 'tests' ? 'examples'
|
: section == 'tests' ? 'examples'
|
||||||
|
|
|
@ -19,7 +19,10 @@ Ox.doc <f> Generates documentation for annotated JavaScript
|
||||||
events <[o]|u> Events (array of doc objects)
|
events <[o]|u> Events (array of doc objects)
|
||||||
Present if the item fires any events
|
Present if the item fires any events
|
||||||
file <s> File name
|
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
|
Present if the item has a class, and any item in its inheritance
|
||||||
chain has (unshadowed) properties
|
chain has (unshadowed) properties
|
||||||
line <n> Line number
|
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"`.
|
Present if the `type` of the item is `"function"`.
|
||||||
summary <s> One-line summary, with some Markdown
|
summary <s> One-line summary, with some Markdown
|
||||||
See Ox.parseMarkdown for details
|
See Ox.parseMarkdown for details
|
||||||
tests <[o]> Tests (array of test objects)
|
tests <[o]|u> Tests (array of test objects)
|
||||||
expected <s> Expected result
|
expected <s> Expected result
|
||||||
statement <s> Statement
|
statement <s> Statement
|
||||||
types <[s]> Types of the item
|
types <[s]> Types of the item
|
||||||
|
@ -97,12 +100,17 @@ Ox.doc = (function() {
|
||||||
var constructors = getConstructors(items), instances = {}, nodes = {};
|
var constructors = getConstructors(items), instances = {}, nodes = {};
|
||||||
function hasProperty(item, property) {
|
function hasProperty(item, property) {
|
||||||
var properties = item.properties || [],
|
var properties = item.properties || [],
|
||||||
inherited = item.inherited ? item.inherited.map(function(v) {
|
inheritedproperties = item.inheritedproperties
|
||||||
|
? item.inheritedproperties.map(function(v) {
|
||||||
return v.properties;
|
return v.properties;
|
||||||
}) : [];
|
})
|
||||||
return Ox.contains(properties.concat(inherited).map(function(property) {
|
: [];
|
||||||
|
return Ox.contains(
|
||||||
|
properties.concat(inheritedproperties).map(function(property) {
|
||||||
return property.name;
|
return property.name;
|
||||||
}), property.name);
|
}),
|
||||||
|
property.name
|
||||||
|
);
|
||||||
}
|
}
|
||||||
var foo = {};
|
var foo = {};
|
||||||
constructors.forEach(function(constructor) {
|
constructors.forEach(function(constructor) {
|
||||||
|
@ -117,18 +125,23 @@ Ox.doc = (function() {
|
||||||
|| Ox.last(items[Ox.indexOf(items, function(item) {
|
|| Ox.last(items[Ox.indexOf(items, function(item) {
|
||||||
return item.name == parentName;
|
return item.name == parentName;
|
||||||
})].returns);
|
})].returns);
|
||||||
parent && parent.properties && parent.properties.forEach(function(property) {
|
['properties', 'events'].forEach(function(key) {
|
||||||
if (!hasProperty(child, property)) {
|
parent[key] && parent[key].forEach(function(value) {
|
||||||
if (!child.inherited) {
|
var key_ = 'inherited' + key;
|
||||||
child.inherited = [];
|
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;
|
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 = item.tests || [];
|
||||||
item.tests.push(parseTest(line));
|
item.tests.push(parseTest(line));
|
||||||
} else if ((subitem = parseItem(line))) {
|
} else if ((subitem = parseItem(line))) {
|
||||||
item.name == 'Ox.getset' && Ox.print(line, subitem)
|
|
||||||
if (subitem.signature) {
|
if (subitem.signature) {
|
||||||
item.returns = item.returns || [];
|
item.returns = item.returns || [];
|
||||||
item.returns.push(parseNode(node));
|
item.returns.push(parseNode(node));
|
||||||
|
|
Loading…
Reference in a new issue