api-builder: move ngdoc stuff out from doc-package and into content package

This commit is contained in:
Peter Bacon Darwin 2015-11-05 12:32:45 +00:00
parent d08ebf4b9a
commit bc8a319f61
5 changed files with 66 additions and 49 deletions

View File

@ -0,0 +1,35 @@
var Package = require('dgeni').Package;
var jsdocPackage = require('dgeni-packages/jsdoc');
var linksPackage = require('../links-package');
var path = require('canonical-path');
var fs = require('fs');
// Define the dgeni package for generating the docs
module.exports = new Package('content', [jsdocPackage, linksPackage])
// Register the services and file readers
.factory(require('./readers/content'))
// Configure file reading
.config(function(readFilesProcessor, contentFileReader) {
readFilesProcessor.fileReaders.push(contentFileReader);
})
// Configure ids and paths
.config(function(computeIdsProcessor, computePathsProcessor) {
computeIdsProcessor.idTemplates.push({
docTypes: ['content'],
getId: function(doc) {
return doc.fileInfo.relativePath
// path should be relative to `modules` folder
.replace(/.*\/?modules\//, '')
// path should not include `/docs/`
.replace(/\/docs\//, '/')
// path should not have a suffix
.replace(/\.\w*$/, '');
},
getAliases: function(doc) { return [doc.id]; }
});
});

View File

@ -0,0 +1,11 @@
var Package = require('dgeni').Package;
module.exports = function mockPackage() {
return new Package('mockPackage', [require('../')])
// provide a mock log service
.factory('log', function() { return require('dgeni/lib/mocks/log')(false); })
.factory('templateEngine', function() { return {}; });
};

View File

@ -1,9 +1,9 @@
var path = require('canonical-path');
/**
* @dgService ngdocFileReader
* @dgService
* @description
* This file reader will pull the contents from a text file (by default .ngdoc)
* This file reader will pull the contents from a text file (by default .md)
*
* The doc will initially have the form:
* ```
@ -13,13 +13,13 @@ var path = require('canonical-path');
* }
* ```
*/
module.exports = function ngdocFileReader() {
var reader = {
name: 'ngdocFileReader',
module.exports = function contentFileReader() {
return {
name: 'contentFileReader',
defaultPattern: /\.md$/,
getDocs: function(fileInfo) {
// We return a single element array because ngdoc files only contain one document
// We return a single element array because content files only contain one document
return [{
docType: 'guide',
content: fileInfo.content,
@ -27,6 +27,4 @@ module.exports = function ngdocFileReader() {
}];
}
};
return reader;
};

View File

@ -1,9 +1,16 @@
var ngdocFileReaderFactory = require('./ngdoc');
var mockPackage = require('../mocks/mockPackage');
var Dgeni = require('dgeni');
var path = require('canonical-path');
var _ = require('lodash');
describe('ngdocFileReader', function() {
describe('contentFileReader', function() {
var dgeni, injector, fileReader;
var fileReader;
beforeEach(function() {
dgeni = new Dgeni([mockPackage()]);
injector = dgeni.configureInjector();
fileReader = injector.get('contentFileReader');
});
var createFileInfo = function(file, content, basePath) {
return {
@ -17,12 +24,6 @@ describe('ngdocFileReader', function() {
};
};
beforeEach(function() {
fileReader = ngdocFileReaderFactory();
});
describe('defaultPattern', function() {
it('should match .md files', function() {
expect(fileReader.defaultPattern.test('abc.md')).toBeTruthy();

View File

@ -10,9 +10,6 @@ var fs = require('fs');
// Define the dgeni package for generating the docs
module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage, gitPackage])
// Register the services and file readers
.factory(require('./readers/ngdoc'))
// Register the processors
.processor(require('./processors/convertPrivateClassesToInterfaces'))
.processor(require('./processors/extractDirectiveClasses'))
@ -36,9 +33,8 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
})
// Configure file reading
.config(function(readFilesProcessor, ngdocFileReader, readTypeScriptModules) {
readFilesProcessor.fileReaders = [ngdocFileReader];
// set the readFilesProcessor base path to point to angular repo.
.config(function(readTypeScriptModules) {
var angular_repo_path = path.resolve(__dirname, '../../../../angular');
// confirm that the angular repo is actually there.
if (!fs.existsSync(angular_repo_path)) {
@ -54,6 +50,7 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
.config(function(parseTagsProcessor, getInjectables) {
// We actually don't want to parse param docs in this package as we are getting the data out using TS
// TODO: rewire the param docs to the params extracted from TS
parseTagsProcessor.tagDefinitions.forEach(function(tagDef) {
if (tagDef.name === 'param') {
tagDef.docProperty = 'paramData';
@ -95,29 +92,4 @@ module.exports = new Package('angular-v2-docs', [jsdocPackage, nunjucksPackage,
'${ doc.docType }.template.html',
'common.template.html'
];
})
// Configure ids and paths
.config(function(computeIdsProcessor, computePathsProcessor) {
computeIdsProcessor.idTemplates.push({
docTypes: ['guide'],
getId: function(doc) {
return doc.fileInfo.relativePath
// path should be relative to `modules` folder
.replace(/.*\/?modules\//, '')
// path should not include `/docs/`
.replace(/\/docs\//, '/')
// path should not have a suffix
.replace(/\.\w*$/, '');
},
getAliases: function(doc) { return [doc.id]; }
});
computePathsProcessor.pathTemplates.push({
docTypes: ['guide'],
pathTemplate: '/${id}',
outputPathTemplate: 'partials/guides/${id}.html'
});
});
});