lots of changes, should have committed earlier

This commit is contained in:
Spencer Alger
2013-12-02 18:30:30 -07:00
parent 477f1aff84
commit 2b5f6cd80d
45 changed files with 2498 additions and 1935 deletions

View File

@ -1,62 +0,0 @@
# API
## Table Of Contents
- [Generic Params](#generic-params)
- [Methods](#methods)<%
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, '').replace(/ /g, '-') %>)<%
})
%>
## Generic Params
Several parameters can be passed to any API method, and will control the way that those requests are carried out. These parameters are not listed in each method's param list.
| Name | Type | Description |
| ---- | ---- | ----------- |
| `[timeout=10000]` | Number | The number of milliseconds this request has to complete. It defaults to the timeout specified at the client level, which defaults to 10 seconds. |
| `ignore` | Number or Number[] | Don't treat these HTTP status codes as "errors". Example use cases could be `ignore: 404` or `ignore: [404]` |
## Methods<%
_.each(actions, function (action) {
%>
### <%= action.name %>()
<%= action.docUrl %><%
if (_.size(action.allParams)) { %>
| Name | Type | Description |
| ---- | ---- | ----------- |
<%
_.each(action.allParams, function(param, paramName) {
%>|`<%= paramWithDefault(paramName, param.default) %>` | <%= paramType(param.type) %> | <%= esc(param.description || '') %>|
<% })
} else {%>
-- none --
<%
}
}); %>

View File

@ -0,0 +1,32 @@
<%
function esc(str) {
return str.replace(/\|/g, '&#124;');
}
var topActions = [];
var names = {};
_.each(actions, function (action) {
if (action.name.indexOf('.') > -1) {
var space = _.studlyCase(action.name.split('.').slice(0, -1).join('.'));
if (!names[space]) {
names[space] = [];
}
names[space].push(action);
} else {
topActions.push(action);
}
}); %>
ul<%
_.each(topActions, function (action) {%>
li: a(href="api.html#<%= action.name.toLowerCase().replace(/[^\w]+/g, '-') %>") <%= action.name %><%
});
_.each(Object.keys(names).sort(), function (namespace) {%>
h3 <%= namespace %>
ul<%
_.each(names[namespace], function (action) {%>
li: a(href="api.html#<%= action.name.toLowerCase().replace(/[^\w]+/g, '-') %>") <%= action.name.replace(/^.*\./, '') %><%
})
})
%>

View File

@ -0,0 +1,40 @@
<%
_.each(actions, function (action) {
var actionId = action.name.toLowerCase().replace(/[^\w]+/g, '-');
%>
h3#<%= actionId %>.fn
span.name <%= action.name %>
span.args (params, [callback])
a.perma(href="api.html#<%= actionId %>", title="Permalink")
a.esdoc(href="<%= action.docUrl %>", title="Endpoint Docs")
//
h4 Spec:
pre
code <%= JSON.stringify(action, null, ' ').split('\n').map(function (line, i) {
return (i > 0 ? ' | ' : '') + line;
}).join('\n') %>
h4 Params:
ul.params.api
<% _.each(action.allParams, function (param, paramName) { %>
li
code.name <%= paramWithDefault(paramName, param.default) %>
<%=
_.map(
('<span class="types">' + paramType(param.type) + '</span> ' + (param.description || '')).split('\n'),
function (line) {
return '| ' + line + '\n';
}
).join('\n')
%>
<% }); %>
li <a href="#api-conventions-params">the usual</a>
h4 Method: <code><%= action.spec.method || 'GET' %></code>
h4 Returns:
p: a(href="#api-conventions-return") the usual<%
});
%>

View File

@ -52,13 +52,13 @@ var templateGlobals = {
paramType: function (type) {
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
case 'time':
return 'Date or Number';
return 'Date, Number';
case 'any':
return '*';
return 'Anything';
case 'enum':
return 'String';
case 'list':
return 'String or String[] or Boolean';
return 'String, String[], Boolean';
default:
return _.ucfirst(type);
}
@ -91,5 +91,6 @@ templates.text = templates.string;
module.exports = {
apiFile: templates.api_file,
apiDocs: templates.api_docs
apiMethodList: templates.api_method_list,
apiMethods: templates.api_methods
};