Skip to content

Commit

Permalink
getting github info needed to adapt links
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Dec 9, 2013
1 parent 69ab694 commit 4a18137
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
58 changes: 58 additions & 0 deletions lib/adapt-links.js
Original file line number Diff line number Diff line change
@@ -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 = [
'<article>'
, ' <div class="container-overview">'
, ' <div class="description"><p>Public wicked API</p></div>'
, '<dl class="details">'
, ' <dt class="tag-source">Source:</dt>'
, ' <dd class="tag-source"><ul class="dummy"><li>'
, ' util/helper.js, line 3'
, ' </li></ul></dd>'
, '</dl>'
, ' </div>'
, ' </article>'].join('\n');

githubInfo(function (err, res) {
if (err) return console.error(err);
inspect(res)
});

}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 30 additions & 0 deletions test/links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

var test = require('tap').test
, applyTransform = require('apply-transform')
, transform = require('../')

var html = [
'<article>'
, ' <div class="container-overview">'
, ' <div class="description"><p>Public wicked API</p></div>'
, '<dl class="details">'
, ' <dt class="tag-source">Source:</dt>'
, ' <dd class="tag-source"><ul class="dummy"><li>'
, ' util/helper.js, line 3'
, ' </li></ul></dd>'
, '</dl>'
, ' </div>'
, ' </article>'].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()
});
})

0 comments on commit 4a18137

Please sign in to comment.