// jscs:disable jsDoc
var _ = require('lodash'),
util = require('arrow-util').content;
function generate(object, baseurl, adminurl, context) {
var pages = [];
_.keys(object.models).forEach(function (name) {
var page = {
url: util.makeAnchor(name),
title: name
},
markdown = [];
var model = object.models[name];
if (model.documented !== undefined && !model.documented) {
return;
}
markdown.push('# ' + name + '\n');
markdown.push(model.description || '');
var links = [];
Eif (!model.generated && (!model.connector || model.connector.indexOf('composite') === -1)) {
links.push('[Edit](build.html?edit=' + encodeURIComponent(model.name) + '),');
}
links.push('[Extend](build.html?extend=' + encodeURIComponent(model.name) + ')');
links.push('or [Reduce](build.html?reduce=' + encodeURIComponent(model.name) + ')');
markdown.push('You can ' + links.join(' ') + ' this model.');
markdown.push('## Fields\n');
Eif (_.keys(model.fields).length > 0) {
markdown.push('The following fields have been defined for this model:');
markdown.push('');
markdown.push('Type | Name | Required | Default | Description | Links to');
markdown.push('---- | --------- | -------- | ------- | ----------- | --------');
_.keys(model.fields).forEach(function (key) {
var field = model.fields[key],
def = field.default || '-',
desc = (field.description || '').replace(/\n/g, '<br />') || '-',
link = (field.model && '[' + field.model + '](docs.html?models/' + util.makeAnchor(field.model) + '.html)') || '-';
markdown.push(field.type + ' | ' + key.replace(/_/g, '\\_') + ' | ' + field.required + ' | ' + def + ' | ' + desc + ' | ' + link);
});
} else {
markdown.push('This model has no defined fields.');
}
Eif (model.connector) {
markdown.push('## Connector');
markdown.push('This model uses the [' + model.connector + '](docs.html?connectors/' + util.makeAnchor(model.connector) + '.html) connector.');
Eif (!(model.connector in context.connectors)) {
context.connectors[model.connector] = [name];
} else if (!(name in context.connectors[model.connector])) {
context.connectors[model.connector].push(name);
}
markdown.push('');
}
page.markdown = markdown.join('\n');
pages.push(page);
});
return pages;
}
exports.generate = generate;
|