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) {
|
2016-01-08 23:43:17 -05:00
|
|
|
// 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',
|
|
|
|
|
2015-09-18 22:51:10 -04:00
|
|
|
// 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;
|
2015-09-18 22:51:10 -04:00
|
|
|
var fragItems = [];
|
2015-08-10 14:17:02 -04:00
|
|
|
var r;
|
|
|
|
while ((r = rx.exec(content)) !== null) {
|
2015-09-18 22:51:10 -04:00
|
|
|
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
|
|
|
}
|
2016-01-08 23:43:17 -05:00
|
|
|
while ((r = rxJson.exec(content)) !== null) {
|
|
|
|
var filePaths = r[1].split(',');
|
|
|
|
filePaths.forEach(function(filePath) {
|
|
|
|
fragItems.push( { mixinPath: filePath, region: null } );
|
|
|
|
});
|
|
|
|
}
|
2015-09-18 22:51:10 -04:00
|
|
|
if (fragItems.length) {
|
2015-08-10 14:17:02 -04:00
|
|
|
return [{
|
2015-09-18 22:51:10 -04:00
|
|
|
fragItems: fragItems
|
2015-08-10 14:17:02 -04:00
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|