added docs to the repo
This commit is contained in:
@ -1,32 +0,0 @@
|
||||
<%
|
||||
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(/^.*\./, '') %><%
|
||||
})
|
||||
})
|
||||
%>
|
||||
@ -1,27 +1,34 @@
|
||||
== API Method Reference
|
||||
<%
|
||||
_.each(actions, function (action) {
|
||||
var actionId = action.name.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
var actionId = 'api-' + action.name.toLowerCase().replace(/[^\w]+/g, '-');
|
||||
|
||||
%>
|
||||
|
||||
h2#<%= actionId %>.fn <%= action.name %>(params, [callback])
|
||||
include _descriptions/<%= action.name %>.jade
|
||||
p.
|
||||
The default method is <code><%= action.spec.method || 'GET' %></code> and
|
||||
the usual <a href="#api-conventions">params and return values</a> apply.
|
||||
See <a href="<%= action.docUrl %>" title="<%= action.name %>
|
||||
at elasticsearch.org"><%= action.docUrl %></a> for more about this method.
|
||||
include _examples/<%= action.name %>.jade
|
||||
[[<%= actionId %>]]
|
||||
=== `<%= action.name %>`
|
||||
|
||||
[source,js]
|
||||
--------
|
||||
client.<%= action.name %>([params, [callback]])
|
||||
--------
|
||||
|
||||
<%= description(action.name) %>
|
||||
|
||||
The default method is `<%= action.spec.method || 'GET' %>` and the usual <<api-conventions,params and return values>> apply. See <%= action.docUrl %>[the elasticsearch docs] for more about this method.
|
||||
|
||||
<%= examples(action.name) %>
|
||||
|
||||
<% if (_.size(action.allParams)) { %>
|
||||
h3 Params
|
||||
dl.params.api
|
||||
<% _.each(action.allParams, function (param, paramName) { %>
|
||||
dt: dfn: code <%= paramWithDefault(paramName, param.default) %>
|
||||
dd.
|
||||
<span class="types"><%= paramType(param.type) %></span>
|
||||
<%= indent(param.description || '', 4) %><%
|
||||
}); %>
|
||||
<% }
|
||||
==== Params
|
||||
|
||||
});
|
||||
[horizontal]<%
|
||||
_.each(action.allParams, function (param, paramName) { %>
|
||||
`<%= paramWithDefault(paramName, param.default) %>`::
|
||||
`<%= paramType(param.type) %>` -- <%= joinParagraphs(param.description || '', 4) %><%
|
||||
|
||||
}); // endeach
|
||||
} // endif
|
||||
|
||||
}); // endeach
|
||||
%>
|
||||
|
||||
@ -49,6 +49,34 @@ var templateGlobals = {
|
||||
}).join('\n');
|
||||
},
|
||||
|
||||
joinParagraphs: function (block) {
|
||||
return block.split('\n\n').join('\n+\n');
|
||||
},
|
||||
|
||||
description: function (action) {
|
||||
try {
|
||||
return fs.readFileSync(path.join(__dirname, '../../../docs/_descriptions/' + action + '.asciidoc'));
|
||||
} catch (e) {
|
||||
if (~e.message.indexOf('ENOENT')) {
|
||||
return '// no description';
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
examples: function (action) {
|
||||
try {
|
||||
return fs.readFileSync(path.join(__dirname, '../../../docs/_examples/' + action + '.asciidoc'));
|
||||
} catch (e) {
|
||||
if (~e.message.indexOf('ENOENT')) {
|
||||
return '// no examples';
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
paramType: function (type) {
|
||||
switch (type && type.toLowerCase ? type.toLowerCase() : 'any') {
|
||||
case 'time':
|
||||
|
||||
Reference in New Issue
Block a user