build(aio): remove cheatsheet processing and content
This will be replaced by a single file migrated from angular.io
This commit is contained in:

committed by
Miško Hevery

parent
4e10faf1eb
commit
b0a7bc77ee
@ -16,7 +16,7 @@ const gitPackage = require('dgeni-packages/git');
|
||||
const linksPackage = require('../links-package');
|
||||
const examplesPackage = require('../examples-package');
|
||||
const targetPackage = require('../target-package');
|
||||
const cheatsheetPackage = require('../cheatsheet-package');
|
||||
const contentPackage = require('../content-package');
|
||||
const rhoPackage = require('../rho-package');
|
||||
|
||||
const PROJECT_ROOT = path.resolve(__dirname, '../../..');
|
||||
@ -31,7 +31,7 @@ module.exports =
|
||||
'angular.io',
|
||||
[
|
||||
jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage, examplesPackage,
|
||||
gitPackage, targetPackage, cheatsheetPackage, rhoPackage
|
||||
gitPackage, targetPackage, contentPackage, rhoPackage
|
||||
])
|
||||
|
||||
// Register the processors
|
||||
@ -110,7 +110,6 @@ module.exports =
|
||||
include: CONTENTS_PATH + '/file-not-found.md',
|
||||
fileReader: 'contentFileReader'
|
||||
},
|
||||
{basePath: CONTENTS_PATH, include: CONTENTS_PATH + '/cheatsheet/*.md'},
|
||||
{
|
||||
basePath: API_SOURCE_PATH,
|
||||
include: API_SOURCE_PATH + '/examples/**/*',
|
||||
@ -245,11 +244,6 @@ module.exports =
|
||||
pathTemplate: '${moduleDoc.moduleFolder}/${name}',
|
||||
outputPathTemplate: '${moduleDoc.moduleFolder}/${name}.json',
|
||||
},
|
||||
{
|
||||
docTypes: ['cheatsheet-data'],
|
||||
pathTemplate: GUIDE_SEGMENT + '/cheatsheet.json',
|
||||
outputPathTemplate: '${path}'
|
||||
},
|
||||
{docTypes: ['example-region'], getOutputPath: function() {}},
|
||||
{docTypes: ['content'], pathTemplate: '${id}', outputPathTemplate: '${path}.json'},
|
||||
{docTypes: ['navigation-map'], pathTemplate: '${id}', outputPathTemplate: '../${id}.json'}
|
||||
|
@ -1,16 +0,0 @@
|
||||
var Package = require('dgeni').Package;
|
||||
|
||||
module.exports = new Package(
|
||||
'cheatsheet',
|
||||
[
|
||||
require('../content-package'), require('../target-package'),
|
||||
require('dgeni-packages/git'), require('dgeni-packages/nunjucks')
|
||||
])
|
||||
|
||||
.factory(require('./services/cheatsheetItemParser'))
|
||||
.processor(require('./processors/createCheatsheetDoc'))
|
||||
|
||||
.config(function(parseTagsProcessor, getInjectables) {
|
||||
parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions.concat(
|
||||
getInjectables(require('./tag-defs')));
|
||||
});
|
@ -1,48 +0,0 @@
|
||||
var _ = require('lodash');
|
||||
|
||||
module.exports = function createCheatsheetDoc(
|
||||
createDocMessage, renderMarkdown, versionInfo, targetEnvironments) {
|
||||
return {
|
||||
$runAfter: ['processing-docs'],
|
||||
$runBefore: ['docs-processed'],
|
||||
$process: function(docs) {
|
||||
|
||||
var currentEnvironment = targetEnvironments.isActive('ts') && 'TypeScript' ||
|
||||
targetEnvironments.isActive('js') && 'JavaScript' ||
|
||||
targetEnvironments.isActive('dart') && 'Dart';
|
||||
|
||||
var cheatsheetDoc = {
|
||||
id: 'cheatsheet',
|
||||
aliases: ['cheatsheet'],
|
||||
docType: 'cheatsheet-data',
|
||||
sections: [],
|
||||
version: versionInfo,
|
||||
currentEnvironment: currentEnvironment
|
||||
};
|
||||
|
||||
docs = docs.filter(function(doc) {
|
||||
if (doc.docType === 'cheatsheet-section') {
|
||||
var section = _.pick(doc, ['name', 'description', 'items', 'index']);
|
||||
|
||||
// Let's make sure that the descriptions are rendered as markdown
|
||||
section.description = renderMarkdown(section.description);
|
||||
section.items.forEach(function(item) {
|
||||
item.description = renderMarkdown(item.description);
|
||||
});
|
||||
|
||||
|
||||
cheatsheetDoc.sections.push(section);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// Sort the sections by their index
|
||||
cheatsheetDoc.sections.sort(function(a, b) { return a.index - b.index; });
|
||||
|
||||
docs.push(cheatsheetDoc);
|
||||
|
||||
return docs;
|
||||
}
|
||||
};
|
||||
};
|
@ -1,125 +0,0 @@
|
||||
/**
|
||||
* @dgService
|
||||
* @description
|
||||
* Parse the text from a cheatsheetItem tag into a cheatsheet item object
|
||||
* The text must contain a syntax block followed by zero or more bold matchers and finally a
|
||||
* description
|
||||
* The syntax block and bold matchers must be wrapped in backticks and be separated by pipes.
|
||||
* For example
|
||||
*
|
||||
* ```
|
||||
* `<div [ng-switch]="conditionExpression">
|
||||
* <template [ng-switch-when]="case1Exp">...</template>
|
||||
* <template ng-switch-when="case2LiteralString">...</template>
|
||||
* <template ng-switch-default>...</template>
|
||||
* </div>`|`[ng-switch]`|`[ng-switch-when]`|`ng-switch-when`|`ng-switch-default`
|
||||
* Conditionally swaps the contents of the div by selecting one of the embedded templates based on
|
||||
* the current value of conditionExpression.
|
||||
* ```
|
||||
*
|
||||
* will be parsed into
|
||||
*
|
||||
* ```
|
||||
* {
|
||||
* syntax: '<div [ng-switch]="conditionExpression">\n'+
|
||||
* ' <template [ng-switch-when]="case1Exp">...</template>\n'+
|
||||
* ' <template ng-switch-when="case2LiteralString">...</template>\n'+
|
||||
* ' <template ng-switch-default>...</template>\n'+
|
||||
* '</div>',
|
||||
* bold: ['[ng-switch]', '[ng-switch-when]', 'ng-switch-when', 'ng-switch-default'],
|
||||
* description: 'Conditionally swaps the contents of the div by selecting one of the embedded
|
||||
* templates based on the current value of conditionExpression.'
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
module.exports =
|
||||
function cheatsheetItemParser(targetEnvironments) {
|
||||
return function(text) {
|
||||
var fields = getFields(text, ['syntax', 'description']);
|
||||
|
||||
var item = {syntax: '', bold: [], description: ''};
|
||||
|
||||
fields.forEach(function(field) {
|
||||
if (!field.languages || targetEnvironments.someActive(field.languages)) {
|
||||
switch (field.name) {
|
||||
case 'syntax':
|
||||
parseSyntax(field.value.trim());
|
||||
break;
|
||||
case 'description':
|
||||
item.description = field.value.trim();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return item;
|
||||
|
||||
function parseSyntax(text) {
|
||||
var index = 0;
|
||||
|
||||
if (text.charAt(index) !== '`') throw new Error('item syntax must start with a backtick');
|
||||
|
||||
var start = index + 1;
|
||||
index = text.indexOf('`', start);
|
||||
if (index === -1) throw new Error('item syntax must end with a backtick');
|
||||
item.syntax = text.substring(start, index);
|
||||
start = index + 1;
|
||||
|
||||
// skip to next pipe
|
||||
while (index < text.length && text.charAt(index) !== '|') index += 1;
|
||||
|
||||
while (text.charAt(start) === '|') {
|
||||
start += 1;
|
||||
|
||||
// skip whitespace
|
||||
while (start < text.length && /\s/.test(text.charAt(start))) start++;
|
||||
|
||||
if (text.charAt(start) !== '`') throw new Error('bold matcher must start with a backtick');
|
||||
|
||||
start += 1;
|
||||
index = text.indexOf('`', start);
|
||||
if (index === -1) throw new Error('bold matcher must end with a backtick');
|
||||
item.bold.push(text.substring(start, index));
|
||||
start = index + 1;
|
||||
}
|
||||
|
||||
if (start !== text.length) {
|
||||
throw new Error(
|
||||
'syntax field must only contain a syntax code block and zero or more bold ' +
|
||||
'matcher code blocks, delimited by pipes.\n' +
|
||||
'Instead it was "' + text + '"');
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function getFields(text, fieldNames) {
|
||||
var FIELD_START = /^([^:(]+)\(?([^)]+)?\)?:$/;
|
||||
var lines = text.split('\n');
|
||||
var fields = [];
|
||||
var field, line;
|
||||
while (lines.length) {
|
||||
line = lines.shift();
|
||||
var match = FIELD_START.exec(line);
|
||||
if (match && fieldNames.indexOf(match[1]) !== -1) {
|
||||
// start new field
|
||||
if (field) {
|
||||
fields.push(field);
|
||||
}
|
||||
field = {name: match[1], languages: (match[2] && match[2].split(' ')), value: ''};
|
||||
} else {
|
||||
if (!field)
|
||||
throw new Error(
|
||||
'item must start with one of the following field specifiers:\n' +
|
||||
fieldNames.map(function(field) { return field + ':'; }).join('\n') + '\n' +
|
||||
'but instead it contained: "' + text + '"');
|
||||
field.value += line + '\n';
|
||||
}
|
||||
}
|
||||
if (field) {
|
||||
fields.push(field);
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
var testPackage = require('../../helpers/test-package');
|
||||
var Dgeni = require('dgeni');
|
||||
|
||||
describe('cheatsheetItemParser', function() {
|
||||
var dgeni, injector, cheatsheetItemParser;
|
||||
|
||||
beforeEach(function() {
|
||||
dgeni = new Dgeni([testPackage('cheatsheet-package')]);
|
||||
injector = dgeni.configureInjector();
|
||||
cheatsheetItemParser = injector.get('cheatsheetItemParser');
|
||||
var targetEnvironments = injector.get('targetEnvironments');
|
||||
targetEnvironments.addAllowed('js');
|
||||
targetEnvironments.addAllowed('ts', true);
|
||||
});
|
||||
|
||||
describe('no language targets', function() {
|
||||
it('should extract the syntax', function() {
|
||||
expect(cheatsheetItemParser('syntax:\n`abc`'))
|
||||
.toEqual({syntax: 'abc', bold: [], description: ''});
|
||||
});
|
||||
|
||||
it('should extract the bolds', function() {
|
||||
expect(cheatsheetItemParser('syntax:\n`abc`|`bold1`|`bold2`'))
|
||||
.toEqual({syntax: 'abc', bold: ['bold1', 'bold2'], description: ''});
|
||||
});
|
||||
|
||||
it('should extract the description', function() {
|
||||
expect(cheatsheetItemParser('syntax:\n`abc`|`bold1`|`bold2`\ndescription:\nsome description'))
|
||||
.toEqual({syntax: 'abc', bold: ['bold1', 'bold2'], description: 'some description'});
|
||||
});
|
||||
|
||||
it('should allow bold to be optional', function() {
|
||||
expect(cheatsheetItemParser('syntax:\n`abc`\ndescription:\nsome description'))
|
||||
.toEqual({syntax: 'abc', bold: [], description: 'some description'});
|
||||
});
|
||||
|
||||
it('should allow whitespace between the parts', function() {
|
||||
expect(cheatsheetItemParser(
|
||||
'syntax:\n`abc`| `bold1`| `bold2`\ndescription:\n\nsome description'))
|
||||
.toEqual({syntax: 'abc', bold: ['bold1', 'bold2'], description: 'some description'});
|
||||
});
|
||||
});
|
||||
|
||||
describe('with language targets', function() {
|
||||
it('should extract the active language', function() {
|
||||
expect(cheatsheetItemParser(
|
||||
'syntax(ts):\n`abc`|`bold1`|`bold2`\ndescription(ts):\nsome description'))
|
||||
.toEqual({syntax: 'abc', bold: ['bold1', 'bold2'], description: 'some description'});
|
||||
});
|
||||
|
||||
it('should ignore the non-active language', function() {
|
||||
expect(cheatsheetItemParser(
|
||||
'syntax(js):\n`abc`|`bold1`|`bold2`\ndescription(js):\nsome description'))
|
||||
.toEqual({syntax: '', bold: [], description: ''});
|
||||
});
|
||||
|
||||
it('should select the active language and ignore non-active language', function() {
|
||||
expect(cheatsheetItemParser(
|
||||
'syntax(js):\n`JS`|`boldJS``\n' +
|
||||
'syntax(ts):\n`TS`|`boldTS`\n' +
|
||||
'description(js):\nJS description\n' +
|
||||
'description(ts):\nTS description'))
|
||||
.toEqual({syntax: 'TS', bold: ['boldTS'], description: 'TS description'});
|
||||
});
|
||||
|
||||
it('should error if a language target is used that is not allowed', function() {
|
||||
expect(function() {
|
||||
cheatsheetItemParser(
|
||||
'syntax(dart):\n`abc`|`bold1`|`bold2`\ndescription(ts):\nsome description');
|
||||
})
|
||||
.toThrowError(
|
||||
'Error accessing target "dart". It is not in the list of allowed targets: js,ts');
|
||||
});
|
||||
});
|
||||
});
|
@ -1,14 +0,0 @@
|
||||
module.exports = function(createDocMessage) {
|
||||
return {
|
||||
name: 'cheatsheetIndex',
|
||||
docProperty: 'index',
|
||||
transforms: function(doc, tag, value) {
|
||||
try {
|
||||
return parseInt(value, 10);
|
||||
} catch (x) {
|
||||
throw new Error(
|
||||
createDocMessage('"@' + tag.tagName + '" must be followed by a number', doc));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
@ -1,15 +0,0 @@
|
||||
module.exports = function(createDocMessage, cheatsheetItemParser) {
|
||||
return {
|
||||
name: 'cheatsheetItem',
|
||||
multi: true,
|
||||
docProperty: 'items',
|
||||
transforms: function(doc, tag, value) {
|
||||
try {
|
||||
return cheatsheetItemParser(value);
|
||||
} catch (x) {
|
||||
throw new Error(createDocMessage(
|
||||
'"@' + tag.tagName + '" tag has an invalid format - ' + x.message, doc));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
@ -1,10 +0,0 @@
|
||||
module.exports = function() {
|
||||
return {
|
||||
name: 'cheatsheetSection',
|
||||
docProperty: 'docType',
|
||||
transforms: function(doc, tag, value) {
|
||||
doc.name = value ? value.trim() : '';
|
||||
return 'cheatsheet-section';
|
||||
}
|
||||
};
|
||||
};
|
@ -1,2 +0,0 @@
|
||||
module.exports =
|
||||
[require('./cheatsheet-section'), require('./cheatsheet-index'), require('./cheatsheet-item')];
|
Reference in New Issue
Block a user