diff --git a/tools/api-builder/content-package/index.js b/tools/api-builder/content-package/index.js new file mode 100644 index 0000000000..c1da0d66d0 --- /dev/null +++ b/tools/api-builder/content-package/index.js @@ -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]; } + }); +}); + diff --git a/tools/api-builder/content-package/mocks/mockPackage.js b/tools/api-builder/content-package/mocks/mockPackage.js new file mode 100644 index 0000000000..834d53c959 --- /dev/null +++ b/tools/api-builder/content-package/mocks/mockPackage.js @@ -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 {}; }); + +}; diff --git a/tools/api-builder/docs-package/readers/ngdoc.js b/tools/api-builder/content-package/readers/content.js similarity index 64% rename from tools/api-builder/docs-package/readers/ngdoc.js rename to tools/api-builder/content-package/readers/content.js index a1e6a7e4d5..f4b817a277 100644 --- a/tools/api-builder/docs-package/readers/ngdoc.js +++ b/tools/api-builder/content-package/readers/content.js @@ -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; }; \ No newline at end of file diff --git a/tools/api-builder/docs-package/readers/ngdoc.spec.js b/tools/api-builder/content-package/readers/content.spec.js similarity index 77% rename from tools/api-builder/docs-package/readers/ngdoc.spec.js rename to tools/api-builder/content-package/readers/content.spec.js index 658663c9fb..62540e9dd2 100644 --- a/tools/api-builder/docs-package/readers/ngdoc.spec.js +++ b/tools/api-builder/content-package/readers/content.spec.js @@ -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(); diff --git a/tools/api-builder/docs-package/index.js b/tools/api-builder/docs-package/index.js index 033e181b0e..b65ca98692 100644 --- a/tools/api-builder/docs-package/index.js +++ b/tools/api-builder/docs-package/index.js @@ -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' - }); -}); +}); \ No newline at end of file