cleanup api docs

This commit is contained in:
j 2010-12-06 19:23:04 +01:00
parent ce4fe60fc6
commit ec6f3dad9d
2 changed files with 104 additions and 85 deletions

View file

@ -276,7 +276,7 @@ requires
}();
/**
Creates an Ox.Event
Ox.Event event object
*/
Ox.Event = function() {
var $eventHandler = $('<div>'),
@ -632,7 +632,7 @@ requires
*/
/**
Ox.Request
Ox.Request request object
*/
Ox.Request = function() {
@ -3298,6 +3298,18 @@ requires
};
/**
options:
format: 'short'
value: date value
weekday: false
width: {
day: 32,
month: options.format == 'long' ? 80 : (options.format == 'medium' ? 40 : 32),
weekday: options.format == 'long' ? 80 : 40,
year: 48
}
*/
Ox.DateInput = function(options, self) {
var self = $.extend(self || {}, {

View file

@ -7,7 +7,9 @@ $(function() {
app.$document = $(document);
app.$window = $(window);
app.$ui = {};
app.docstrings = {};
$("<div>").load('../build/js/ox.ui.js', function(data) {
app.source = data;
var docstrings = app.source.match(/\/\*\*\n([\s\S]+?\*\/\n.*?)\n/gm)
@ -26,11 +28,10 @@ $(function() {
app.docstrings[name[1]] = Ox.trim(doc.join('\n'));
}
})
app.$ui = {};
});
app.docs = getDocsJSON();
app.$ui.actionList = constructList();
app.$ui.actionInfo = Ox.Container().css({padding: '8px'});
app.$ui.actionInfo = Ox.Container().css({padding: '8px'}).html('select action on the left.');
var $main = new Ox.SplitPanel({
elements: [
@ -46,7 +47,6 @@ $(function() {
});
$main.appendTo(app.$body);
});
});
function constructList() {
@ -69,12 +69,7 @@ function constructList() {
var items = [];
app.docs.forEach(function(v) {
items.push(v.name);
});
Ox.keys(app.docstrings).forEach(function(v) {
if(!$.inArray(v.name, items)) {
items.push(v.name);
}
});
});
items = Ox.map(items, function(i) { return {name: i}});
items.sort(function(a, b) { if(a.name < b.name) { return -1 } else if( a.name == b.name) { return 0 }else { return 1 } })
if(!data.keys) {
@ -117,26 +112,28 @@ function getDocHtml(doc) {
if(app.docstrings[doc.name])
$('<pre>').html(app.docstrings[doc.name]).appendTo($div);
var $options = $('<div>').html("Options: ")
.css({'marginBottom': '20px'})
.appendTo($div);
var $table = $('<table>').attr({'cellpadding': '4'})
.appendTo($options);
Ox.keys(doc.options).forEach(function(k) {
var $option = $('<tr>');
cell(k).appendTo($option);
if(typeof(doc.options[k]) != 'undefined') {
cell(typeof doc.options[k]).appendTo($option);
if(Ox.isNull(doc.options[k]))
cell(' <b>null</b>').appendTo($option);
else
cell(' <b>' + doc.options[k].toString() + '</b>').appendTo($option);
} else {
cell('&nbsp;').appendTo($option);
cell('<b>required, no default value</b>').appendTo($option);
}
$option.appendTo($options);
});
if(doc.options) {
var $options = $('<div>').html("Options: ")
.css({'marginBottom': '20px'})
.appendTo($div);
var $table = $('<table>').attr({'cellpadding': '4'})
.appendTo($options);
Ox.keys(doc.options).forEach(function(k) {
var $option = $('<tr>');
cell(k).appendTo($option);
if(typeof(doc.options[k]) != 'undefined') {
cell(typeof doc.options[k]).appendTo($option);
if(Ox.isNull(doc.options[k]))
cell(' <b>null</b>').appendTo($option);
else
cell(' <b>' + doc.options[k].toString() + '</b>').appendTo($option);
} else {
cell('&nbsp;').appendTo($option);
cell('<b>required, no default value</b>').appendTo($option);
}
$option.appendTo($options);
});
}
var methods = Ox.keys(doc.methods);
if (methods.length > 0) {
@ -166,20 +163,22 @@ function getDocHtml(doc) {
});
}
var $methodcode = $('<pre>').html(doc.functionString.replace(/</g, '&lt;'))
.hide();
var $button = new Ox.Button({
title: [
{id: "one", title: "expand"},
{id: "two", title: "collapse"},
],
type: "image"
})
.addClass("margin")
.click(function() { $methodcode.toggle()})
.appendTo($div)
$('<span>').html(' View Source').appendTo($div)
$methodcode.appendTo($div);
if(doc.functionString) {
var $methodcode = $('<pre>').html(doc.functionString.replace(/</g, '&lt;'))
.hide();
var $button = new Ox.Button({
title: [
{id: "one", title: "expand"},
{id: "two", title: "collapse"},
],
type: "image"
})
.addClass("margin")
.click(function() { $methodcode.toggle()})
.appendTo($div)
$('<span>').html(' View Source').appendTo($div)
$methodcode.appendTo($div);
}
return $div;
}
@ -194,46 +193,54 @@ function getObjectByName(obj, name) {
}
function getDocsJSON() {
var ret = [],
keys = Ox.keys(Ox);
keys.forEach(function(v) {
if (doc = getDoc(v)) {
ret.push(doc);
} else {
$.noop();
}
});
return ret;
var ret = [],
keys = Ox.keys(Ox);
keys.forEach(function(v) {
if (doc = getDoc(v)) {
ret.push(doc);
} else {
$.noop();
}
});
return ret;
function getDoc(key) {
var standardElement = new Ox.Element();
var standardMethods = Ox.filter(Ox.keys(standardElement), function(m) { return typeof standardElement[m] === 'function' });
var firstLetter = key.substring(0,1);
if (firstLetter != firstLetter.toUpperCase() || typeof Ox[key] != 'function') {
return false;
function getDoc(key) {
var standardElement = new Ox.Element();
var standardMethods = Ox.filter(Ox.keys(standardElement), function(m) { return typeof standardElement[m] === 'function' });
//FIXME: eventually we want to document all Ox values and functions
if (!/^[A-Z][a-z]/.test(key)) {
return false
}
var functionString = Ox[key].toString();
if (typeof Ox[key] != 'function') {
return {
'name': key,
'functionString': functionString
}
}
var functionString = Ox[key].toString();
try {
var o = new Ox[key]();
} catch(err) {
return {
'name': key,
'functionString': functionString
}
}
var methods = {};
var opts = {};
if ('options' in o && typeof o['options'] == 'function') {
var opts = o.options();
var _methods = Ox.filter(Ox.keys(o), function(m) { return (functionString.indexOf('that.'+m+' =') > -1 && typeof o[m] === 'function')});
$.each(_methods, function(i, m) { methods[m] = o[m].toString() });
}
return {
'name': key,
'options': opts,
'methods': methods,
'functionString': functionString
}
}
try {
var o = new Ox[key]();
}
catch(err) {
return false;
}
if ('options' in o && typeof o['options'] == 'function') {
var functionString = Ox[key].toString();
var opts = o.options();
var _methods = Ox.filter(Ox.keys(o), function(m) { return (functionString.indexOf('that.'+m+' =') > -1 && typeof o[m] === 'function')});
var methods = {};
$.each(_methods, function(i, m) { methods[m] = o[m].toString() });
}
else {
return false;
}
return {
'name': key,
'options': opts,
'methods': methods,
'functionString': functionString
}
}
}