[generate/docs/examples] allow overriding individual example files based on version
This commit is contained in:
@ -28,6 +28,10 @@ module.exports = function (branch, done) {
|
||||
clientActionModifier: false
|
||||
});
|
||||
|
||||
var examples = version.mergeOpts(require('../../docs/_examples/index.js'), {
|
||||
examples: {}
|
||||
}).examples;
|
||||
|
||||
var steps = [
|
||||
readSpecFiles,
|
||||
parseSpecFiles,
|
||||
@ -100,6 +104,17 @@ module.exports = function (branch, done) {
|
||||
|
||||
apiSpec.proxies.push(create);
|
||||
|
||||
[].concat(apiSpec.actions, apiSpec.proxies)
|
||||
.forEach(function (action) {
|
||||
var examplePath = examples[action.name] || action.name + '.asciidoc';
|
||||
|
||||
try {
|
||||
action.examples = fs.readFileSync(fromRoot('docs/_examples', examplePath), 'utf8');
|
||||
} catch (e) {
|
||||
action.examples = '// no examples';
|
||||
}
|
||||
})
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
@ -336,4 +351,3 @@ module.exports = function (branch, done) {
|
||||
return actions;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ client.<%= action.name %>([params, [callback]])
|
||||
|
||||
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) %>
|
||||
<%= action.examples %>
|
||||
|
||||
<% if (_.size(action.allParams)) { %>
|
||||
*Params*
|
||||
|
||||
@ -66,18 +66,6 @@ var templateGlobals = {
|
||||
}
|
||||
},
|
||||
|
||||
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