refact(api-builder): move into tools folder
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
var path = require('canonical-path');
|
||||
var Package = require('dgeni').Package;
|
||||
var basePackage = require('../docs-package');
|
||||
|
||||
var PROJECT_PATH = path.resolve(__dirname, "../../..");
|
||||
var PUBLIC_PATH = path.resolve(PROJECT_PATH, 'public');
|
||||
var DOCS_PATH = path.resolve(PUBLIC_PATH, 'docs');
|
||||
|
||||
module.exports = new Package('angular.io', [basePackage])
|
||||
|
||||
.factory(require('./services/renderMarkdown'))
|
||||
.processor(require('./processors/addJadeDataDocsProcessor'))
|
||||
.processor(require('./processors/filterUnwantedDecorators'))
|
||||
.processor(require('./processors/extractDirectiveClasses'))
|
||||
.processor(require('./processors/matchUpDirectiveDecorators'))
|
||||
|
||||
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
|
||||
.factory(require('./services/packageInfo'))
|
||||
|
||||
// Configure rendering
|
||||
.config(function(templateFinder, templateEngine) {
|
||||
|
||||
templateFinder.templateFolders
|
||||
.unshift(path.resolve(__dirname, 'templates'));
|
||||
})
|
||||
|
||||
.config(function(parseTagsProcessor) {
|
||||
parseTagsProcessor.tagDefinitions.push({ name: 'internal', transforms: function() { return true; } });
|
||||
})
|
||||
|
||||
.config(function(readTypeScriptModules, writeFilesProcessor, readFilesProcessor) {
|
||||
|
||||
readTypeScriptModules.sourceFiles = [
|
||||
'angular2/lifecycle_hooks.ts',
|
||||
'angular2/core.ts',
|
||||
'angular2/http.ts',
|
||||
'angular2/router.ts',
|
||||
'angular2/test.ts'
|
||||
];
|
||||
readTypeScriptModules.hidePrivateMembers = true;
|
||||
|
||||
readFilesProcessor.basePath = DOCS_PATH;
|
||||
writeFilesProcessor.outputFolder = 'js/latest/api';
|
||||
})
|
||||
|
||||
.config(function(getLinkInfo) {
|
||||
getLinkInfo.useFirstAmbiguousLink = false;
|
||||
})
|
||||
|
||||
|
||||
.config(function(readFilesProcessor, generateNavigationDoc, createOverviewDump) {
|
||||
// Clear out unwanted processors
|
||||
readFilesProcessor.$enabled = false;
|
||||
generateNavigationDoc.$enabled = false;
|
||||
createOverviewDump.$enabled = false;
|
||||
})
|
||||
|
||||
|
||||
.config(function(computeIdsProcessor, computePathsProcessor, EXPORT_DOC_TYPES) {
|
||||
|
||||
computePathsProcessor.pathTemplates.push({
|
||||
docTypes: ['module'],
|
||||
getPath: function computeModulePath(doc) {
|
||||
return doc.id.replace(/^angular2\//, '');
|
||||
},
|
||||
outputPathTemplate: '${path}/index.jade'
|
||||
});
|
||||
|
||||
computePathsProcessor.pathTemplates.push({
|
||||
docTypes: EXPORT_DOC_TYPES,
|
||||
pathTemplate: '${moduleDoc.path}/${name}-${docType}.html',
|
||||
outputPathTemplate:'${moduleDoc.path}/${name}-${docType}.jade',
|
||||
});
|
||||
|
||||
computePathsProcessor.pathTemplates.push({
|
||||
docTypes: ['jade-data'],
|
||||
pathTemplate: '${originalDoc.path}/_data',
|
||||
outputPathTemplate: '${path}.json'
|
||||
});
|
||||
|
||||
computePathsProcessor.pathTemplates.push({
|
||||
docTypes: ['app-data'],
|
||||
pathTemplate: path.resolve(PUBLIC_PATH, 'resources/js/app-data'),
|
||||
outputPathTemplate: '${path}.json'
|
||||
});
|
||||
})
|
||||
|
||||
.config(function(getLinkInfo) {
|
||||
getLinkInfo.relativeLinks = true;
|
||||
})
|
||||
|
||||
|
||||
.config(function(templateEngine, getInjectables) {
|
||||
templateEngine.filters = templateEngine.filters.concat(getInjectables([
|
||||
require('./rendering/trimBlankLines'),
|
||||
require('./rendering/toId'),
|
||||
require('./rendering/indentForMarkdown')
|
||||
]));
|
||||
})
|
||||
|
||||
.config(function(filterUnwantedDecorators, log) {
|
||||
log.level = 'info';
|
||||
filterUnwantedDecorators.decoratorsToIgnore = [
|
||||
'CONST',
|
||||
'IMPLEMENTS',
|
||||
'ABSTRACT'
|
||||
];
|
||||
})
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
var Package = require('dgeni').Package;
|
||||
|
||||
module.exports = function mockPackage() {
|
||||
|
||||
return new Package('mockPackage', [require('../')])
|
||||
|
||||
.factory('log', function() { return require('dgeni/lib/mocks/log')(false); })
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
var _ = require('lodash');
|
||||
var path = require('canonical-path');
|
||||
|
||||
var titleCase = function(text) {
|
||||
return text.replace(/(.)(.*)/, function(_, first, rest) {
|
||||
return first.toUpperCase() + rest;
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Create _data.json file for Harp pages
|
||||
*
|
||||
* http://harpjs.com/docs/development/metadata
|
||||
*
|
||||
* This method creates the meta data required for each page
|
||||
* such as the title, description, etc. This meta data is used
|
||||
* in the harp static site generator to create the title for headers
|
||||
* and the navigation used in the API docs
|
||||
*
|
||||
*/
|
||||
|
||||
module.exports = function addJadeDataDocsProcessor() {
|
||||
return {
|
||||
$runAfter: ['adding-extra-docs'],
|
||||
$runBefore: ['extra-docs-added'],
|
||||
$process: function(docs) {
|
||||
var extraDocs = [];
|
||||
var modules = [];
|
||||
|
||||
var appDataDoc = {
|
||||
id: 'app-data',
|
||||
docType: 'app-data',
|
||||
data: {}
|
||||
};
|
||||
extraDocs.push(appDataDoc);
|
||||
|
||||
/*
|
||||
* Create Data for Modules
|
||||
*
|
||||
* Modules must be public and have content
|
||||
*/
|
||||
|
||||
_.forEach(docs, function(doc) {
|
||||
if (doc.docType === 'module' && !doc.internal && doc.exports.length) {
|
||||
modules.push(doc);
|
||||
|
||||
// GET DATA FOR INDEX PAGE OF MODULE SECTION
|
||||
var indexPageInfo = [{
|
||||
name: 'index',
|
||||
title: _.map(path.basename(doc.fileInfo.baseName).split('_'), function(part) {
|
||||
return titleCase(part);
|
||||
}).join(' '),
|
||||
intro: doc.description.replace('"', '\"').replace(/\s*(\r?\n|\r)\s*/g," "),
|
||||
docType: 'module'
|
||||
}];
|
||||
|
||||
// GET DATA FOR EACH PAGE (CLASS, VARS, FUNCTIONS)
|
||||
var modulePageInfo = _(doc.exports)
|
||||
.map(function(exportDoc) {
|
||||
var dataDoc = {
|
||||
name: exportDoc.name + '-' + exportDoc.docType,
|
||||
title: exportDoc.name,
|
||||
docType: exportDoc.docType,
|
||||
exportDoc: exportDoc
|
||||
};
|
||||
if (exportDoc.symbolTypeName) dataDoc.varType = titleCase(exportDoc.symbolTypeName);
|
||||
if (exportDoc.originalModule) dataDoc.originalModule = exportDoc.originalModule;
|
||||
return dataDoc;
|
||||
})
|
||||
.sortBy('name')
|
||||
.value();
|
||||
|
||||
// ADD TO APP DATA DOC
|
||||
appDataDoc.data[doc.id] = modulePageInfo;
|
||||
|
||||
// COMBINE WITH INDEX PAGE DATA
|
||||
var allPageData = indexPageInfo.concat(modulePageInfo);
|
||||
|
||||
// PUSH JADE DATA DOC TO EXTRA DOCS ARRAY
|
||||
extraDocs.push({
|
||||
id: doc.id + "-data",
|
||||
aliases: [doc.id + "-data"],
|
||||
docType: 'jade-data',
|
||||
originalDoc: doc,
|
||||
data: allPageData
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return docs.concat(extraDocs);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
var mockPackage = require('../mocks/mockPackage');
|
||||
var Dgeni = require('dgeni');
|
||||
|
||||
describe('addJadeDataDocsProcessor', function() {
|
||||
var dgeni, injector, processor;
|
||||
|
||||
beforeEach(function() {
|
||||
dgeni = new Dgeni([mockPackage()]);
|
||||
injector = dgeni.configureInjector();
|
||||
processor = injector.get('addJadeDataDocsProcessor');
|
||||
});
|
||||
|
||||
it('should add a doc for each module', function() {
|
||||
var docs = [
|
||||
{
|
||||
docType: 'module',
|
||||
id: 'someModule',
|
||||
exports: [
|
||||
{ name: 'someObj', docType: 'var', symbolTypeName: 'MyClass', originalModule: 'some/private/module' }
|
||||
],
|
||||
fileInfo: { baseName: 'x_y' },
|
||||
description: 'some description\nsecond line'
|
||||
}
|
||||
];
|
||||
docs = processor.$process(docs);
|
||||
|
||||
expect(docs[1]).toEqual({
|
||||
id : 'someModule-data',
|
||||
aliases : [ 'someModule-data' ],
|
||||
docType : 'jade-data',
|
||||
originalDoc : docs[0],
|
||||
data : [
|
||||
{ name : 'index', title : 'X Y', intro : 'some description second line', docType : 'module' },
|
||||
{ name : 'someObj-var', title : 'someObj', varType : 'MyClass', docType: 'var', originalModule: 'some/private/module' }
|
||||
] });
|
||||
});
|
||||
|
||||
it('should sort the exports into alphabetical order', function() {
|
||||
var docs = [
|
||||
{
|
||||
docType: 'module',
|
||||
id: 'someModule',
|
||||
exports: [
|
||||
{ name: 'Beta', docType: 'class'},
|
||||
{ name: 'Alpha', docType: 'class'},
|
||||
{ name: 'Gamma', docType: 'class'},
|
||||
{ name: 'Nu', docType: 'class'},
|
||||
{ name: 'Mu', docType: 'class'}
|
||||
],
|
||||
fileInfo: { baseName: 'x_y' },
|
||||
description: 'some description\nsecond line'
|
||||
}
|
||||
];
|
||||
docs = processor.$process(docs);
|
||||
|
||||
expect(docs[1].data).toEqual([
|
||||
{ name : 'index', title : 'X Y', intro : 'some description second line', docType : 'module' },
|
||||
{ name: 'Alpha-class', title: 'Alpha', docType: 'class' },
|
||||
{ name: 'Beta-class', title: 'Beta', docType: 'class' },
|
||||
{ name: 'Gamma-class', title: 'Gamma', docType: 'class' },
|
||||
{ name: 'Mu-class', title: 'Mu', docType: 'class' },
|
||||
{ name: 'Nu-class', title: 'Nu', docType: 'class' }
|
||||
]);
|
||||
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function extractDirectiveClassesProcessor(EXPORT_DOC_TYPES) {
|
||||
|
||||
// Add the "directive" docType into those that can be exported from a module
|
||||
EXPORT_DOC_TYPES.push('directive');
|
||||
|
||||
return {
|
||||
$runAfter: ['processing-docs'],
|
||||
$runBefore: ['docs-processed'],
|
||||
decoratorTypes: ['Directive', 'Component', 'View'],
|
||||
$process: function(docs) {
|
||||
var decoratorTypes = this.decoratorTypes;
|
||||
|
||||
_.forEach(docs, function(doc) {
|
||||
|
||||
_.forEach(doc.decorators, function(decorator) {
|
||||
|
||||
if (decoratorTypes.indexOf(decorator.name) !== -1) {
|
||||
doc.docType = 'directive';
|
||||
|
||||
doc[decorator.name.toLowerCase() + 'Options'] = decorator.argumentInfo[0];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return docs;
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
var mockPackage = require('../mocks/mockPackage');
|
||||
var Dgeni = require('dgeni');
|
||||
|
||||
describe('extractDirectiveClasses processor', function() {
|
||||
var dgeni, injector, processor;
|
||||
|
||||
beforeEach(function() {
|
||||
dgeni = new Dgeni([mockPackage()]);
|
||||
injector = dgeni.configureInjector();
|
||||
processor = injector.get('extractDirectiveClassesProcessor');
|
||||
});
|
||||
|
||||
it('should extract specified decorator arguments', function() {
|
||||
var doc = {
|
||||
id: 'angular2/angular2.ngFor',
|
||||
name: 'ngFor',
|
||||
docType: 'class',
|
||||
decorators: [
|
||||
{
|
||||
name: 'Directive',
|
||||
arguments: ['{selector: \'[ng-for][ng-for-of]\', properties: [\'ngForOf\']}'],
|
||||
argumentInfo: [
|
||||
{ selector: '[ng-for][ng-for-of]', properties: ['ngForOf'] }
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var docs = processor.$process([doc]);
|
||||
|
||||
expect(doc).toEqual(jasmine.objectContaining({
|
||||
id: 'angular2/angular2.ngFor',
|
||||
name: 'ngFor',
|
||||
docType: 'directive',
|
||||
decorators: [
|
||||
{
|
||||
name: 'Directive',
|
||||
arguments: ['{selector: \'[ng-for][ng-for-of]\', properties: [\'ngForOf\']}'],
|
||||
argumentInfo: [
|
||||
{ selector: '[ng-for][ng-for-of]', properties: ['ngForOf'] }
|
||||
]
|
||||
}
|
||||
]
|
||||
}));
|
||||
|
||||
expect(doc.directiveOptions).toEqual({
|
||||
selector: '[ng-for][ng-for-of]',
|
||||
properties: ['ngForOf']
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function filterUnwantedDecorators() {
|
||||
return {
|
||||
decoratorsToIgnore: [],
|
||||
$runAfter: ['processing-docs'],
|
||||
$runBefore: ['docs-processed'],
|
||||
$process: function(docs) {
|
||||
var decoratorsToIgnore = this.decoratorsToIgnore || [];
|
||||
_.forEach(docs, function(doc) {
|
||||
if (doc.decorators) {
|
||||
doc.decorators = _.filter(doc.decorators, function(decorator) {
|
||||
return decoratorsToIgnore.indexOf(decorator.name) === -1;
|
||||
});
|
||||
}
|
||||
});
|
||||
return docs;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
var mockPackage = require('../mocks/mockPackage');
|
||||
var Dgeni = require('dgeni');
|
||||
|
||||
describe('filterUnwantedDecorators', function() {
|
||||
var dgeni, injector, processor;
|
||||
|
||||
beforeEach(function() {
|
||||
dgeni = new Dgeni([mockPackage()]);
|
||||
injector = dgeni.configureInjector();
|
||||
processor = injector.get('filterUnwantedDecorators');
|
||||
});
|
||||
|
||||
|
||||
it('should remove decorators specified by name', function() {
|
||||
var docs = [
|
||||
{ id: 'doc1', decorators: [ { name: 'A' }, { name: 'B' } ] },
|
||||
{ id: 'doc2', decorators: [ { name: 'B' }, { name: 'C' } ] },
|
||||
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
|
||||
];
|
||||
processor.decoratorsToIgnore = ['D', 'B'];
|
||||
docs = processor.$process(docs);
|
||||
|
||||
expect(docs).toEqual([
|
||||
{ id: 'doc1', decorators: [ { name: 'A' } ] },
|
||||
{ id: 'doc2', decorators: [ { name: 'C' } ] },
|
||||
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
it('should ignore docs that have no decorators', function() {
|
||||
var docs = [
|
||||
{ id: 'doc1', decorators: [ { name: 'A' }, { name: 'B' } ] },
|
||||
{ id: 'doc2' },
|
||||
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
|
||||
];
|
||||
processor.decoratorsToIgnore = ['D', 'B'];
|
||||
docs = processor.$process(docs);
|
||||
|
||||
expect(docs).toEqual([
|
||||
{ id: 'doc1', decorators: [ { name: 'A' } ] },
|
||||
{ id: 'doc2' },
|
||||
{ id: 'doc3', decorators: [ { name: 'A' }, { name: 'C' } ] }
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
var _ = require('lodash');
|
||||
|
||||
/**
|
||||
* @dgProcessor
|
||||
* @description
|
||||
*
|
||||
*/
|
||||
module.exports = function matchUpDirectiveDecoratorsProcessor(aliasMap) {
|
||||
|
||||
return {
|
||||
$runAfter: ['ids-computed', 'paths-computed'],
|
||||
$runBefore: ['rendering-docs'],
|
||||
decoratorMappings: {
|
||||
'Inputs' : 'inputs',
|
||||
'Outputs' : 'outputs'
|
||||
},
|
||||
$process: function(docs) {
|
||||
var decoratorMappings = this.decoratorMappings;
|
||||
_.forEach(docs, function(doc) {
|
||||
if (doc.docType === 'directive') {
|
||||
doc.selector = doc.directiveOptions.selector;
|
||||
|
||||
for(decoratorName in decoratorMappings) {
|
||||
var propertyName = decoratorMappings[decoratorName];
|
||||
doc[propertyName] = getDecoratorValues(doc.directiveOptions[propertyName], decoratorName, doc.members);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function getDecoratorValues(classDecoratorValues, memberDecoratorName, members) {
|
||||
var optionMap = {};
|
||||
var decoratorValues = {};
|
||||
|
||||
// Parse the class decorator
|
||||
_.forEach(classDecoratorValues, function(option) {
|
||||
// Options are of the form: "propName : bindingName" (bindingName is optional)
|
||||
var optionPair = option.split(':');
|
||||
var propertyName = optionPair.shift().trim();
|
||||
var bindingName = (optionPair.shift() || '').trim() || propertyName;
|
||||
|
||||
decoratorValues[propertyName] = {
|
||||
propertyName: propertyName,
|
||||
bindingName: bindingName
|
||||
};
|
||||
});
|
||||
|
||||
_.forEach(members, function(member) {
|
||||
_.forEach(member.decorators, function(decorator) {
|
||||
if (decorator.name === memberDecoratorName) {
|
||||
decoratorValues[member.name] = {
|
||||
propertyName: member.name,
|
||||
bindingName: decorator.arguments[0] || member.name
|
||||
};
|
||||
}
|
||||
});
|
||||
if (decoratorValues[member.name]) {
|
||||
decoratorValues[member.name].memberDoc = member;
|
||||
}
|
||||
});
|
||||
|
||||
if (Object.keys(decoratorValues).length) {
|
||||
return decoratorValues;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
module.exports = function(encodeCodeBlock) {
|
||||
// var MIXIN_PATTERN = /\S*\+\S*\(.*/;
|
||||
return {
|
||||
name: 'indentForMarkdown',
|
||||
process: function (str, width ) {
|
||||
if(str == null || str.length === 0) {
|
||||
return '';
|
||||
}
|
||||
width = width || 4;
|
||||
|
||||
var lines = str.split('\n');
|
||||
var newLines = [];
|
||||
var sp = spaces(width);
|
||||
var spMixin = spaces(width - 2);
|
||||
var isAfterMarkdownTag = true;
|
||||
lines.forEach(function(line) {
|
||||
// indent lines that match mixin pattern by 2 less than specified width
|
||||
if (line.indexOf('{@example') >= 0) {
|
||||
if (isAfterMarkdownTag) {
|
||||
// happens if example follows example
|
||||
if (newLines.length > 0) {
|
||||
newLines.pop();
|
||||
} else {
|
||||
// wierd case - first expression in str is an @example
|
||||
// in this case the :markdown appear above the str passed in,
|
||||
// so we need to put 'something' into the markdown tag.
|
||||
newLines.push(sp + "."); // '.' is a dummy char
|
||||
}
|
||||
}
|
||||
newLines.push(spMixin + line);
|
||||
// after a mixin line we need to reenter markdown.
|
||||
newLines.push(spMixin + ':markdown');
|
||||
isAfterMarkdownTag = true;
|
||||
} else {
|
||||
if ((!isAfterMarkdownTag) || (line.trim().length > 0)) {
|
||||
newLines.push(sp + line);
|
||||
isAfterMarkdownTag = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (isAfterMarkdownTag) {
|
||||
if (newLines.length > 0) {
|
||||
// if last line is a markdown tag remove it.
|
||||
newLines.pop();
|
||||
}
|
||||
}
|
||||
// force character to be a newLine.
|
||||
if (newLines.length > 0) newLines.push('');
|
||||
var res = newLines.join('\n');
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
function spaces(n) {
|
||||
var str = '';
|
||||
for(var i=0; i<n; i++) {
|
||||
str += ' ';
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
};
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = function toId() {
|
||||
return {
|
||||
name: 'toId',
|
||||
process: function(str) {
|
||||
return str.replace(/[^(a-z)(A-Z)(0-9)._-]/g, '-');
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
var factory = require('./toId');
|
||||
|
||||
describe('toId filter', function() {
|
||||
var filter;
|
||||
|
||||
beforeEach(function() {
|
||||
filter = factory();
|
||||
});
|
||||
|
||||
it('should be called "toId"', function() {
|
||||
expect(filter.name).toEqual('toId');
|
||||
});
|
||||
|
||||
it('should convert a string to make it appropriate for use as an HTML id', function() {
|
||||
expect(filter.process('This is a big string with €bad#characaters¢\nAnd even NewLines'))
|
||||
.toEqual('This-is-a-big-string-with--bad-characaters--And-even-NewLines');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
module.exports = function() {
|
||||
return {
|
||||
name: 'trimBlankLines',
|
||||
process: function(str) {
|
||||
var lines = str.split(/\r?\n/);
|
||||
while(lines.length && (lines[0].trim() === '')) {
|
||||
lines.shift();
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
var factory = require('./trimBlankLines');
|
||||
|
||||
describe('trimBlankLines filter', function() {
|
||||
var filter;
|
||||
|
||||
beforeEach(function() {
|
||||
filter = factory();
|
||||
});
|
||||
|
||||
it('should be called "trimBlankLines"', function() {
|
||||
expect(filter.name).toEqual('trimBlankLines');
|
||||
});
|
||||
|
||||
it('should remove all empty lines from the start of the string', function() {
|
||||
expect(filter.process('\n\n\nsome text\n\nmore text\n\n'))
|
||||
.toEqual('some text\n\nmore text\n\n');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('canonical-path');
|
||||
|
||||
/**
|
||||
* Load information about this project from the package.json
|
||||
* @return {Object} The package information
|
||||
*/
|
||||
module.exports = function packageInfo() {
|
||||
|
||||
var angularPackageJson= path.join('../angular','package.json');
|
||||
return JSON.parse(fs.readFileSync(angularPackageJson), 'UTF-8');
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
var marked = require('marked');
|
||||
var Encoder = require('node-html-encoder').Encoder;
|
||||
var html2jade = require('html2jade');
|
||||
var indentString = require('indent-string');
|
||||
|
||||
|
||||
function stripTags(s) { //from sugar.js
|
||||
return s.replace(RegExp('<\/?[^<>]*>', 'gi'), '');
|
||||
}
|
||||
|
||||
// entity type encoder
|
||||
var encoder = new Encoder('entity');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @dgService renderMarkdown
|
||||
* @description
|
||||
* Render the markdown in the given string as HTML.
|
||||
*/
|
||||
module.exports = function renderMarkdown(trimIndentation) {
|
||||
|
||||
var renderer = new marked.Renderer();
|
||||
|
||||
renderer.code = function(code, lang, escaped) {
|
||||
|
||||
var cssClasses = ['prettyprint', 'linenums'];
|
||||
var trimmedCode = trimIndentation(code);
|
||||
|
||||
if(lang) {
|
||||
if(lang=='html') {
|
||||
trimmedCode = encoder.htmlEncode(trimmedCode);
|
||||
}
|
||||
cssClasses.push(this.options.langPrefix + escape(lang, true));
|
||||
}
|
||||
|
||||
return 'pre(class="' + cssClasses.join(' ') + '")\n' + indentString('code.\n', ' ', 2) + trimmedCode;
|
||||
};
|
||||
|
||||
renderer.heading = function (text, level, raw) {
|
||||
var headingText = marked.Renderer.prototype.heading.call(renderer, text, level, raw);
|
||||
var title = 'h2 ' + stripTags(headingText);
|
||||
|
||||
if (level==2) {
|
||||
title = '.l-main-section\n' + indentString(title, ' ', 2) ;
|
||||
}
|
||||
|
||||
return title;
|
||||
};
|
||||
|
||||
return function(content) {
|
||||
return marked(content, { renderer: renderer });
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
{%- for module, items in doc.data %}
|
||||
"{$ module $}" : [{% for item in items %}
|
||||
{
|
||||
"title": "{$ item.title $}",
|
||||
"path": "{$ item.exportDoc.path $}",
|
||||
"docType": "{$ item.docType $}"
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor %}]{% if not loop.last %},{% endif %}
|
||||
{% endfor -%}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
{% include "lib/githubLinks.html" -%}
|
||||
{% include "lib/paramList.html" -%}
|
||||
{% extends 'layout/base.template.html' -%}
|
||||
|
||||
{% block body %}
|
||||
include ../../_util-fns
|
||||
|
||||
h2(class="{$ doc.docType $} export")
|
||||
pre.prettyprint
|
||||
code.
|
||||
export {$ doc.docType $} {$ doc.name $}
|
||||
|
||||
p.location-badge.
|
||||
exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} }
|
||||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{%- if doc.notYetDocumented %}
|
||||
*Not Yet Documented*
|
||||
{% else %}
|
||||
{$ doc.description | indentForMarkdown(2) | trimBlankLines $}
|
||||
{% endif %}
|
||||
|
||||
{% block additional %}
|
||||
{% endblock %}
|
||||
|
||||
{%- if doc.decorators.length %}
|
||||
.l-main-section
|
||||
h2 Annotations
|
||||
{%- for decorator in doc.decorators %}
|
||||
.l-sub-section
|
||||
h3.annotation
|
||||
pre.prettyprint
|
||||
code.
|
||||
@{$ decorator.name $}{$ paramList(decorator.arguments) | indent(8, false) $}
|
||||
{% endfor %}
|
||||
{%- endif %}
|
||||
|
||||
|
||||
{% if doc.constructorDoc or doc.members.length -%}
|
||||
.l-main-section
|
||||
h2 Members
|
||||
|
||||
{%- if doc.constructorDoc %}
|
||||
.l-sub-section
|
||||
h3#{$ doc.constructorDoc.name | toId $}
|
||||
pre.prettyprint
|
||||
code.
|
||||
{$ doc.constructorDoc.name $}{$ paramList(doc.constructorDoc.parameters) | indent(8, false) | trim $}
|
||||
:markdown
|
||||
{$ doc.constructorDoc.description | indentForMarkdown(6) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
{% endif -%}
|
||||
|
||||
{%- for member in doc.members %}{% if not member.internal %}
|
||||
.l-sub-section
|
||||
h3#{$ member.name | toId $}
|
||||
pre.prettyprint
|
||||
code.
|
||||
{$ member.name $}{$ paramList(member.parameters) | indent(8, false) | trim $}{$ returnType(member.returnType) $}
|
||||
|
||||
:markdown
|
||||
{$ member.description | indentForMarkdown(6) | replace('## Example', '') | replace('# Example', '') | trimBlankLines $}
|
||||
|
||||
{% endif %}{% endfor %}
|
||||
{%- endif -%}
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,39 @@
|
||||
{% include "lib/githubLinks.html" -%}
|
||||
{% include "lib/paramList.html" -%}
|
||||
{% extends 'class.template.html' -%}
|
||||
|
||||
{% block additional %}
|
||||
.l-main-section
|
||||
h2 Selectors
|
||||
.l-sub-section
|
||||
{% for selector in doc.directiveOptions.selector.split(',') %}
|
||||
h3.selector
|
||||
code {$ selector $}
|
||||
{% endfor %}
|
||||
|
||||
{% if doc.inputs %}
|
||||
.l-main-section
|
||||
h2 Inputs
|
||||
.l-sub-section{% for binding, property in doc.inputs %}
|
||||
h3.input
|
||||
code {$ property.bindingName | dashCase $}
|
||||
| bound to
|
||||
code {$ property.memberDoc.classDoc.name $}.{$ property.propertyName $}
|
||||
:markdown
|
||||
{$ property.memberDoc.description | indentForMarkdown(2) | trimBlankLines $}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if doc.outputs %}
|
||||
.l-main-section
|
||||
h2 Outputs
|
||||
.l-sub-section{% for binding, property in doc.outputs %}
|
||||
h3.output
|
||||
code {$ property.bindingName | dashCase $}
|
||||
| bound to
|
||||
code {$ property.memberDoc.classDoc.name $}.{$ property.propertyName $}
|
||||
:markdown
|
||||
{$ event.memberDoc.description | indentForMarkdown(2) | trimBlankLines $}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1 @@
|
||||
{% extends 'class.template.html' -%}
|
||||
@@ -0,0 +1,20 @@
|
||||
{% include "lib/githubLinks.html" -%}
|
||||
{% include "lib/paramList.html" -%}
|
||||
{% extends 'layout/base.template.html' -%}
|
||||
|
||||
{% block body %}
|
||||
include ../../_util-fns
|
||||
.l-main-section
|
||||
h2(class="function export")
|
||||
pre.prettyprint
|
||||
code.
|
||||
export {$ doc.name $}{$ paramList(doc.parameters) | indent(4, true) | trim $}{$ returnType(doc.returnType) $}
|
||||
|
||||
p.location-badge.
|
||||
exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} }
|
||||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{$ doc.description | indentForMarkdown(4) | trimBlankLines $}
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
{%- for item in doc.data %}
|
||||
"{$ item.name $}" : {
|
||||
"title" : "{$ item.title $}",
|
||||
{%- if item.intro %}
|
||||
"intro" : "{$ item.intro $}",
|
||||
{%- endif %}
|
||||
{%- if item.varType %}
|
||||
"varType" : "{$ item.varType $}",
|
||||
{%- endif %}
|
||||
{%- if item.originalModule %}
|
||||
"originalModule" : "{$ item.originalModule $}",
|
||||
{%- endif %}
|
||||
"docType": "{$ item.docType $}"
|
||||
}{% if not loop.last %},{% endif %}
|
||||
{% endfor -%}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{% block body %}{% endblock %}
|
||||
@@ -0,0 +1,12 @@
|
||||
{% macro paramList(params) -%}
|
||||
{%- if params -%}
|
||||
({%- for param in params -%}
|
||||
{$ param | escape $}{% if not loop.last %}, {% endif %}
|
||||
{%- endfor %})
|
||||
{%- endif %}
|
||||
{%- endmacro -%}
|
||||
|
||||
|
||||
{% macro returnType(returnType) -%}
|
||||
{%- if returnType %} : {$ returnType | escape $}{% endif -%}
|
||||
{%- endmacro -%}
|
||||
@@ -0,0 +1,16 @@
|
||||
{% include "lib/githubLinks.html" -%}
|
||||
{% extends 'layout/base.template.html' -%}
|
||||
{% block body -%}
|
||||
include ../../_util-fns
|
||||
p.location-badge.
|
||||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
ul
|
||||
for page, slug in public.docs[current.path[1]][current.path[2]][current.path[3]][current.path[4]]._data
|
||||
if slug != 'index'
|
||||
- var url = "/docs/" + current.path[1] + "/" + current.path[2] + "/" + current.path[3] + "/" + current.path[4] + "/" + slug + ".html"
|
||||
|
||||
li
|
||||
!= partial("../../../../../_includes/_hover-card", {name: page.title, url: url })
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,23 @@
|
||||
{% include "lib/githubLinks.html" -%}
|
||||
{% include "lib/paramList.html" -%}
|
||||
{% extends 'layout/base.template.html' %}
|
||||
|
||||
{% block body %}
|
||||
include ../../_util-fns
|
||||
.l-main-section
|
||||
h2(class="variable export")
|
||||
pre.prettyprint
|
||||
code.
|
||||
export {$ doc.name $}{$ returnType(doc.returnType) $}
|
||||
|
||||
p.location-badge.
|
||||
exported from {@link {$ doc.moduleDoc.id $} {$doc.moduleDoc.id $} }
|
||||
defined in {$ githubViewLink(doc) $}
|
||||
|
||||
:markdown
|
||||
{%- if doc.notYetDocumented %}
|
||||
### *Not Yet Documented*
|
||||
{% else %}
|
||||
{$ doc.description | indentForMarkdown(4) | trimBlankLines $}
|
||||
{% endif -%}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user