build(aio): support guide authoring

This commit implements various tags, inline tags and changes the markdown
renderer to use Rho. This enables us to generate guide type documents.
This commit is contained in:
Peter Bacon Darwin
2017-02-02 08:19:20 +00:00
committed by Igor Minar
parent 470997ebb9
commit 12f03b90fd
18 changed files with 315 additions and 44 deletions

View File

@ -22,22 +22,27 @@ module.exports = function exampleInlineTagDef(
handler: function(doc, tagName, tagDescription) {
const EXAMPLES_FOLDER = collectExamples.exampleFolders[0];
const EXAMPLES_FOLDERS = collectExamples.exampleFolders;
var tagArgs = parseArgString(entities.decodeHTML(tagDescription));
var unnamedArgs = tagArgs._;
var relativePath = unnamedArgs[0];
var regionName = tagArgs.region || (unnamedArgs.length > 1 ? unnamedArgs[1] : null);
var regionName = tagArgs.region || (unnamedArgs.length > 1 ? unnamedArgs[1] : '');
var title = tagArgs.title || (unnamedArgs.length > 2 ? unnamedArgs[2] : null);
var stylePattern = tagArgs.stylePattern; // TODO: not yet implemented here
var exampleFile = exampleMap[EXAMPLES_FOLDER][relativePath];
// Find the example in the folders
var exampleFile;
EXAMPLES_FOLDERS.some(
EXAMPLES_FOLDER => { return exampleFile = exampleMap[EXAMPLES_FOLDER][relativePath]; });
if (!exampleFile) {
log.error(
createDocMessage('Missing example file... relativePath: "' + relativePath + '".', doc));
log.error(
'Example files available are:', Object.keys(exampleMap[EXAMPLES_FOLDER]).join('\n'));
'Example files available are:',
EXAMPLES_FOLDERS.map(
EXAMPLES_FOLDER => Object.keys(exampleMap[EXAMPLES_FOLDER]).join('\n')));
return '';
}

View File

@ -42,19 +42,24 @@ function regionParserImpl(contents, fileType) {
// start region processing
if (startRegion) {
// open up the specified region
const regionName = getRegionName(startRegion[1]);
const region = regionMap[regionName];
if (region) {
if (region.open) {
throw new RegionParserError(
`Tried to open a region, named "${regionName}", that is already open`, index);
}
region.open = true;
region.lines.push(plaster);
} else {
regionMap[regionName] = {lines: [], open: true};
const regionNames = getRegionNames(startRegion[1]);
if (regionNames.length === 0) {
regionNames.push('');
}
openRegions.push(regionName);
regionNames.forEach(regionName => {
const region = regionMap[regionName];
if (region) {
if (region.open) {
throw new RegionParserError(
`Tried to open a region, named "${regionName}", that is already open`, index);
}
region.open = true;
region.lines.push(plaster);
} else {
regionMap[regionName] = {lines: [], open: true};
}
openRegions.push(regionName);
});
// end region processing
} else if (endRegion) {
@ -62,14 +67,20 @@ function regionParserImpl(contents, fileType) {
throw new RegionParserError('Tried to close a region when none are open', index);
}
// close down the specified region (or most recent if no name is given)
const regionName = getRegionName(endRegion[1]) || openRegions[openRegions.length - 1];
const region = regionMap[regionName];
if (!region || !region.open) {
throw new RegionParserError(
`Tried to close a region, named "${regionName}", that is not open`, index);
const regionNames = getRegionNames(endRegion[1]);
if (regionNames.length === 0) {
regionNames.push(openRegions[openRegions.length - 1]);
}
region.open = false;
removeLast(openRegions, regionName);
regionNames.forEach(regionName => {
const region = regionMap[regionName];
if (!region || !region.open) {
throw new RegionParserError(
`Tried to close a region, named "${regionName}", that is not open`, index);
}
region.open = false;
removeLast(openRegions, regionName);
});
// doc plaster processing
} else if (updatePlaster) {
@ -94,8 +105,8 @@ function regionParserImpl(contents, fileType) {
}
}
function getRegionName(input) {
return input.trim();
function getRegionNames(input) {
return input.split(',').map(name => name.trim()).filter(name => name.length > 0);
}
function removeLast(array, item) {

View File

@ -70,6 +70,11 @@ describe('regionParser service', () => {
expect(output.regions['Y']).toEqual(t('ghi'));
});
it('should open a region with a null name if there is no region name', () => {
const output = regionParser(t('/* #docregion */', 'abc', '/* #enddocregion */'), 'test-type');
expect(output.regions['']).toEqual('abc');
});
it('should close the most recently opened region if there is no region name', () => {
const output = regionParser(
t('/* #docregion X*/', 'abc', '/* #docregion Y */', 'def', '/* #enddocregion */', 'ghi',
@ -136,6 +141,16 @@ describe('regionParser service', () => {
expect(output.regions['']).toEqual(t('abc', '/* . . . */', 'ghi'));
expect(output.regions['A']).toEqual(t('jkl', '/* ... elided ... */', 'pqr'));
});
it('should parse multiple region names separated by commas', () => {
const output = regionParser(
t('/* #docregion , A, B */', 'abc', '/* #enddocregion B */', '/* #docregion C */', 'xyz',
'/* #enddocregion A, C, */'),
'test-type');
expect(output.regions['A']).toEqual(t('abc', 'xyz'));
expect(output.regions['B']).toEqual(t('abc'));
expect(output.regions['C']).toEqual(t('xyz'));
})
});
function t() {