From bc8ad406c205a4495415a6603700aca2753b7231 Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Wed, 24 May 2017 11:04:40 -0600 Subject: [PATCH 1/4] Fix github edit link pathing --- templates/helpers.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/templates/helpers.js b/templates/helpers.js index 53f68284..12e00a70 100644 --- a/templates/helpers.js +++ b/templates/helpers.js @@ -234,16 +234,23 @@ module.exports = function(docMap, options, getCurrent, helpers, OtherHandlebars) version = version.replace(/-/g, '--'); return 'https://img.shields.io/badge/npm%20package-'+version+'-brightgreen.svg'; }, - sourceLink: function(packageObject) { - var current = docMapInfo.getCurrent(); - if (!current.src) { - return false; - } - var name = packageObject.name, - srcPath = current.src.path.replace('node_modules/' + name + '/', ''), - line = current.src.line ? '#L' + (current.src.line + 1) : ''; - return '//github.com/canjs/' + name + '/edit/master/' + srcPath + line; - }, + sourceLink: function() { + var current = docMapInfo.getCurrent(); + + if (!current.src) { + return false; + } + + var nodeModulesFolderNameRegex = /^node_modules\/([\w-]+)\/.*/, + folderNameMatches = current.src.path.match(nodeModulesFolderNameRegex), + // find repoName by picking it out of the node_modules path, or we can assume this page is in the root canjs repo + // this assumes the npm module name matches the github repository name + repoName = folderNameMatches ? folderNameMatches[1] : 'canjs', + srcPath = current.src.path.replace('node_modules/' + repoName + '/', ''), + line = current.src.line ? '#L' + (current.src.line + 1) : ''; + + return '//github.com/canjs/' + repoName + '/edit/master/' + srcPath + line; + }, customSort: function(children) { var ordered = [], sorted = []; From 26e6b1efdb6e92e01bb3e3076a93a5b84173da49 Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Wed, 24 May 2017 11:05:50 -0600 Subject: [PATCH 2/4] Simplify helper call to sourceLink --- templates/title.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/title.mustache b/templates/title.mustache index b9754833..4f36aae5 100644 --- a/templates/title.mustache +++ b/templates/title.mustache @@ -29,7 +29,7 @@ {{#with (getClosestWithPackage)}} From 92be2a65f094614b89143502b51be8ad6c662ac9 Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Wed, 24 May 2017 11:30:36 -0600 Subject: [PATCH 3/4] Fix GitHub stars shield on 'API Docs' page --- templates/helpers.js | 43 ++++++++++++++++++++++++---------------- templates/title.mustache | 10 +++++----- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/templates/helpers.js b/templates/helpers.js index 12e00a70..62e2e533 100644 --- a/templates/helpers.js +++ b/templates/helpers.js @@ -234,23 +234,32 @@ module.exports = function(docMap, options, getCurrent, helpers, OtherHandlebars) version = version.replace(/-/g, '--'); return 'https://img.shields.io/badge/npm%20package-'+version+'-brightgreen.svg'; }, - sourceLink: function() { - var current = docMapInfo.getCurrent(); - - if (!current.src) { - return false; - } - - var nodeModulesFolderNameRegex = /^node_modules\/([\w-]+)\/.*/, - folderNameMatches = current.src.path.match(nodeModulesFolderNameRegex), - // find repoName by picking it out of the node_modules path, or we can assume this page is in the root canjs repo - // this assumes the npm module name matches the github repository name - repoName = folderNameMatches ? folderNameMatches[1] : 'canjs', - srcPath = current.src.path.replace('node_modules/' + repoName + '/', ''), - line = current.src.line ? '#L' + (current.src.line + 1) : ''; - - return '//github.com/canjs/' + repoName + '/edit/master/' + srcPath + line; - }, + repoName: function() { + var current = docMapInfo.getCurrent(); + + if (!current.src) { + return false; + } + + var nodeModulesFolderNameRegex = /^node_modules\/([\w-]+)\/.*/, + folderNameMatches = current.src.path.match(nodeModulesFolderNameRegex); + + // find repoName by picking it out of the node_modules path, or we can assume this page is in the root canjs repo + // this assumes the npm module name matches the github repository name + return folderNameMatches ? folderNameMatches[1] : 'canjs'; + }, + sourceLink: function(repoName) { + var current = docMapInfo.getCurrent(); + + if (!current.src) { + return false; + } + + var srcPath = current.src.path.replace('node_modules/' + repoName + '/', ''), + line = current.src.line ? '#L' + (current.src.line + 1) : ''; + + return '//github.com/canjs/' + repoName + '/edit/master/' + srcPath + line; + }, customSort: function(children) { var ordered = [], sorted = []; diff --git a/templates/title.mustache b/templates/title.mustache index 4f36aae5..7f587504 100644 --- a/templates/title.mustache +++ b/templates/title.mustache @@ -20,16 +20,16 @@
  • - Star -
  • + Star + {{/if}} {{#with (getClosestWithPackage)}} From 133262b45a6fbb61d20d8a5259961bafcb047f76 Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Thu, 25 May 2017 10:26:59 -0600 Subject: [PATCH 4/4] Check for required input in template & don't call docMapInfo.getCurrent when you can get the variables from the template. --- templates/helpers.js | 22 +++++----------------- templates/title.mustache | 12 ++++++------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/templates/helpers.js b/templates/helpers.js index 62e2e533..d5859c09 100644 --- a/templates/helpers.js +++ b/templates/helpers.js @@ -234,29 +234,17 @@ module.exports = function(docMap, options, getCurrent, helpers, OtherHandlebars) version = version.replace(/-/g, '--'); return 'https://img.shields.io/badge/npm%20package-'+version+'-brightgreen.svg'; }, - repoName: function() { - var current = docMapInfo.getCurrent(); - - if (!current.src) { - return false; - } - + repoName: function(path) { var nodeModulesFolderNameRegex = /^node_modules\/([\w-]+)\/.*/, - folderNameMatches = current.src.path.match(nodeModulesFolderNameRegex); + folderNameMatches = path.match(nodeModulesFolderNameRegex); // find repoName by picking it out of the node_modules path, or we can assume this page is in the root canjs repo // this assumes the npm module name matches the github repository name return folderNameMatches ? folderNameMatches[1] : 'canjs'; }, - sourceLink: function(repoName) { - var current = docMapInfo.getCurrent(); - - if (!current.src) { - return false; - } - - var srcPath = current.src.path.replace('node_modules/' + repoName + '/', ''), - line = current.src.line ? '#L' + (current.src.line + 1) : ''; + sourceLink: function(src, repoName) { + var srcPath = src.path.replace('node_modules/' + repoName + '/', ''), + line = src.line ? '#L' + (src.line + 1) : ''; return '//github.com/canjs/' + repoName + '/edit/master/' + srcPath + line; }, diff --git a/templates/title.mustache b/templates/title.mustache index 7f587504..f619ffdc 100644 --- a/templates/title.mustache +++ b/templates/title.mustache @@ -20,18 +20,18 @@
  • - Star + Star
  • {{/if}} - {{#with (getClosestWithPackage)}} + {{#if src.path}} - {{/with}} + {{/if}}