added api.md generation [ci skip]

This commit is contained in:
Spencer Alger
2013-11-11 16:01:05 -07:00
parent 7905d9b78c
commit 671280a0a6
10 changed files with 1174 additions and 33108 deletions

View File

@ -8,6 +8,7 @@ var clean = require('../../clean');
var urlParamRE = /\{(\w+)\}/g;
var outputPath = _.joinPath(__dirname, '../../../src/lib/api.js');
var docOutputPath = _.joinPath(__dirname, '../../../docs/api.md');
function download() {
require('./actions').on('ready', function (actions) {
@ -27,6 +28,9 @@ function download() {
actions: actions,
namespaces: _.unique(namespaces.sort(), true)
}));
fs.writeFileSync(docOutputPath, templates.apiDocs({
actions: actions
}));
});
}

View File

@ -0,0 +1,39 @@
# API
## Table Of Contents
<%
function esc(str) {
return str.replace(/\|/g, '&#124;');
}
var _paramWithDefault = paramWithDefault;
paramWithDefault = function (name, _default) {
return esc(_paramWithDefault(name, _default));
};
var _paramType = paramType;
paramType = function (type) {
return esc(_paramType(type));
};
_.each(actions, function (action) {%>
- [<%= action.name %>](#<%= action.name.toLowerCase().replace(/[^\w]/g, '') %>)<%
})
_.each(actions, function (action) {
%>
### <%= action.name %>()
<%= action.docUrl %>
| Name | Type | Description |
| ---- | ---- | ----------- |
<%
_.each(action.allParams, function(param, paramName) {
%>|`<%= paramWithDefault(paramName, param.default) %>` | <%= paramType(param.type) %> | <%= esc(param.description || '') %>|
<% })
}); %>

View File

@ -87,13 +87,13 @@ var templateGlobals = {
paramType: function (type) {
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
case 'time':
return 'Date|Number';
return 'Date or Number';
case 'any':
return '*';
case 'enum':
return 'String';
case 'list':
return 'String|ArrayOfStrings|Boolean';
return 'String or String[] or Boolean';
default:
return _.ucfirst(type);
}
@ -125,5 +125,6 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
templates.text = templates.string;
module.exports = {
apiFile: templates.api_file
apiFile: templates.api_file,
apiDocs: templates.api_docs
};