clean up regionExtractor to hoist nullLine pattern,

add examplesDir to xref info
This commit is contained in:
Jay Traband 2015-08-11 11:55:22 -07:00
parent 64ea3b6f9a
commit 903f59b8ee
8 changed files with 108 additions and 65 deletions

View File

@ -1,4 +1,8 @@
module.exports = function regionExtractor() { module.exports = function regionExtractor() {
var nullLine = '###';
var nullLinePattern = new RegExp(nullLine + '\n', 'g');
// split out each fragment in {content} into a separate doc // split out each fragment in {content} into a separate doc
// a fragment is a section of text surrounded by // a fragment is a section of text surrounded by
// 1) In front: a comment marker followed by '#docregion' followed by an optional region name. For example: // 1) In front: a comment marker followed by '#docregion' followed by an optional region name. For example:
@ -12,7 +16,6 @@ module.exports = function regionExtractor() {
var docs = []; var docs = [];
var docStack = []; var docStack = [];
var doc = null; var doc = null;
var nullLine = '###';
lines.forEach(function(line, ix) { lines.forEach(function(line, ix) {
if (isCommentLine(line, commentPrefixes)) { if (isCommentLine(line, commentPrefixes)) {
@ -29,7 +32,7 @@ module.exports = function regionExtractor() {
} }
}); });
var rx = new RegExp(nullLine + '\n', 'g');
docs.forEach(function(doc) { docs.forEach(function(doc) {
var content; var content;
if (doc.endIx) { if (doc.endIx) {
@ -38,7 +41,7 @@ module.exports = function regionExtractor() {
content = lines.slice(doc.startIx + 1).join('\n'); content = lines.slice(doc.startIx + 1).join('\n');
} }
// eliminate all #docregion lines // eliminate all #docregion lines
content = content.replace(rx, ''); content = content.replace(nullLinePattern, '');
if (content.substr(-3) === nullLine) { if (content.substr(-3) === nullLine) {
content = content.substr(0, content.length-3); content = content.substr(0, content.length-3);
} }

View File

@ -15,12 +15,15 @@ module.exports = function shredMapProcessor(log) {
var options = this.options; var options = this.options;
var jadeToFragMap = {}; var jadeToFragMap = {};
var fragToJadeMap = {}; var fragToJadeMap = {};
docs.forEach(function(doc) { docs.forEach(function(doc) {
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath); var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath);
var fragInfos = doc.fragPaths.map(function(fragPath) { var fragInfos = doc.fragPaths.map(function(fragPath) {
fragPath = path.join(options.fragmentsDir, fragPath) + '.md'; var relativeFragPath = path.join(options.fragmentsDir, fragPath) + '.md';
var fullPath = path.join(options.basePath, fragPath); var fullPath = path.join(options.basePath, relativeFragPath);
var fragInfo = { fragPath: fragPath, exists: fs.existsSync(fullPath) }; var examplePath = getExampleName(fragPath);
var relativeExamplePath = path.join(options.examplesDir, examplePath);
var fragInfo = { fragPath: relativeFragPath, examplePath: relativeExamplePath, exists: fs.existsSync(fullPath) };
if (fragInfo.exists) { if (fragInfo.exists) {
var jadePaths = fragToJadeMap[fragInfo]; var jadePaths = fragToJadeMap[fragInfo];
if (!jadePaths) { if (!jadePaths) {
@ -55,3 +58,14 @@ module.exports = function shredMapProcessor(log) {
} }
}; };
}; };
function getExampleName(fragPath) {
// pattern to isolate base fileName and extension from fragment name
var rx = /(.*)\-(.*)\.(.s)/;
var r = rx.exec(fragPath);
if (r) {
return r[1] + '.' + r[3];
} else {
return fragPath;
}
}

View File

@ -4,7 +4,7 @@
<ol> <ol>
<li> <li>
Fragment file: <strong>test_fragments/gettingstarted/ts/index.html.md</strong> Fragment file: <strong>gettingstarted/ts/index.html</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>test_jade/guides/setupAlt2.jade</li> <li>test_jade/guides/setupAlt2.jade</li>
@ -12,7 +12,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>test_fragments/gettingstarted/js/index.html.md</strong> Fragment file: <strong>gettingstarted/js/index.html</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>test_jade/setupAlt.jade</li> <li>test_jade/setupAlt.jade</li>
@ -20,7 +20,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>test_fragments/gettingstarted/ts/main.ts.md</strong> Fragment file: <strong>gettingstarted/ts/main.ts</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>test_jade/setupAlt.jade</li> <li>test_jade/setupAlt.jade</li>
@ -28,7 +28,15 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>test_fragments/gettingstarted/ts/main-import.ts.md</strong> Fragment file: <strong>gettingstarted/js/main.js</strong>
<p>Jade files</p>
<ul>
<li>test_jade/guides/setupAlt2.jade</li>
</ul>
<br>
</li>
<li>
Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>test_jade/setupAlt.jade</li> <li>test_jade/setupAlt.jade</li>

View File

@ -6,14 +6,14 @@
<li> <li>
Jade file: <strong>test_jade/guides/setupAlt2.jade</strong> Jade file: <strong>test_jade/guides/setupAlt2.jade</strong>
<p>Fragment files</p> <p>Fragment files</p>
<ul><li>test_fragments/gettingstarted/ts/index.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/ js/main.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li> <ul><li>test_fragments/gettingstarted/ts/index.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li>test_fragments/gettingstarted/js/main.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
</ul> </ul>
<br> <br>
</li> </li>
<li> <li>
Jade file: <strong>test_jade/setupAlt.jade</strong> Jade file: <strong>test_jade/setupAlt.jade</strong>
<p>Fragment files</p> <p>Fragment files</p>
<ul><li> *** NOT FOUND*** : test_fragments/gettingstarted/ts/index2.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/ js/main2.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li> <ul><li> *** NOT FOUND*** : test_fragments/gettingstarted/ts/index2.html.md</li><li>test_fragments/gettingstarted/js/index.html.md</li><li>test_fragments/gettingstarted/ts/main.ts.md</li><li> *** NOT FOUND*** : test_fragments/gettingstarted/js/main2.js.md</li><li>test_fragments/gettingstarted/ts/main-import.ts.md</li>
</ul> </ul>
<br> <br>
</li> </li>

View File

@ -1,46 +1,59 @@
{ {
"basePath": "c:/GitHub/angular.io.ideablade/public/doc-shredder/test",
"jadeToFragMap": {
"test_jade/guides/setupAlt2.jade": [ "test_jade/guides/setupAlt2.jade": [
{ {
"fragPath": "test_fragments/gettingstarted/ts/index.html.md", "fragPath": "test_fragments/gettingstarted/ts/index.html.md",
"examplePath": "test_source/gettingstarted/ts/index.html",
"exists": true "exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/js/index.html.md", "fragPath": "test_fragments/gettingstarted/js/index.html.md",
"examplePath": "test_source/gettingstarted/js/index.html",
"exists": true "exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md", "fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true "exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ js/main.js.md", "fragPath": "test_fragments/gettingstarted/js/main.js.md",
"exists": false "examplePath": "test_source/gettingstarted/js/main.js",
"exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md", "fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true "exists": true
} }
], ],
"test_jade/setupAlt.jade": [ "test_jade/setupAlt.jade": [
{ {
"fragPath": "test_fragments/gettingstarted/ts/index2.html.md", "fragPath": "test_fragments/gettingstarted/ts/index2.html.md",
"examplePath": "test_source/gettingstarted/ts/index2.html",
"exists": false "exists": false
}, },
{ {
"fragPath": "test_fragments/gettingstarted/js/index.html.md", "fragPath": "test_fragments/gettingstarted/js/index.html.md",
"examplePath": "test_source/gettingstarted/js/index.html",
"exists": true "exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ts/main.ts.md", "fragPath": "test_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true "exists": true
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ js/main2.js.md", "fragPath": "test_fragments/gettingstarted/js/main2.js.md",
"examplePath": "test_source/gettingstarted/js/main2.js",
"exists": false "exists": false
}, },
{ {
"fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md", "fragPath": "test_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "test_source/gettingstarted/ts/main.ts",
"exists": true "exists": true
} }
] ]
}
} }

View File

@ -1,10 +1,10 @@
<h1> Frament path to jade path cross reference report <h1> Frament path to jade path cross reference report
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p> <p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
<ol> <ol>
<li> <li>
Fragment file: <strong>_fragments/gettingstarted/ts/index.html.md</strong> Fragment file: <strong>gettingstarted/ts/index.html</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>js/latest/guide/setupAlt.jade</li> <li>js/latest/guide/setupAlt.jade</li>
@ -12,7 +12,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>_fragments/gettingstarted/js/index.html.md</strong> Fragment file: <strong>gettingstarted/js/index.html</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>js/latest/guide/setupAlt.jade</li> <li>js/latest/guide/setupAlt.jade</li>
@ -20,7 +20,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>_fragments/gettingstarted/ts/main.ts.md</strong> Fragment file: <strong>gettingstarted/ts/main.ts</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>js/latest/guide/setupAlt.jade</li> <li>js/latest/guide/setupAlt.jade</li>
@ -28,7 +28,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>_fragments/gettingstarted/js/main.js.md</strong> Fragment file: <strong>gettingstarted/js/main.js</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>js/latest/guide/setupAlt.jade</li> <li>js/latest/guide/setupAlt.jade</li>
@ -36,7 +36,7 @@
<br> <br>
</li> </li>
<li> <li>
Fragment file: <strong>_fragments/gettingstarted/ts/main-import.ts.md</strong> Fragment file: <strong>gettingstarted/ts/main-import.ts</strong>
<p>Jade files</p> <p>Jade files</p>
<ul> <ul>
<li>js/latest/guide/setupAlt.jade</li> <li>js/latest/guide/setupAlt.jade</li>

View File

@ -1,6 +1,6 @@
<h1> Jade path to fragment path cross reference report <h1> Jade path to fragment path cross reference report
<p>Base path: c:\GitHub\angular.io.ideablade\public\docs</p> <p>Base path: C:\GitHub\angular.io.ideablade\public\docs</p>
<ol> <ol>
<li> <li>

View File

@ -1,25 +1,30 @@
{ {
"basePath": "c:\\GitHub\\angular.io.ideablade\\public\\docs", "basePath": "C:\\GitHub\\angular.io.ideablade\\public\\docs",
"jadeToFragMap": { "jadeToFragMap": {
"js/latest/guide/setupAlt.jade": [ "js/latest/guide/setupAlt.jade": [
{ {
"fragPath": "_fragments/gettingstarted/ts/index.html.md", "fragPath": "_fragments/gettingstarted/ts/index.html.md",
"examplePath": "_examples/gettingstarted/ts/index.html",
"exists": true "exists": true
}, },
{ {
"fragPath": "_fragments/gettingstarted/js/index.html.md", "fragPath": "_fragments/gettingstarted/js/index.html.md",
"examplePath": "_examples/gettingstarted/js/index.html",
"exists": true "exists": true
}, },
{ {
"fragPath": "_fragments/gettingstarted/ts/main.ts.md", "fragPath": "_fragments/gettingstarted/ts/main.ts.md",
"examplePath": "_examples/gettingstarted/ts/main.ts",
"exists": true "exists": true
}, },
{ {
"fragPath": "_fragments/gettingstarted/js/main.js.md", "fragPath": "_fragments/gettingstarted/js/main.js.md",
"examplePath": "_examples/gettingstarted/js/main.js",
"exists": true "exists": true
}, },
{ {
"fragPath": "_fragments/gettingstarted/ts/main-import.ts.md", "fragPath": "_fragments/gettingstarted/ts/main-import.ts.md",
"examplePath": "_examples/gettingstarted/ts/main.ts",
"exists": true "exists": true
} }
] ]