cleanup api docs

This commit is contained in:
j 2010-12-06 19:23:04 +01:00
parent 79bbc1d75a
commit ba9bf2ee4b
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() { Ox.Event = function() {
var $eventHandler = $('<div>'), var $eventHandler = $('<div>'),
@ -632,7 +632,7 @@ requires
*/ */
/** /**
Ox.Request Ox.Request request object
*/ */
Ox.Request = function() { 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) { Ox.DateInput = function(options, self) {
var self = $.extend(self || {}, { var self = $.extend(self || {}, {

View File

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