-
Notifications
You must be signed in to change notification settings - Fork 875
chore: fix "Invalid example" warnings from shred map builder #1832
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
!= partial("../glossary") | ||
include ../glossary |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
!= partial("../glossary") | ||
include ../glossary |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,25 +18,37 @@ module.exports = function shredMapProcessor(log, createDocMessage) { | |
var fragToJadeMap = {}; | ||
|
||
docs.forEach(function(doc) { | ||
var jadePath = path.join(options.jadeDir, doc.fileInfo.relativePath); | ||
var relativePath = doc.fileInfo.relativePath; | ||
var jadePath = path.join(options.jadeDir, relativePath); | ||
var lang = relativePath.substr(0, relativePath.indexOf('\/')); | ||
var appProjDirName = jadeBaseFileNameToExampleName(doc.fileInfo.baseName); | ||
var fragInfoSet = {}; | ||
doc.fragItems.forEach(function(fragItem) { | ||
var mixinPath = fragItem.mixinPath; | ||
var fullExamplePath; | ||
// Normalize mixinPath: strip out optional trailing '(...)' | ||
var mixinPath = mixinPath.replace(/ \([^\)]*\)/,''); | ||
if ( mixinPath.indexOf('_api') >= 0) { | ||
var sourcePath = mixinPath.replace('_api/',''); | ||
fullExamplePath = path.join(options.apiExamplesDir, sourcePath); | ||
} else { | ||
fullExamplePath = path.join(options.devguideExamplesDir, mixinPath); | ||
} | ||
var region = fragItem.region ? "-" + fragItem.region : ''; | ||
var extn = path.extname(mixinPath); | ||
var basename = path.basename(mixinPath, extn); | ||
var fragDir = path.dirname(mixinPath); | ||
var fragPath = path.join(fragDir, basename + region + extn) + '.md'; | ||
var fullFragPath = path.join(options.fragmentsDir, fragPath); | ||
|
||
var fragInfo = { fragPath: fullFragPath, examplePath: fullExamplePath, exists: fs.existsSync(fullFragPath) }; | ||
var fragInfo = makeFragInfo(options.fragmentsDir, fullExamplePath, fragItem, mixinPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what the consequences of this (and similar changes) are for the way we write examples in Jade? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has no impact on how we write the Jade, but it allows the shred xref mapper to make sense of the abbreviated +makeExample('app/hero.service.ts') vs the original long form: +makeExample('router/ts/app/main.1.ts','all', 'main.ts')(format=".") Does that answer your question? |
||
if (!fragInfo.exists) { | ||
var savedFragInfo = fragInfo; | ||
// Assume that mixinPath is actually app-project-folder relative and | ||
// prepend "lang/appProjDirName": | ||
var appProjRelPath = mixinPath; | ||
mixinPath = appProjDirName + '/' + lang + '/' + mixinPath; | ||
fragInfo = makeFragInfo(options.fragmentsDir, fullExamplePath, fragItem, mixinPath); | ||
if (fragInfo.exists) { | ||
log.info('Ajusted example path (' + doc.fileInfo.baseName + '): ' + appProjRelPath + ' -> ' + mixinPath); | ||
} else { | ||
fragInfo = savedFragInfo; | ||
} | ||
} | ||
var fragPath = fragInfo.relFragPath; | ||
fragInfoSet[fragPath] = fragInfo; | ||
if (fragInfo.exists) { | ||
var jadePathsSet = fragToJadeMap[fragPath]; | ||
|
@@ -46,7 +58,7 @@ module.exports = function shredMapProcessor(log, createDocMessage) { | |
} | ||
jadePathsSet[jadePath] = jadePath; | ||
} else { | ||
var relativePath = path.relative(".", fullFragPath); | ||
var relativePath = path.relative(".", fragInfo.fragPath); | ||
log.warn(createDocMessage('Invalid example (unable to locate fragment file: "' + relativePath + '")', doc)); | ||
} | ||
}); | ||
|
@@ -82,13 +94,24 @@ module.exports = function shredMapProcessor(log, createDocMessage) { | |
} | ||
}; | ||
|
||
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; | ||
} | ||
// TODO: use the functionality in public/resources/js/util.js once it lands. | ||
function jadeBaseFileNameToExampleName(name) { | ||
// Adjust for known cases where chapter name is not the example name. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of a PITA I know. I wanted to fix the folders so we didn't have the discrepancy that requires this hack. That would mean adding firebase rewrite rules to handle external links. Sigh. I guess this gets it done. But it adds technical debt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. |
||
var matches = name.match(/(toh-)pt(\d+)/); | ||
if (matches) name = matches[1] + matches[2]; | ||
return name; | ||
} | ||
|
||
function makeFragInfo(fragmentsDir, fullExamplePath, fragItem, mixinPath) { | ||
var region = fragItem.region ? "-" + fragItem.region : ''; | ||
var extn = path.extname(mixinPath); | ||
var basename = path.basename(mixinPath, extn); | ||
var fragDir = path.dirname(mixinPath); | ||
var fragPath = path.join(fragDir, basename + region + extn) + '.md'; | ||
var fullFragPath = path.join(fragmentsDir, fragPath); | ||
return { | ||
fragPath: fullFragPath, | ||
relFragPath: fragPath, | ||
examplePath: fullExamplePath, | ||
exists: fs.existsSync(fullFragPath) }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why removing
(format='')
here and elsewhere in this file?Not against it. Just wondering why the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer: because it has no effect
code-example
(see the source).Longer answer: this idiom comes from the
makeExample
mixin (where it prevents the default behavior of turning on line numbers if there is more than one line). But is has no utility when applied directly tocode-example
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, something has changed.
code-example
_used to_ display line numbers by default.Now the default is no line numbers. If you want them you have to add them explicitly as in:
I wonder when this change took place? Not that I'm objecting.