angular-docs-cn/tools/doc-shredder/fileReaders/extractPathsReader.js

38 lines
998 B
JavaScript
Raw Normal View History

2015-08-10 14:17:02 -04:00
/**
2015-08-11 03:27:09 -04:00
* @dgService extractPathsReader
2015-08-10 14:17:02 -04:00
* @description
*/
var path = require('canonical-path');
module.exports = function extractPathsReader(log) {
2015-08-11 03:27:09 -04:00
// regex for makeTabs line
var rx = /\s*\+make(?:=Tabs|Example|Json)\(\s*["'](.*?)["']\s*,\s*["'](.*?)["'].*?\)/g
2015-08-10 14:17:02 -04:00
return {
name: 'extractPathsReader',
// returns the fragment filePath without the _fragments dir on the front or the '.md'
2015-08-10 14:17:02 -04:00
getDocs: function (fileInfo) {
var content = fileInfo.content;
var fragItems = [];
2015-08-10 14:17:02 -04:00
var r;
while ((r = rx.exec(content)) !== null) {
var filePaths = r[1].split(',');
var regions = (r.length > 2) ? r[2].split(",") : null;
filePaths.forEach(function(filePath, ix) {
var region = regions && regions[ix];
fragItems.push( { mixinPath: filePath, region: region } );
});
2015-08-10 14:17:02 -04:00
}
if (fragItems.length) {
2015-08-10 14:17:02 -04:00
return [{
fragItems: fragItems
2015-08-10 14:17:02 -04:00
}];
} else {
return [];
}
}
}
}