lots of changes, should have committed earlier
This commit is contained in:
@ -1,62 +0,0 @@
|
||||
# API
|
||||
|
||||
## Table Of Contents
|
||||
|
||||
- [Generic Params](#generic-params)
|
||||
- [Methods](#methods)<%
|
||||
|
||||
function esc(str) {
|
||||
return str.replace(/\|/g, '|');
|
||||
}
|
||||
|
||||
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 --
|
||||
<%
|
||||
|
||||
}
|
||||
|
||||
}); %>
|
||||
32
scripts/generate/js_api/templates/api_method_list.tmpl
Normal file
32
scripts/generate/js_api/templates/api_method_list.tmpl
Normal file
@ -0,0 +1,32 @@
|
||||
<%
|
||||
function esc(str) {
|
||||
return str.replace(/\|/g, '|');
|
||||
}
|
||||
|
||||
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(/^.*\./, '') %><%
|
||||
})
|
||||
})
|
||||
%>
|
||||
40
scripts/generate/js_api/templates/api_methods.tmpl
Normal file
40
scripts/generate/js_api/templates/api_methods.tmpl
Normal 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<%
|
||||
});
|
||||
%>
|
||||
@ -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
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user