From 4a1813789b80cebcd90b55071b14ecf04fee3c92 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Mon, 9 Dec 2013 17:34:15 -0500 Subject: [PATCH] getting github info needed to adapt links --- lib/adapt-links.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++++- test/links.js | 30 ++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 lib/adapt-links.js create mode 100644 test/links.js diff --git a/lib/adapt-links.js b/lib/adapt-links.js new file mode 100644 index 0000000..855ae7d --- /dev/null +++ b/lib/adapt-links.js @@ -0,0 +1,58 @@ +'use strict'; + +var resolveBranch = require('resolve-git-branch') + , resolveRemote = require('resolve-git-remote') + , asyncreduce = require('asyncreduce') + +function githubInfo(cb) { + asyncreduce( + [ [ 'remote', resolveRemote ], [ 'branch', resolveBranch ] ] + , {} + , function (acc, tuple, cb_) { + tuple[1](function (err, res) { + if (err) return cb_(err); + acc[tuple[0]] = res; + cb_(null, acc); + }); + } + , function (err, res) { + if (err) return cb(err); + res.blobRoot = 'https://github.com/' + res.remote + '/blob/' + res.branch + '/'; + cb(null, res); + } + ); +} + +var go = module.exports = function (cb) { + githubInfo(function (err, ghinfo) { + if (err) return cb(err); + + }); +}; + +// Test + +function inspect(obj, depth) { + console.error(require('util').inspect(obj, false, depth || 5, true)); +} + +if (!module.parent) { + var html = [ + '
' + , '
' + , '

Public wicked API

' + , '
' + , '
Source:
' + , '
  • ' + , ' util/helper.js, line 3' + , '
' + , '
' + , '
' + , '
'].join('\n'); + + githubInfo(function (err, res) { + if (err) return console.error(err); + inspect(res) + }); + +} diff --git a/package.json b/package.json index 07b9bbe..69089ae 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,11 @@ "url": "git://github.com/thlorenz/jsdoc-githubify.git" }, "homepage": "https://github.com/thlorenz/jsdoc-githubify", - "dependencies": {}, + "dependencies": { + "resolve-git-remote": "~0.1.1", + "resolve-git-branch": "~0.1.0", + "asyncreduce": "~0.1.4" + }, "devDependencies": { "nave": "~0.4.3", "tap": "~0.4.3", diff --git a/test/links.js b/test/links.js new file mode 100644 index 0000000..8988219 --- /dev/null +++ b/test/links.js @@ -0,0 +1,30 @@ +'use strict'; + +var test = require('tap').test + , applyTransform = require('apply-transform') + , transform = require('../') + +var html = [ + '
' + , '
' + , '

Public wicked API

' + , '
' + , '
Source:
' + , '
  • ' + , ' util/helper.js, line 3' + , '
' + , '
' + , '
' + , '
'].join('\n'); + +function inspect(obj, depth) { + console.error(require('util').inspect(obj, false, depth || 5, true)); +} + +test('\nhtml with multiple links without repo or branch override', function (t) { + applyTransform(transform(), html, function (err, res) { + if (err) { t.fail(err); return t.end() } + inspect(res.split('\n')); + t.end() + }); +})