From 0b28de1e550d4811cd7206d2883fde157e500e83 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Sat, 15 Feb 2014 20:57:38 +0000 Subject: chore(doc-gen): improve error page navigation --- docs/config/index.js | 1 + docs/config/processors/error-docs.js | 42 ++++++++++++++++++++++ docs/config/processors/pages-data.js | 5 +-- docs/config/templates/errorNamespace.template.html | 28 +++++++++++++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 docs/config/processors/error-docs.js create mode 100644 docs/config/templates/errorNamespace.template.html diff --git a/docs/config/index.js b/docs/config/index.js index f2d76977..ea15ce44 100644 --- a/docs/config/index.js +++ b/docs/config/index.js @@ -10,6 +10,7 @@ module.exports = function(config) { config.append('processing.processors', [ require('./processors/git-data'), + require('./processors/error-docs'), require('./processors/keywords'), require('./processors/versions-data'), require('./processors/pages-data'), diff --git a/docs/config/processors/error-docs.js b/docs/config/processors/error-docs.js new file mode 100644 index 00000000..80a7b996 --- /dev/null +++ b/docs/config/processors/error-docs.js @@ -0,0 +1,42 @@ +var _ = require('lodash'); +var log = require('winston'); +var path = require('canonical-path'); + +module.exports = { + name: 'error-docs', + description: 'Compute the various fields for docs in the Error area', + runAfter: ['tags-extracted'], + init: function(config, injectables) { + injectables.value('errorNamespaces', {}); + }, + process: function(docs, partialNames, errorNamespaces) { + + // Create error namespace docs and attach error docs to each + _.forEach(docs, function(doc) { + if ( doc.docType === 'error' ) { + + var namespaceDoc = errorNamespaces[doc.namespace]; + if ( !namespaceDoc ) { + // First time we came across this namespace, so create a new one + namespaceDoc = errorNamespaces[doc.namespace] = { + area: doc.area, + name: doc.namespace, + errors: [], + path: path.dirname(doc.path), + outputPath: path.dirname(doc.outputPath) + '.html', + docType: 'errorNamespace' + }; + } + + // Add this error to the namespace + namespaceDoc.errors.push(doc); + doc.namespace = namespaceDoc; + + } + + }); + + + return docs.concat(_.values(errorNamespaces)); + } +}; \ No newline at end of file diff --git a/docs/config/processors/pages-data.js b/docs/config/processors/pages-data.js index 35ed242f..ff419423 100644 --- a/docs/config/processors/pages-data.js +++ b/docs/config/processors/pages-data.js @@ -103,7 +103,7 @@ var navGroupMappers = { return { name: page.name, href: page.path, - type: 'error' + type: page.docType === 'errorNamespace' ? 'section' : 'error' }; })]; }, @@ -142,7 +142,8 @@ module.exports = { // We are only interested in docs that are in a area and not landing pages var navPages = _.filter(docs, function(page) { - return page.area && page.docType != 'componentGroup'; + return page.area && + page.docType != 'componentGroup'; }); // Generate an object collection of pages that is grouped by area e.g. diff --git a/docs/config/templates/errorNamespace.template.html b/docs/config/templates/errorNamespace.template.html new file mode 100644 index 00000000..ebd48e04 --- /dev/null +++ b/docs/config/templates/errorNamespace.template.html @@ -0,0 +1,28 @@ +{% extends 'base.template.html' %} + +{% block content %} +
| Name | +Description | +
|---|---|
| {$ errorDoc.name $} | +{$ errorDoc.fullName $} | +