diff --git a/docs/helpers.md b/docs/helpers.md
index 5bf4d07..8d86b7f 100644
--- a/docs/helpers.md
+++ b/docs/helpers.md
@@ -24,6 +24,7 @@ Default Handlebars-helpers for Thought
* [.hasCoveralls()](#helpers.hasCoveralls) ⇒ boolean
* [.hasGreenkeeper(options)](#helpers.hasGreenkeeper)
* [.github(filePath)](#helpers.github) ⇒ string
+ * [.repoWebUrl(gitUrl)](#helpers.repoWebUrl)
* [.githubRepo()](#helpers.githubRepo) ⇒ string
* [.arr(...args)](#helpers.arr)
@@ -274,6 +275,19 @@ set correctly in package.json
| --- | --- | --- |
| filePath | string
| the path to the file |
+
+
+### helpers.repoWebUrl(gitUrl)
+Returns the http-url for viewing a git-repository in the browser given a repo-url from the package.json
+Currently, only github urls are supported
+
+**Kind**: static method of [helpers
](#helpers)
+**Access**: public
+
+| Param | Type | Description |
+| --- | --- | --- |
+| gitUrl | string
| the git url from the repository.url-property of package.json |
+
### helpers.githubRepo() ⇒ string
diff --git a/handlebars/helpers/index.js b/handlebars/helpers/index.js
index 5326869..fa568d2 100644
--- a/handlebars/helpers/index.js
+++ b/handlebars/helpers/index.js
@@ -31,6 +31,7 @@ module.exports = {
withPackageOf,
github,
githubRepo,
+ repoWebUrl,
npm,
htmlId,
hasCoveralls,
@@ -380,7 +381,7 @@ function transformTree (object, fn) {
* @memberOf helpers
*/
function github (filePath) {
- // Build url to correct version and file in github
+ // Build url to correct version and file in githubs
const packageJson = findPackage(path.resolve(filePath), true)
const url = packageJson && packageJson.repository && packageJson.repository.url
if (url && url.match(/github.com/)) {
@@ -391,6 +392,25 @@ function github (filePath) {
}
}
+/**
+ * Returns the http-url for viewing a git-repository in the browser given a repo-url from the package.json
+ * Currently, only github urls are supported
+ * @param {string} gitUrl the git url from the repository.url-property of package.json
+ * @access public
+ * @memberOf helpers
+ */
+function repoWebUrl (gitUrl) {
+ if (!gitUrl) {
+ return undefined
+ }
+ const match = gitUrl.match(/.*?(:\/\/|@)github\.com[/:](.*?)(#.*?)?$/)
+ if (match) {
+ return 'https://github.com/' + match[2].replace(/\.git$/, '')
+ } else {
+ return null
+ }
+}
+
/**
* Returns the current repository group and name (e.g. `nknapp/thought` for this project)
*
diff --git a/test/helper-spec.js b/test/helper-spec.js
index bacc60a..0f86c25 100644
--- a/test/helper-spec.js
+++ b/test/helper-spec.js
@@ -543,4 +543,11 @@ describe('thought-helpers:', function () {
return expectHbs("{{#each (arr 'a' 'b' 'c')}}v:{{.}} {{/each}}", {}).to.eventually.equal('v:a v:b v:c')
})
})
+
+ describe('The "repoWebUrl" helper', function () {
+ it('should return a github-web-url for a github-ssh-url', function () {
+ return expect(helpers.repoWebUrl('git+ssh://git@github.com/nknapp/thought-plugin-jsdoc.git'))
+ .to.equal('https://github.com/nknapp/thought-plugin-jsdoc')
+ })
+ })
})