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

45 lines
1.3 KiB
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) {
// regexs for makeTabs. makeExample and makeJson lines
var rx = /\s*\+make(?:=Tabs|Example)\(\s*["'](.*?)["']\s*,\s*["'](.*?)["'].*?\)/g
var rxJson = /\s*\+makeJson\(\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
}
while ((r = rxJson.exec(content)) !== null) {
var filePaths = r[1].split(',');
filePaths.forEach(function(filePath) {
fragItems.push( { mixinPath: filePath, region: null } );
});
}
if (fragItems.length) {
2015-08-10 14:17:02 -04:00
return [{
fragItems: fragItems
2015-08-10 14:17:02 -04:00
}];
} else {
return [];
}
}
}
}