├── test
├── fixtures
│ ├── require.coffee
│ ├── require.js
│ ├── bower.json
│ ├── composer.json
│ ├── package.json
│ ├── require.coffee.html
│ ├── require.js.html
│ ├── bower.json.html
│ └── composer.json.html
├── test_setup.js
├── test_require_coffee_remote.js
├── test_require_coffee_local.js
├── test_utils.js
├── test_manifest_bower_remote.js
├── test_manifest_bower_local.js
├── test_manifest_composer_remote.js
├── test_manifest_composer_local.js
├── test_manifest_package_remote.js
├── test_manifest_package_local.js
├── test_require_remote.js
└── test_require_local.js
├── .gitignore
├── .travis.yml
├── CHANGELOG.md
├── .editorconfig
├── .jshintrc
├── lib
├── flash.js
├── utils.js
├── link_builder.js
├── manifest.js
└── require.js
├── .jscs.json
├── README.md
├── index.js
├── package.json
└── gulpfile.js
/test/fixtures/require.coffee:
--------------------------------------------------------------------------------
1 | require "path"
2 | lodash = require("lodash")
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | temp/
3 | coverage/
4 | npm-debug.log
5 | .DS_Store
6 | .idea
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - '0.10'
4 | after_script:
5 | - npm run coveralls
6 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 |
4 | ## v1.0.2 (2014-10-10)
5 |
6 | - Fix css typo
7 |
8 |
9 | ## v1.0.0 (2014-09-25)
10 |
11 | - Initial version
12 |
--------------------------------------------------------------------------------
/test/test_setup.js:
--------------------------------------------------------------------------------
1 | var registries = require('github-linker-cache');
2 |
3 | before(function() {
4 | registries.npm = {
5 | lodash: 'https://github.com/lodash/lodash'
6 | };
7 | });
8 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig helps developers define and maintain consistent
2 | # coding styles between different editors and IDEs
3 | # editorconfig.org
4 |
5 | root = true
6 |
7 |
8 | [*]
9 |
10 | # Change these settings to your own preference
11 | indent_style = space
12 | indent_size = 2
13 |
14 | # We recommend you to keep these unchanged
15 | end_of_line = lf
16 | charset = utf-8
17 | trim_trailing_whitespace = true
18 | insert_final_newline = true
19 |
20 | [*.md]
21 | trim_trailing_whitespace = false
22 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "curly": true,
3 | "eqeqeq": true,
4 | "immed": true,
5 | "latedef": true,
6 | "newcap": true,
7 | "noarg": true,
8 | "sub": true,
9 | "undef": true,
10 | "unused": true,
11 | "boss": true,
12 | "eqnull": true,
13 | "node": true,
14 | "expr": true,
15 | "globals": {
16 | "describe" : false,
17 | "it" : false,
18 | "before" : false,
19 | "beforeEach" : false,
20 | "after" : false,
21 | "afterEach" : false,
22 | "window" : false,
23 | "localStorage" : false
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/test/fixtures/require.js:
--------------------------------------------------------------------------------
1 |
2 | require('path');
3 | require('lodash');
4 | require('unknown-package-name');
5 | require('./file.js');
6 | require('./folder/file.js');
7 | require('./file-or-folder');
8 | require('../file.js');
9 | require('../folder/file.js');
10 | require('../file-or-folder');
11 | require('../../file.js');
12 | require('../../folder/file.js');
13 | require('../../file-or-folder');
14 | require('./');
15 | require('..');
16 | require('../');
17 | require('../..');
18 | require('../../');
19 | require('.');
20 | require('...');
21 | require('/');
22 | require('matthewmueller/uid');
23 | require('component/tip@master');
24 | require('yields/shortcuts@0.0.1:/index.js');
25 |
--------------------------------------------------------------------------------
/lib/flash.js:
--------------------------------------------------------------------------------
1 | /*
2 | * github-linker-core
3 | * https://github.com/stefanbuck/github-linker
4 | *
5 | * Copyright (c) 2014 Stefan Buck
6 | * Licensed under the MIT license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var util = require('util');
12 |
13 | module.exports = function($) {
14 |
15 | if ($('.github-linker-intro').length === 0) {
16 |
17 | var message = 'The GitHub-Linker Chrome extension has some improvements for you! %s';
18 | var changelogLink = 'Read more';
19 | var messageHTML = util.format(message, changelogLink);
20 |
21 | var $intro = $('
' + messageHTML + '
');
22 | $('.wrapper').prepend($intro);
23 | }
24 | };
25 |
--------------------------------------------------------------------------------
/.jscs.json:
--------------------------------------------------------------------------------
1 | {
2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"],
3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
4 | "disallowSpaceBeforeBinaryOperators": [",", ":"],
5 | "disallowSpaceAfterBinaryOperators": ["!"],
6 | "requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
7 | "requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="],
8 | "disallowImplicitTypeConversion": ["string"],
9 | "disallowKeywords": ["with"],
10 | "disallowMultipleLineBreaks": true,
11 | "disallowKeywordsOnNewLine": ["else"],
12 | "disallowTrailingWhitespace": true,
13 | "requireLineFeedAtFileEnd": true,
14 | "validateIndentation": 2,
15 | "validateQuoteMarks": "'",
16 | "validateJSDoc": {
17 | "checkParamNames": true,
18 | "requireParamTypes": true
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test/fixtures/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "playground-repo",
3 | "description": "My personal playground",
4 | "version": "0.0.1",
5 | "main": "index.js",
6 | "license": "MIT",
7 | "ignore": "",
8 | "keywords": [],
9 | "author": [
10 | "Stefan Buck (http://stefanbuck.com)"
11 | ],
12 | "homepage": "https://github.com/stefanbuck/playground-repo",
13 | "repository": {
14 | "type": "git",
15 | "url": "https://github.com/stefanbuck/playground-repo"
16 | },
17 | "dependencies": {
18 | "lodash": "2.4.1",
19 | "modernizr": "Modernizr/Modernizr",
20 | "backbone": "jashkenas/backbone#master",
21 | "jquery": "jquery/jquery#1.x-master",
22 | "unknown-package-name": "latest"
23 | },
24 | "devDependencies": {
25 | "chai": "^1.9.1",
26 | "should": "^3.3.1"
27 | },
28 | "resolutions": {
29 | "lodash": "2.1.0"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _ = require('lodash');
4 |
5 | var urlMatch = function(url, lookup) {
6 |
7 | var urlContains = function(indicator) {
8 | url = url.split('#')[0];
9 | return url.indexOf(indicator) === url.length - indicator.length;
10 | };
11 |
12 | return _.find(lookup, function(type, urlFragment) {
13 | return urlContains(urlFragment);
14 | });
15 | };
16 |
17 | var stripQuotes = function(jqElement) {
18 | return jqElement.html().replace(/"|'/g, '');
19 | };
20 |
21 | var showLoader = function($) {
22 | var $loaderContainer = $('.page-context-loader');
23 | $loaderContainer.addClass('is-context-loading');
24 | };
25 |
26 | var runInBrowser = function(global) {
27 | if (typeof global.chrome === 'object') {
28 | return true;
29 | }
30 | return false;
31 | };
32 |
33 | module.exports = {
34 | stripQuotes: stripQuotes,
35 | urlMatch: urlMatch,
36 | showLoader: showLoader,
37 | runInBrowser: runInBrowser,
38 | };
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # github-linker-core
2 | [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Coverage Status][coveralls-image]][coveralls-url]
3 |
4 | > The [GitHub-Linker](https://github.com/stefanbuck/github-linker) core
5 |
6 |
7 | ## License
8 |
9 | Copyright (c) 2014 Stefan Buck. Licensed under the MIT license.
10 |
11 |
12 |
13 | [npm-url]: https://npmjs.org/package/github-linker-core
14 | [npm-image]: https://badge.fury.io/js/github-linker-core.svg
15 | [travis-url]: https://travis-ci.org/stefanbuck/github-linker-core
16 | [travis-image]: https://travis-ci.org/stefanbuck/github-linker-core.svg?branch=master
17 | [daviddm-url]: https://david-dm.org/stefanbuck/github-linker-core.svg?theme=shields.io
18 | [daviddm-image]: https://david-dm.org/stefanbuck/github-linker-core
19 | [coveralls-url]: https://coveralls.io/r/stefanbuck/github-linker-core
20 | [coveralls-image]: https://coveralls.io/repos/stefanbuck/github-linker-core/badge.png
21 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * github-linker-core
3 | * https://github.com/stefanbuck/github-linker
4 | *
5 | * Copyright (c) 2014 Stefan Buck
6 | * Licensed under the MIT license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var manifest = require('./lib/manifest');
12 | var reqr = require('./lib/require');
13 | var flash = require('./lib/flash');
14 | var utils = require('./lib/utils');
15 |
16 | var isNewVersion = function(global) {
17 | var version = '3.0.x';
18 | var installedVersion = global.localStorage.getItem('github-linker-version');
19 | if (installedVersion !== version) {
20 | global.localStorage.setItem('github-linker-version', version);
21 | if (installedVersion) {
22 | return true;
23 | }
24 | }
25 | return false;
26 | };
27 |
28 | module.exports = function(global, $, url, cb) {
29 |
30 | if ($('.github-linker').length > 0) {
31 | return cb(null);
32 | }
33 |
34 | if (utils.runInBrowser(global)) {
35 | if (isNewVersion(global)) {
36 | flash($);
37 | }
38 | }
39 |
40 | if (manifest.supported(url)) {
41 | manifest.init($, url, cb);
42 | } else if (reqr.supported(url)) {
43 | reqr.init($, url, cb);
44 | }
45 | };
46 |
--------------------------------------------------------------------------------
/test/fixtures/composer.json:
--------------------------------------------------------------------------------
1 |
2 | {
3 | "name": "playground-repo",
4 | "description": "My personal playground",
5 | "version": "0.0.1",
6 | "type": "library",
7 | "keywords": [],
8 | "homepage": "https://github.com/stefanbuck/playground-repo",
9 | "time": "2014-09-19",
10 | "license": "MIT",
11 | "authors": [
12 | {
13 | "name": "Stefan Buck",
14 | "email": "dev@stefanbuck.com",
15 | "homepage": "http://stefanbuck.com",
16 | "role": "Developer"
17 | }
18 | ],
19 | "support": {
20 | "email": "dev@stefanbuck.com",
21 | "irc": "irc://irc.freenode.org/composer"
22 | },
23 | "require": {
24 | "php": ">=5.3.2",
25 | "laravel/framework": "~4.2",
26 | "unknown-package-name": "*"
27 | },
28 | "require-dev": {
29 | "phpunit/phpunit": "~4.0",
30 | "doctrine/dbal": "~2.3"
31 | },
32 | "conflict": {},
33 | "replace": {},
34 | "provide": {},
35 | "suggest'": {
36 | "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages",
37 | "doctrine/dbal": "Load information from the database about models for phpdocs (~2.3)"
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "github-linker-core",
3 | "description": "The GitHub Linker core",
4 | "version": "1.0.2",
5 | "homepage": "https://github.com/stefanbuck/github-linker",
6 | "bugs": "https://github.com/stefanbuck/github-linker-core/issues",
7 | "license": "MIT",
8 | "main": "index.js",
9 | "author": {
10 | "name": "Stefan Buck",
11 | "email": "dev@stefanbuck.com",
12 | "url": "http://stefanbuck.com"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "https://github.com/stefanbuck/github-linker-core"
17 | },
18 | "keywords": [],
19 | "dependencies": {
20 | "github-linker-cache": "^0.2.0",
21 | "github-linker-resolve": "^0.1.0",
22 | "jquery": "^2.1.1",
23 | "lodash": "2.4.1"
24 | },
25 | "devDependencies": {
26 | "coveralls": "^2.11.1",
27 | "gulp": "^3.8.8",
28 | "gulp-bump": "^0.1.11",
29 | "gulp-istanbul": "^0.3.0",
30 | "gulp-jscs": "^1.1.2",
31 | "gulp-jshint": "^1.8.4",
32 | "gulp-load-plugins": "^0.6.0",
33 | "gulp-mocha": "^1.1.0",
34 | "gulp-plumber": "^0.6.5",
35 | "gulp-util": "^3.0.1",
36 | "jsdom": "^1.0.0-pre.6",
37 | "jshint-stylish": "^0.4.0",
38 | "should": "^4.0.4"
39 | },
40 | "scripts": {
41 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
42 | "test": "gulp test"
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/test/fixtures/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "playground-repo",
3 | "description": "My personal playground",
4 | "version": "0.0.1",
5 | "homepage": "https://github.com/stefanbuck/playground-repo",
6 | "bugs": "https://github.com/stefanbuck/playground-repo/issues",
7 | "license": "MIT",
8 | "directories": {
9 | "main": "./main",
10 | "bin": "./bin"
11 | },
12 | "bin": "./index.js",
13 | "main": "index.js",
14 | "author": {
15 | "name": "Stefan Buck",
16 | "email": "dev@stefanbuck.com",
17 | "url": "http://stefanbuck.com"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/stefanbuck/playground-repo"
22 | },
23 | "keywords": [],
24 | "dependencies": {
25 | "lodash": "2.4.1",
26 | "request": "^2.40.0",
27 | "modernizr": "Modernizr/Modernizr",
28 | "backbone": "jashkenas/backbone#master",
29 | "jquery": "jquery/jquery#1.x-master",
30 | "unknown-package-name": "latest"
31 | },
32 | "devDependencies": {
33 | "chai": "^1.9.1",
34 | "gulp": "^3.6.2"
35 | },
36 | "optionalDependencies": {
37 | "should": "^3.3.1"
38 | },
39 | "peerDependencies": {
40 | "yo": ">=1.0.0"
41 | },
42 | "scripts": {
43 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
44 | "test": "gulp test"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/gulpfile.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var gulp = require('gulp');
4 | var plugins = require('gulp-load-plugins')();
5 |
6 | var paths = {
7 | lint: ['./gulpfile.js', './lib/**/*.js', './index.js'],
8 | watch: ['./gulpfile.js', './lib/**/*.js', './index.js', './test/**/*.js', '!test/{temp,temp/**}'],
9 | tests: ['./test/**/*.js', '!test/{temp,temp/**}', '!test/fixtures/**'],
10 | source: ['./lib/**/*.js', './index.js']
11 | };
12 |
13 | gulp.task('lint', function () {
14 | return gulp.src(paths.lint)
15 | .pipe(plugins.jshint('.jshintrc'))
16 | .pipe(plugins.jscs())
17 | .pipe(plugins.jshint.reporter('jshint-stylish'));
18 | });
19 |
20 | gulp.task('istanbul', function (cb) {
21 | gulp.src(paths.source)
22 | .pipe(plugins.istanbul()) // Covering files
23 | .on('finish', function () {
24 | gulp.src(paths.tests)
25 | .pipe(plugins.plumber())
26 | .pipe(plugins.mocha())
27 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned
28 | .on('finish', function() {
29 | process.chdir(__dirname);
30 | cb();
31 | });
32 | });
33 | });
34 |
35 | gulp.task('bump', ['test'], function () {
36 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch
37 |
38 | return gulp.src(['./package.json'])
39 | .pipe(plugins.bump({ type: bumpType }))
40 | .pipe(gulp.dest('./'));
41 | });
42 |
43 | gulp.task('watch', ['test'], function () {
44 | gulp.watch(paths.watch, ['test']);
45 | });
46 |
47 | gulp.task('test', ['lint', 'istanbul']);
48 |
49 | gulp.task('release', ['bump']);
50 |
51 | gulp.task('default', ['test']);
52 |
--------------------------------------------------------------------------------
/test/test_require_coffee_remote.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var assert = require('should');
5 | var _ = require('lodash');
6 | var env = require('jsdom').env;
7 |
8 | describe('require.coffee', function() {
9 |
10 | describe('local', function() {
11 | var $, result;
12 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/require.coffee';
13 |
14 | before(function(done) {
15 | $ = result = null;
16 |
17 | env(url, function(err, window) {
18 | if (err) {
19 | return done(err);
20 | }
21 | $ = require('jquery')(window);
22 |
23 | githubLinkerCore(window, $, url, function(err, _result) {
24 | if (err) {
25 | throw err;
26 | }
27 | result = _result;
28 | done();
29 | });
30 | });
31 | });
32 |
33 | it('found dependencies', function() {
34 |
35 | // TODO Evaluate why this doesn't work
36 | // result.should.have.length(2);
37 |
38 | result.length.should.equal(2);
39 | });
40 |
41 | it('http://nodejs.org/api/path.html', function() {
42 | var item = _.findWhere(result, {
43 | name: 'path'
44 | });
45 |
46 | item.link.should.equal('http://nodejs.org/api/path.html');
47 |
48 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
49 | item.el.hasClass('tooltipped').should.be.false;
50 | });
51 |
52 | it('https://github.com/lodash/lodash', function() {
53 | var item = _.findWhere(result, {
54 | name: 'lodash'
55 | });
56 |
57 | item.link.should.equal('https://github.com/lodash/lodash');
58 |
59 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
60 | item.el.hasClass('tooltipped').should.be.false;
61 | });
62 |
63 | });
64 | });
65 |
--------------------------------------------------------------------------------
/test/test_require_coffee_local.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('should');
7 | var _ = require('lodash');
8 | var env = require('jsdom').env;
9 |
10 | describe('require.coffee', function() {
11 |
12 | describe('local', function() {
13 | var $, result;
14 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/require.coffee';
15 | var file = path.resolve(__dirname, 'fixtures/require.coffee.html');
16 |
17 | before(function(done) {
18 | $ = result = null;
19 | var html = fs.readFileSync(file, 'utf-8');
20 |
21 | env(html, function(err, window) {
22 | if (err) {
23 | return done(err);
24 | }
25 | $ = require('jquery')(window);
26 |
27 | githubLinkerCore(window, $, url, function(err, _result) {
28 | if (err) {
29 | throw err;
30 | }
31 | result = _result;
32 | done();
33 | });
34 | });
35 | });
36 |
37 | it('found dependencies', function() {
38 |
39 | // TODO Evaluate why this doesn't work
40 | // result.should.have.length(2);
41 |
42 | result.length.should.equal(2);
43 | });
44 |
45 | it('http://nodejs.org/api/path.html', function() {
46 | var item = _.findWhere(result, {
47 | name: 'path'
48 | });
49 |
50 | item.link.should.equal('http://nodejs.org/api/path.html');
51 |
52 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
53 | item.el.hasClass('tooltipped').should.be.false;
54 | });
55 |
56 | it('https://github.com/lodash/lodash', function() {
57 | var item = _.findWhere(result, {
58 | name: 'lodash'
59 | });
60 |
61 | item.link.should.equal('https://github.com/lodash/lodash');
62 |
63 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
64 | item.el.hasClass('tooltipped').should.be.false;
65 | });
66 |
67 | });
68 | });
69 |
--------------------------------------------------------------------------------
/test/test_utils.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var utils = require('../lib/utils');
4 | var manifest = require('../lib/manifest');
5 | var reqr = require('../lib/require');
6 | var assert = require('should');
7 |
8 | describe('utils', function() {
9 |
10 | describe('manifest.supported', function() {
11 |
12 | it('package.json', function() {
13 | manifest.supported('https://github.com/stefanbuck/github-linker-core/blob/master/package.json').should.equal(true);
14 | });
15 |
16 | it('bower.json', function() {
17 | manifest.supported('https://github.com/stefanbuck/github-linker-core/blob/master/bower.json').should.equal(true);
18 | });
19 |
20 | it('composer.json', function() {
21 | manifest.supported('https://github.com/stefanbuck/github-linker-core/blob/master/composer.json').should.equal(true);
22 | });
23 |
24 | it('unknown.json', function() {
25 | manifest.supported('https://github.com/stefanbuck/github-linker-core/blob/master/unknown.json').should.equal(false);
26 | });
27 | });
28 |
29 | describe('require.supported', function() {
30 |
31 | it('file.js', function() {
32 | reqr.supported('https://github.com/stefanbuck/github-linker-core/blob/master/file.js').should.equal(true);
33 | });
34 |
35 | it('file.coffee', function() {
36 | reqr.supported('https://github.com/stefanbuck/github-linker-core/blob/master/file.coffee').should.equal(true);
37 | });
38 |
39 | it('file.txt', function() {
40 | reqr.supported('https://github.com/stefanbuck/github-linker-core/blob/master/file.txt').should.equal(false);
41 | });
42 | });
43 |
44 | describe('advanced urls', function() {
45 |
46 | it('with line marker', function() {
47 | manifest.supported('https://github.com/stefanbuck/github-linker-core/blob/master/package.json#L1').should.equal(true);
48 | reqr.supported('https://github.com/stefanbuck/github-linker-core/blob/master/file.js#L1').should.equal(true);
49 | });
50 | });
51 |
52 | describe('stripQuotes', function() {
53 |
54 | it('lodash', function() {
55 | utils.stripQuotes({html: function(){return 'lodash';}}).should.equal('lodash');
56 | });
57 |
58 | it('"lodash"', function() {
59 | utils.stripQuotes({html: function(){return '"lodash"';}}).should.equal('lodash');
60 | });
61 |
62 | it('\'lodash\'', function() {
63 | utils.stripQuotes({html: function(){return '\'lodash\'';}}).should.equal('lodash');
64 | });
65 |
66 | it('"lodash\'', function() {
67 | utils.stripQuotes({html: function(){return '"lodash\'';}}).should.equal('lodash');
68 | });
69 |
70 | });
71 | });
72 |
--------------------------------------------------------------------------------
/lib/link_builder.js:
--------------------------------------------------------------------------------
1 | /*
2 | * github-linker-core
3 | * https://github.com/stefanbuck/github-linker
4 | *
5 | * Copyright (c) 2014 Stefan Buck
6 | * Licensed under the MIT license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var util = require('util');
12 | var cache = require('github-linker-cache');
13 | var glResolve = require('github-linker-resolve');
14 |
15 | // List of nodejs core modules (v0.11.13)
16 | // see: https://github.com/joyent/node/blob/master/lib/repl.js#L72
17 | var NODE_CORE_MODULES = ['assert', 'buffer', 'child_process', 'cluster', 'crypto', 'dgram', 'dns', 'domain', 'events', 'fs', 'http', 'https', 'net', 'os', 'path', 'punycode', 'querystring', 'readline', 'stream', 'string_decoder', 'tls', 'tty', 'url', 'util', 'vm', 'zlib', 'smalloc', 'tracing'];
18 |
19 | var NODE_API = 'http://nodejs.org/api/%s.html';
20 | var NPM_API = 'https://www.npmjs.org/package/';
21 | var BOWER_API = 'http://bower.io/search/?q=';
22 |
23 | var GITHUBCOM = 'https://github.com';
24 | var RESOLVE_INDICATOR = 'resolve:';
25 |
26 | var manifestBuilder = function(type, name, version) {
27 |
28 | var link = cache[type][name];
29 |
30 | if (version.split('/').length === 2) {
31 | link = GITHUBCOM + '/' + version.replace('#', '/tree/');
32 |
33 | } else if (!link) {
34 |
35 | if (type === 'npm') {
36 | link = NPM_API + name;
37 | } else if (type === 'bower') {
38 | link = BOWER_API + name;
39 | }
40 | }
41 |
42 | return link || '';
43 | };
44 |
45 | // Method taken from https://github.com/npm/npm-package-arg/blob/97487d38bcf1879d7c32dd577b181abb65af4e02/npa.js
46 | var validPackageName = function (name) {
47 | if (!name) {
48 | return false;
49 | }
50 | var n = name.trim();
51 | if (!n || n.charAt(0) === '.' || !n.match(/^[a-zA-Z0-9]/) || n.match(/[\/\(\)&\?#\|<>@:%\s\\\*'"!~`]/) || n.toLowerCase() === 'node_modules' || n !== encodeURIComponent(n) || n.toLowerCase() === 'favicon.ico') {
52 | return false;
53 | }
54 | return n;
55 | };
56 |
57 | var requireBuilder = function(url, requireValue) {
58 | var link = '';
59 |
60 | if (NODE_CORE_MODULES.indexOf(requireValue) !== -1) {
61 | // Redirect to http://nodejs.org/api/{module}.html
62 | link = util.format(NODE_API, requireValue);
63 | } else if (cache.npm[requireValue]) {
64 | // Get repo link from cache list
65 | link = cache.npm[requireValue];
66 | } else {
67 | if (validPackageName(requireValue)) {
68 | // Try to resolve link via https://www.npmjs.org/package/{name}
69 | link = RESOLVE_INDICATOR + NPM_API + requireValue;
70 | } else {
71 | // Resolve paths, duojs and github shorthand
72 | link = glResolve(requireValue, url);
73 | if (link) {
74 | link = RESOLVE_INDICATOR + link;
75 | }
76 | }
77 | }
78 | return link;
79 | };
80 |
81 | module.exports = {
82 | require: requireBuilder,
83 | manifest: manifestBuilder
84 | };
85 |
--------------------------------------------------------------------------------
/lib/manifest.js:
--------------------------------------------------------------------------------
1 | /*
2 | * github-linker-core
3 | * https://github.com/stefanbuck/github-linker
4 | *
5 | * Copyright (c) 2014 Stefan Buck
6 | * Licensed under the MIT license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var linkBuilder = require('./link_builder').manifest;
12 | var utils = require('./utils');
13 |
14 | var SORRY = 'Sorry, there is no link for this package available';
15 |
16 | var getType = function(url) {
17 | var lookup = {
18 | '/package.json': 'npm',
19 | '/bower.json': 'bower',
20 | '/composer.json': 'composer'
21 | };
22 | return utils.urlMatch(url, lookup);
23 | };
24 |
25 | var supported = function(url) {
26 | return !!getType(url);
27 | };
28 |
29 | var mainField = function($, type) {
30 | if (type === 'npm' || type === 'bower') {
31 | var $main = $('span.nt').filter(function() {
32 | return $(this).text().replace(/"|'/g, '') === 'main';
33 | }).next().next('[class^="s"]');
34 | if ($main.length > 0) {
35 | var entryFile = utils.stripQuotes($main);
36 | if (entryFile) {
37 | $main.wrap('');
38 | }
39 | }
40 | }
41 | };
42 |
43 | var dependencieField = function($, type) {
44 | var $root, $row, $item, $version, name, version, link;
45 | var selectors = [];
46 | if (type === 'npm') {
47 | selectors = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
48 | } else if (type === 'bower') {
49 | selectors = ['dependencies', 'devDependencies', 'resolutions'];
50 | } else if (type === 'composer') {
51 | selectors = ['require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest'];
52 | }
53 |
54 | var result = [];
55 |
56 | selectors.forEach(function(selector) {
57 | $root = $('.nt').filter(function() {
58 | return $(this).text().replace(/"|'/g, '') === selector;
59 | });
60 |
61 | if (!$root || $root.length === 0) {
62 | return;
63 | }
64 |
65 | $row = $root.closest('tr').next();
66 |
67 | while ($row) {
68 | $item = $row.find('.nt');
69 | $version = $row.find('.s2');
70 |
71 | if (!$item.length || !$version.length) {
72 | return;
73 | }
74 |
75 | name = utils.stripQuotes($item);
76 | version = utils.stripQuotes($version);
77 |
78 | link = linkBuilder(type, name, version);
79 |
80 | if (link) {
81 | $item = $item.wrap('').parent();
82 | } else {
83 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY);
84 | }
85 |
86 | result.push({
87 | el: $item,
88 | version: version,
89 | name: name,
90 | link: link
91 | });
92 |
93 | $row = $row.next();
94 | }
95 | });
96 | return result;
97 | };
98 |
99 | var init = function($, url, cb) {
100 |
101 | var type = getType(url);
102 | var result = dependencieField($, type);
103 | mainField($, type);
104 |
105 | cb(null, result);
106 | };
107 |
108 | module.exports = {
109 | init: init,
110 | supported: supported
111 | };
112 |
--------------------------------------------------------------------------------
/lib/require.js:
--------------------------------------------------------------------------------
1 | /*
2 | * github-linker-core
3 | * https://github.com/stefanbuck/github-linker
4 | *
5 | * Copyright (c) 2014 Stefan Buck
6 | * Licensed under the MIT license.
7 | */
8 |
9 | 'use strict';
10 |
11 | var path = require('path');
12 | var linkBuilder = require('./link_builder').require;
13 | var utils = require('./utils');
14 |
15 | var GITHUBCOM = 'https://github.com';
16 | var SORRY = 'Can\'t resolve this require for you, sorry.';
17 | var RESOLVE_INDICATOR = 'resolve:';
18 |
19 | var getType = function(url) {
20 | var lookup = {
21 | '.js': 'js',
22 | '.coffee': 'coffee'
23 | };
24 | return utils.urlMatch(url, lookup);
25 | };
26 |
27 | var attemptToLoadURL = function($, urls, cb) {
28 | var url = urls.shift();
29 | $.ajax({
30 | url: url,
31 | type: 'HEAD',
32 | timeout: 3000
33 | }).then(function() {
34 | cb(url);
35 | }).fail(function() {
36 | if (urls.length > 0) {
37 | attemptToLoadURL($, urls, cb);
38 | } else {
39 | cb(null);
40 | }
41 | });
42 | };
43 |
44 | var registerClickListener = function($, fileExtension) {
45 | fileExtension = '.' + fileExtension;
46 |
47 | $('body').on('click', 'a.github-linker', function(e) {
48 | utils.showLoader($);
49 | var $el = $(this);
50 | var link = $el.data('href');
51 |
52 | if (link) {
53 | e.stopPropagation();
54 |
55 | var urls = [];
56 | if (link.indexOf(GITHUBCOM) === 0) {
57 | if (path.extname(link)) {
58 | urls.push(link);
59 | } else {
60 | urls.push(link + fileExtension);
61 | }
62 | urls = urls.concat([
63 | link + '/index' + fileExtension,
64 | link.replace('blob', 'tree')
65 | ]);
66 | } else {
67 | urls = link.split(',');
68 | }
69 |
70 | $el.addClass('tooltipped tooltipped-e').attr('aria-label', 'Loading ...');
71 | attemptToLoadURL($, urls, function(link) {
72 | if (link) {
73 | window.location.href = link;
74 | } else {
75 | $el.attr('aria-label', SORRY);
76 | }
77 | });
78 | }
79 | });
80 | };
81 |
82 | var supported = function(url) {
83 | return !!getType(url);
84 | };
85 |
86 | var init = function($, url, cb) {
87 |
88 | var $requires, $coffeeRequires, $item, name, link, resolveLink;
89 | var result = [];
90 | var type = getType(url);
91 |
92 | // Search for require dom elements
93 | $requires = $('span.nx').filter(function() {
94 | return $(this).text() === 'require';
95 | }).next().next('[class^="s"]');
96 |
97 | if (type === 'coffee') {
98 | $coffeeRequires = $('span.nx').filter(function() {
99 | return $(this).text() === 'require';
100 | }).next('[class^="s"]');
101 | $requires = $.merge($coffeeRequires, $requires);
102 | }
103 |
104 | $requires.each(function(index, item) {
105 | $item = $(item);
106 |
107 | name = utils.stripQuotes($item);
108 | link = linkBuilder(url, name);
109 | resolveLink = false;
110 |
111 | if (link) {
112 | if ( link.indexOf(RESOLVE_INDICATOR) === 0) {
113 | link = link.replace(RESOLVE_INDICATOR, '');
114 | resolveLink = true;
115 | $item = $item.wrap('').parent();
116 | } else {
117 | $item = $item.wrap('').parent();
118 | }
119 | } else {
120 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY);
121 | }
122 |
123 | result.push({
124 | el: $item,
125 | name: name,
126 | link: link,
127 | resolveLink: resolveLink
128 | });
129 | });
130 |
131 | registerClickListener($, type);
132 |
133 | cb(null, result);
134 | };
135 |
136 | module.exports = {
137 | init: init,
138 | supported: supported
139 | };
140 |
--------------------------------------------------------------------------------
/test/test_manifest_bower_remote.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var assert = require('should');
5 | var _ = require('lodash');
6 | var env = require('jsdom').env;
7 |
8 | describe('manifest', function() {
9 |
10 | describe('bower.json', function() {
11 |
12 | describe('remote', function() {
13 |
14 | this.timeout(4000);
15 |
16 | var $, result;
17 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/bower.json';
18 |
19 | before(function(done) {
20 | $ = result = null;
21 |
22 | env(url, function(err, window) {
23 | if (err) {
24 | return done(err);
25 | }
26 | $ = require('jquery')(window);
27 | githubLinkerCore(window, $, url, function(err, _result) {
28 | if (err) {
29 | throw err;
30 | }
31 | result = _result;
32 | done();
33 | });
34 | });
35 | });
36 |
37 | it('found dependencies', function() {
38 |
39 | // TODO Evaluate why this doesn't work
40 | // result.should.have.length(10);
41 |
42 | result.length.should.equal(8);
43 | });
44 |
45 | it('check order', function() {
46 | result.length.should.equal(8);
47 | var pkgNames = ['lodash', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'should', 'lodash'];
48 | _.each(result, function(item, index) {
49 | item.name.should.equal( pkgNames[index] );
50 | });
51 | });
52 |
53 | it('check link replacement', function() {
54 | $('a.github-linker').length.should.equal(9);
55 | });
56 |
57 | it('link https://github.com/lodash/lodash', function() {
58 | var item = _.findWhere(result, {
59 | name: 'lodash'
60 | });
61 |
62 | (item.link === null).should.equal(false);
63 | item.link.should.equal('https://github.com/lodash/lodash');
64 |
65 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
66 | item.el.hasClass('tooltipped').should.be.false;
67 | });
68 |
69 | it('link https://github.com/Modernizr/Modernizr', function() {
70 | var item = _.findWhere(result, {
71 | name: 'modernizr'
72 | });
73 |
74 | (item.link === null).should.equal(false);
75 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
76 |
77 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
78 | item.el.hasClass('tooltipped').should.be.false;
79 | });
80 |
81 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
82 | var item = _.findWhere(result, {
83 | name: 'backbone'
84 | });
85 |
86 | (item.link === null).should.equal(false);
87 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
88 |
89 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
90 | item.el.hasClass('tooltipped').should.be.false;
91 | });
92 |
93 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
94 | var item = _.findWhere(result, {
95 | name: 'jquery'
96 | });
97 |
98 | (item.link === null).should.equal(false);
99 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
100 |
101 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
102 | item.el.hasClass('tooltipped').should.be.false;
103 | });
104 |
105 | it('link http://bower.io/search/?q=unknown-package-name', function() {
106 | var item = _.findWhere(result, {
107 | name: 'unknown-package-name'
108 | });
109 |
110 | (item.link === null).should.equal(false);
111 | item.link.should.equal('http://bower.io/search/?q=unknown-package-name');
112 | });
113 |
114 | it('entry file', function() {
115 | var mainFile = $('span.nt:contains("main")').parent().find('.github-linker').attr('href');
116 | (!!mainFile).should.equal(true);
117 | mainFile.should.equal('index.js');
118 | });
119 | });
120 | });
121 | });
122 |
--------------------------------------------------------------------------------
/test/test_manifest_bower_local.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('should');
7 | var _ = require('lodash');
8 | var env = require('jsdom').env;
9 |
10 | describe('manifest', function() {
11 |
12 | describe('bower.json', function() {
13 |
14 | describe('local', function() {
15 | var $, result;
16 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/bower.json';
17 | var file = path.resolve(__dirname, 'fixtures/bower.json.html');
18 |
19 | before(function(done) {
20 | $ = result = null;
21 | var html = fs.readFileSync(file, 'utf-8');
22 |
23 | env(html, function(err, window) {
24 | if (err) {
25 | return done(err);
26 | }
27 | $ = require('jquery')(window);
28 |
29 | githubLinkerCore(window, $, url, function(err, _result) {
30 | if (err) {
31 | throw err;
32 | }
33 | result = _result;
34 | done();
35 | });
36 | });
37 | });
38 |
39 | it('found dependencies', function() {
40 |
41 | // TODO Evaluate why this doesn't work
42 | // result.should.have.length(10);
43 |
44 | result.length.should.equal(8);
45 | });
46 |
47 | it('check order', function() {
48 | result.length.should.equal(8);
49 | var pkgNames = ['lodash', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'should', 'lodash'];
50 | _.each(result, function(item, index) {
51 | item.name.should.equal( pkgNames[index] );
52 | });
53 | });
54 |
55 | it('check link replacement', function() {
56 | $('a.github-linker').length.should.equal(9);
57 | });
58 |
59 | it('link https://github.com/lodash/lodash', function() {
60 | var item = _.findWhere(result, {
61 | name: 'lodash'
62 | });
63 |
64 | (item.link === null).should.equal(false);
65 | item.link.should.equal('https://github.com/lodash/lodash');
66 |
67 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
68 | item.el.hasClass('tooltipped').should.be.false;
69 | });
70 |
71 | it('link https://github.com/Modernizr/Modernizr', function() {
72 | var item = _.findWhere(result, {
73 | name: 'modernizr'
74 | });
75 |
76 | (item.link === null).should.equal(false);
77 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
78 |
79 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
80 | item.el.hasClass('tooltipped').should.be.false;
81 | });
82 |
83 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
84 | var item = _.findWhere(result, {
85 | name: 'backbone'
86 | });
87 |
88 | (item.link === null).should.equal(false);
89 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
90 |
91 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
92 | item.el.hasClass('tooltipped').should.be.false;
93 | });
94 |
95 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
96 | var item = _.findWhere(result, {
97 | name: 'jquery'
98 | });
99 |
100 | (item.link === null).should.equal(false);
101 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
102 |
103 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
104 | item.el.hasClass('tooltipped').should.be.false;
105 | });
106 |
107 | it('link http://bower.io/search/?q=unknown-package-name', function() {
108 | var item = _.findWhere(result, {
109 | name: 'unknown-package-name'
110 | });
111 |
112 | (item.link === null).should.equal(false);
113 | item.link.should.equal('http://bower.io/search/?q=unknown-package-name');
114 | });
115 |
116 | it('entry file', function() {
117 | var mainFile = $('span.nt:contains("main")').parent().find('.github-linker').attr('href');
118 | (!!mainFile).should.equal(true);
119 | mainFile.should.equal('index.js');
120 | });
121 | });
122 | });
123 | });
124 |
--------------------------------------------------------------------------------
/test/test_manifest_composer_remote.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var assert = require('should');
5 | var _ = require('lodash');
6 | var env = require('jsdom').env;
7 |
8 | describe('manifest', function() {
9 |
10 | describe('composer.json', function() {
11 |
12 | describe('remote', function() {
13 |
14 | this.timeout(4000);
15 |
16 | var $, result;
17 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/composer.json';
18 |
19 | before(function(done) {
20 | $ = result = null;
21 |
22 | env(url, function(err, window) {
23 | if (err) {
24 | return done(err);
25 | }
26 | $ = require('jquery')(window);
27 | githubLinkerCore(window, $, url, function(err, _result) {
28 | if (err) {
29 | throw err;
30 | }
31 | result = _result;
32 | done();
33 | });
34 | });
35 | });
36 |
37 | it('found dependencies', function() {
38 |
39 | // TODO Evaluate why this doesn't work
40 | // result.should.have.length(7);
41 | result.length.should.equal(7);
42 | });
43 |
44 | it('check order', function() {
45 | result.length.should.equal(7);
46 | var pkgNames = ['php', 'laravel/framework', 'unknown-package-name', 'phpunit/phpunit', 'doctrine/dbal', 'ext-openssl', 'doctrine/dbal'];
47 | _.each(result, function(item, index) {
48 | item.name.should.equal( pkgNames[index] );
49 | });
50 | });
51 |
52 | it('check link replacement', function() {
53 | $('a.github-linker').length.should.equal(4);
54 | });
55 |
56 | describe('require', function() {
57 |
58 | it('link php', function() {
59 | var item = _.findWhere(result, {
60 | name: 'php'
61 | });
62 |
63 | (item.link === '').should.equal(true);
64 | item.el.hasClass('tooltipped').should.be.true;
65 | });
66 |
67 | it('link laravel/framework', function() {
68 | var item = _.findWhere(result, {
69 | name: 'laravel/framework'
70 | });
71 |
72 | (item.link === null).should.equal(false);
73 | item.link.should.equal('https://github.com/laravel/framework');
74 |
75 | item.el.attr('href').should.equal('https://github.com/laravel/framework');
76 | item.el.hasClass('tooltipped').should.be.false;
77 | });
78 |
79 | it('link unknown-package-name', function() {
80 | var item = _.findWhere(result, {
81 | name: 'unknown-package-name'
82 | });
83 |
84 | (item.link === '').should.equal(true);
85 | item.el.hasClass('tooltipped').should.be.true;
86 | });
87 | });
88 |
89 | describe('require-dev', function() {
90 |
91 | it('link phpunit/phpunit', function() {
92 | var item = _.findWhere(result, {
93 | name: 'phpunit/phpunit'
94 | });
95 |
96 | (item.link === null).should.equal(false);
97 | item.link.should.equal('https://github.com/sebastianbergmann/phpunit');
98 |
99 | item.el.attr('href').should.equal('https://github.com/sebastianbergmann/phpunit');
100 | item.el.hasClass('tooltipped').should.be.false;
101 | });
102 |
103 | it('link doctrine/dbal', function() {
104 | var item = _.findWhere(result, {
105 | name: 'doctrine/dbal'
106 | });
107 |
108 | (item.link === null).should.equal(false);
109 | item.link.should.equal('https://github.com/doctrine/dbal');
110 |
111 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
112 | item.el.hasClass('tooltipped').should.be.false;
113 | });
114 | });
115 |
116 | describe('suggest', function() {
117 |
118 | it('link ext-openssl', function() {
119 | var item = _.findWhere(result, {
120 | name: 'ext-openssl'
121 | });
122 |
123 | (item.link === '').should.equal(true);
124 | item.el.hasClass('tooltipped').should.be.true;
125 | });
126 |
127 | it('doctrine/dbal', function() {
128 | var item = result[result.length - 1];
129 |
130 | (item.link === null).should.equal(false);
131 | item.link.should.equal('https://github.com/doctrine/dbal');
132 |
133 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
134 | item.el.hasClass('tooltipped').should.be.false;
135 | });
136 | });
137 |
138 | });
139 | });
140 | });
141 |
--------------------------------------------------------------------------------
/test/test_manifest_composer_local.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('should');
7 | var _ = require('lodash');
8 | var env = require('jsdom').env;
9 |
10 | describe('manifest', function() {
11 |
12 | describe('composer.json', function() {
13 |
14 | describe('local', function() {
15 | var $, result;
16 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/composer.json';
17 | var file = path.resolve(__dirname, 'fixtures/composer.json.html');
18 |
19 | before(function(done) {
20 | $ = result = null;
21 | var html = fs.readFileSync(file, 'utf-8');
22 |
23 | env(html, function(err, window) {
24 | if (err) {
25 | return done(err);
26 | }
27 | $ = require('jquery')(window);
28 |
29 | githubLinkerCore(window, $, url, function(err, _result) {
30 | if (err) {
31 | throw err;
32 | }
33 | result = _result;
34 | done();
35 | });
36 | });
37 | });
38 |
39 | it('found dependencies', function() {
40 |
41 | // TODO Evaluate why this doesn't work
42 | // result.should.have.length(7);
43 | result.length.should.equal(7);
44 | });
45 |
46 | it('check order', function() {
47 | result.length.should.equal(7);
48 | var pkgNames = ['php', 'laravel/framework', 'unknown-package-name', 'phpunit/phpunit', 'doctrine/dbal', 'ext-openssl', 'doctrine/dbal'];
49 | _.each(result, function(item, index) {
50 | item.name.should.equal( pkgNames[index] );
51 | });
52 | });
53 |
54 | it('check link replacement', function() {
55 | $('a.github-linker').length.should.equal(4);
56 | });
57 |
58 | describe('require', function() {
59 |
60 | it('link php', function() {
61 | var item = _.findWhere(result, {
62 | name: 'php'
63 | });
64 |
65 | (item.link === '').should.equal(true);
66 | item.el.hasClass('tooltipped').should.be.true;
67 | });
68 |
69 | it('link laravel/framework', function() {
70 | var item = _.findWhere(result, {
71 | name: 'laravel/framework'
72 | });
73 |
74 | (item.link === null).should.equal(false);
75 | item.link.should.equal('https://github.com/laravel/framework');
76 |
77 | item.el.attr('href').should.equal('https://github.com/laravel/framework');
78 | item.el.hasClass('tooltipped').should.be.false;
79 | });
80 |
81 | it('link unknown-package-name', function() {
82 | var item = _.findWhere(result, {
83 | name: 'unknown-package-name'
84 | });
85 |
86 | (item.link === '').should.equal(true);
87 | item.el.hasClass('tooltipped').should.be.true;
88 | });
89 | });
90 |
91 | describe('require-dev', function() {
92 |
93 | it('link phpunit/phpunit', function() {
94 | var item = _.findWhere(result, {
95 | name: 'phpunit/phpunit'
96 | });
97 |
98 | (item.link === null).should.equal(false);
99 | item.link.should.equal('https://github.com/sebastianbergmann/phpunit');
100 |
101 | item.el.attr('href').should.equal('https://github.com/sebastianbergmann/phpunit');
102 | item.el.hasClass('tooltipped').should.be.false;
103 | });
104 |
105 | it('link doctrine/dbal', function() {
106 | var item = _.findWhere(result, {
107 | name: 'doctrine/dbal'
108 | });
109 |
110 | (item.link === null).should.equal(false);
111 | item.link.should.equal('https://github.com/doctrine/dbal');
112 |
113 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
114 | item.el.hasClass('tooltipped').should.be.false;
115 | });
116 | });
117 |
118 | describe('suggest', function() {
119 |
120 | it('link ext-openssl', function() {
121 | var item = _.findWhere(result, {
122 | name: 'ext-openssl'
123 | });
124 |
125 | (item.link === '').should.equal(true);
126 | item.el.hasClass('tooltipped').should.be.true;
127 | });
128 |
129 | it('doctrine/dbal', function() {
130 | var item = result[result.length - 1];
131 |
132 | (item.link === null).should.equal(false);
133 | item.link.should.equal('https://github.com/doctrine/dbal');
134 |
135 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
136 | item.el.hasClass('tooltipped').should.be.false;
137 | });
138 | });
139 |
140 | });
141 | });
142 | });
143 |
--------------------------------------------------------------------------------
/test/test_manifest_package_remote.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var assert = require('should');
5 | var _ = require('lodash');
6 | var env = require('jsdom').env;
7 |
8 | describe('manifest', function() {
9 |
10 | describe('package.json', function() {
11 |
12 | describe('remote', function() {
13 |
14 | this.timeout(4000);
15 |
16 | var $, result;
17 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/package.json';
18 |
19 | before(function(done) {
20 | $ = result = null;
21 |
22 | env(url, function(err, window) {
23 | if (err) {
24 | return done(err);
25 | }
26 | $ = require('jquery')(window);
27 | githubLinkerCore(window, $, url, function(err, _result) {
28 | if (err) {
29 | throw err;
30 | }
31 | result = _result;
32 | done();
33 | });
34 | });
35 | });
36 |
37 | it('found dependencies', function() {
38 |
39 | // TODO Evaluate why this doesn't work
40 | // result.should.have.length(10);
41 |
42 | result.length.should.equal(10);
43 | });
44 |
45 | it('check order', function() {
46 | result.length.should.equal(10);
47 | var pkgNames = ['lodash', 'request', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'gulp', 'yo', 'should'];
48 | _.each(result, function(item, index) {
49 | item.name.should.equal( pkgNames[index] );
50 | });
51 | });
52 |
53 | it('check link replacement', function() {
54 | $('a.github-linker').length.should.equal(11);
55 | });
56 |
57 | it('link https://github.com/lodash/lodash', function() {
58 | var item = _.findWhere(result, {
59 | name: 'lodash'
60 | });
61 |
62 | (item.link === null).should.equal(false);
63 | item.link.should.equal('https://github.com/lodash/lodash');
64 |
65 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
66 | item.el.hasClass('tooltipped').should.be.false;
67 | });
68 |
69 | it('link https://www.npmjs.org/package/request', function() {
70 | var item = _.findWhere(result, {
71 | name: 'request'
72 | });
73 |
74 | (item.link === null).should.equal(false);
75 | item.link.should.equal('https://www.npmjs.org/package/request');
76 |
77 | item.el.attr('href').should.equal('https://www.npmjs.org/package/request');
78 | item.el.hasClass('tooltipped').should.be.false;
79 | });
80 |
81 | it('link https://github.com/Modernizr/Modernizr', function() {
82 | var item = _.findWhere(result, {
83 | name: 'modernizr'
84 | });
85 |
86 | (item.link === null).should.equal(false);
87 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
88 |
89 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
90 | item.el.hasClass('tooltipped').should.be.false;
91 | });
92 |
93 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
94 | var item = _.findWhere(result, {
95 | name: 'backbone'
96 | });
97 |
98 | (item.link === null).should.equal(false);
99 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
100 |
101 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
102 | item.el.hasClass('tooltipped').should.be.false;
103 | });
104 |
105 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
106 | var item = _.findWhere(result, {
107 | name: 'jquery'
108 | });
109 |
110 | (item.link === null).should.equal(false);
111 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
112 |
113 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
114 | item.el.hasClass('tooltipped').should.be.false;
115 | });
116 |
117 | it('link https://www.npmjs.org/package/unknown-package-name', function() {
118 | var item = _.findWhere(result, {
119 | name: 'unknown-package-name'
120 | });
121 |
122 | (item.link === null).should.equal(false);
123 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
124 |
125 | item.el.attr('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
126 | item.el.hasClass('tooltipped').should.be.false;
127 | });
128 |
129 | it('entry file', function() {
130 | var mainFile = $('span.nt:contains("main")').parent().find('.github-linker').attr('href');
131 | (!!mainFile).should.equal(true);
132 | mainFile.should.equal('index.js');
133 | });
134 | });
135 | });
136 | });
137 |
--------------------------------------------------------------------------------
/test/test_manifest_package_local.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('should');
7 | var _ = require('lodash');
8 | var env = require('jsdom').env;
9 |
10 | describe('manifest', function() {
11 |
12 | describe('package.json', function() {
13 |
14 | describe('local', function() {
15 | var $, result;
16 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/package.json';
17 | var file = path.resolve(__dirname, 'fixtures/package.json.html');
18 |
19 | before(function(done) {
20 | $ = result = null;
21 | var html = fs.readFileSync(file, 'utf-8');
22 |
23 | env(html, function(err, window) {
24 | if (err) {
25 | return done(err);
26 | }
27 | $ = require('jquery')(window);
28 |
29 | githubLinkerCore(window, $, url, function(err, _result) {
30 | if (err) {
31 | throw err;
32 | }
33 | result = _result;
34 | done();
35 | });
36 | });
37 | });
38 |
39 | it('found dependencies', function() {
40 |
41 | // TODO Evaluate why this doesn't work
42 | // result.should.have.length(10);
43 |
44 | result.length.should.equal(10);
45 | });
46 |
47 | it('check order', function() {
48 | result.length.should.equal(10);
49 | var pkgNames = ['lodash', 'request', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'gulp', 'yo', 'should'];
50 | _.each(result, function(item, index) {
51 | item.name.should.equal( pkgNames[index] );
52 | });
53 | });
54 |
55 | it('check link replacement', function() {
56 | $('a.github-linker').length.should.equal(11);
57 | });
58 |
59 | it('link https://github.com/lodash/lodash', function() {
60 | var item = _.findWhere(result, {
61 | name: 'lodash'
62 | });
63 |
64 | (item.link === null).should.equal(false);
65 | item.link.should.equal('https://github.com/lodash/lodash');
66 |
67 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
68 | item.el.hasClass('tooltipped').should.be.false;
69 | });
70 |
71 | it('link https://www.npmjs.org/package/request', function() {
72 | var item = _.findWhere(result, {
73 | name: 'request'
74 | });
75 |
76 | (item.link === null).should.equal(false);
77 | item.link.should.equal('https://www.npmjs.org/package/request');
78 |
79 | item.el.attr('href').should.equal('https://www.npmjs.org/package/request');
80 | item.el.hasClass('tooltipped').should.be.false;
81 | });
82 |
83 | it('link https://github.com/Modernizr/Modernizr', function() {
84 | var item = _.findWhere(result, {
85 | name: 'modernizr'
86 | });
87 |
88 | (item.link === null).should.equal(false);
89 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
90 |
91 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
92 | item.el.hasClass('tooltipped').should.be.false;
93 | });
94 |
95 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
96 | var item = _.findWhere(result, {
97 | name: 'backbone'
98 | });
99 |
100 | (item.link === null).should.equal(false);
101 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
102 |
103 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
104 | item.el.hasClass('tooltipped').should.be.false;
105 | });
106 |
107 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
108 | var item = _.findWhere(result, {
109 | name: 'jquery'
110 | });
111 |
112 | (item.link === null).should.equal(false);
113 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
114 |
115 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
116 | item.el.hasClass('tooltipped').should.be.false;
117 | });
118 |
119 | it('link https://www.npmjs.org/package/unknown-package-name', function() {
120 | var item = _.findWhere(result, {
121 | name: 'unknown-package-name'
122 | });
123 |
124 | (item.link === null).should.equal(false);
125 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
126 |
127 | item.el.attr('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
128 | item.el.hasClass('tooltipped').should.be.false;
129 | });
130 |
131 | it('entry file', function() {
132 | var mainFile = $('span.nt:contains("main")').parent().find('.github-linker').attr('href');
133 | (!!mainFile).should.equal(true);
134 | mainFile.should.equal('index.js');
135 | });
136 | });
137 | });
138 | });
139 |
--------------------------------------------------------------------------------
/test/test_require_remote.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var assert = require('should');
5 | var _ = require('lodash');
6 | var env = require('jsdom').env;
7 |
8 | describe('require.js', function() {
9 |
10 | describe('remote', function() {
11 | var $, result;
12 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/require.js';
13 |
14 | before(function(done) {
15 | $ = result = null;
16 |
17 | env(url, function(err, window) {
18 | if (err) {
19 | return done(err);
20 | }
21 | $ = require('jquery')(window);
22 |
23 | githubLinkerCore(window, $, url, function(err, _result) {
24 | if (err) {
25 | throw err;
26 | }
27 | result = _result;
28 | done();
29 | });
30 | });
31 | });
32 |
33 | it('found dependencies', function() {
34 |
35 | // TODO Evaluate why this doesn't work
36 | // result.should.have.length(23);
37 |
38 | result.length.should.equal(23);
39 | });
40 |
41 | it('check link replacement', function() {
42 | $('a.github-linker').length.should.equal(20);
43 | });
44 |
45 | it('http://nodejs.org/api/path.html', function() {
46 | var item = _.findWhere(result, {
47 | name: 'path'
48 | });
49 |
50 | item.link.should.equal('http://nodejs.org/api/path.html');
51 |
52 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
53 | item.el.hasClass('tooltipped').should.be.false;
54 | });
55 |
56 | it('https://github.com/lodash/lodash', function() {
57 | var item = _.findWhere(result, {
58 | name: 'lodash'
59 | });
60 |
61 | item.link.should.equal('https://github.com/lodash/lodash');
62 |
63 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
64 | item.el.hasClass('tooltipped').should.be.false;
65 | });
66 |
67 | it('unknown-package-name', function() {
68 | var item = _.findWhere(result, {
69 | name: 'unknown-package-name'
70 | });
71 |
72 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
73 |
74 | item.el.data('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
75 | item.el.hasClass('tooltipped').should.be.false;
76 | });
77 |
78 | it('matthewmueller/uid', function() {
79 | var item = _.findWhere(result, {
80 | name: 'matthewmueller/uid'
81 | });
82 |
83 | item.resolveLink.should.be.ok;
84 | item.link.should.equal('https://github.com/matthewmueller/uid');
85 |
86 | item.el.data('href').should.equal('https://github.com/matthewmueller/uid');
87 | item.el.hasClass('tooltipped').should.be.false;
88 | });
89 |
90 | it('component/tip@master', function() {
91 | var item = _.findWhere(result, {
92 | name: 'component/tip@master'
93 | });
94 |
95 | item.resolveLink.should.be.ok;
96 | item.link.should.equal('https://github.com/component/tip/tree/master');
97 |
98 | item.el.data('href').should.equal('https://github.com/component/tip/tree/master');
99 | item.el.hasClass('tooltipped').should.be.false;
100 | });
101 |
102 | it('yields/shortcuts@0.0.1:/index.js', function() {
103 | var item = _.findWhere(result, {
104 | name: 'yields/shortcuts@0.0.1:/index.js'
105 | });
106 |
107 | item.resolveLink.should.be.ok;
108 | item.link.should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
109 |
110 | item.el.data('href').should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
111 | item.el.hasClass('tooltipped').should.be.false;
112 | });
113 |
114 | it('./file.js', function() {
115 | var item = _.findWhere(result, {
116 | name: './file.js'
117 | });
118 |
119 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
120 |
121 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
122 | item.el.hasClass('tooltipped').should.be.false;
123 | });
124 |
125 | it('./folder/file.js', function() {
126 | var item = _.findWhere(result, {
127 | name: './folder/file.js'
128 | });
129 |
130 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
131 |
132 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
133 | item.el.hasClass('tooltipped').should.be.false;
134 | });
135 |
136 | it('./file-or-folder', function() {
137 | var item = _.findWhere(result, {
138 | name: './file-or-folder'
139 | });
140 |
141 | item.resolveLink.should.be.ok;
142 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
143 |
144 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
145 | item.el.hasClass('tooltipped').should.be.false;
146 | });
147 |
148 | it('../file.js', function() {
149 | var item = _.findWhere(result, {
150 | name: '../file.js'
151 | });
152 |
153 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
154 |
155 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
156 | item.el.hasClass('tooltipped').should.be.false;
157 | });
158 |
159 | it('../folder/file.js', function() {
160 | var item = _.findWhere(result, {
161 | name: '../folder/file.js'
162 | });
163 |
164 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
165 |
166 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
167 | item.el.hasClass('tooltipped').should.be.false;
168 | });
169 |
170 | it('../file-or-folder', function() {
171 | var item = _.findWhere(result, {
172 | name: '../file-or-folder'
173 | });
174 |
175 | item.resolveLink.should.be.ok;
176 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
177 |
178 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
179 | item.el.hasClass('tooltipped').should.be.false;
180 | });
181 |
182 | it('../../file.js', function() {
183 | var item = _.findWhere(result, {
184 | name: '../../file.js'
185 | });
186 |
187 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
188 |
189 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
190 | item.el.hasClass('tooltipped').should.be.false;
191 | });
192 |
193 | it('../../folder/file.js', function() {
194 | var item = _.findWhere(result, {
195 | name: '../../folder/file.js'
196 | });
197 |
198 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
199 |
200 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
201 | item.el.hasClass('tooltipped').should.be.false;
202 | });
203 |
204 | it('../../file-or-folder', function() {
205 | var item = _.findWhere(result, {
206 | name: '../../file-or-folder'
207 | });
208 |
209 | item.resolveLink.should.be.ok;
210 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
211 |
212 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
213 | item.el.hasClass('tooltipped').should.be.false;
214 | });
215 |
216 | it('./', function() {
217 | var item = _.findWhere(result, {
218 | name: './'
219 | });
220 |
221 | item.resolveLink.should.be.ok;
222 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
223 |
224 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
225 | item.el.hasClass('tooltipped').should.be.false;
226 | });
227 |
228 | it('..', function() {
229 | var item = _.findWhere(result, {
230 | name: '..'
231 | });
232 |
233 | item.resolveLink.should.be.ok;
234 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
235 |
236 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
237 | item.el.hasClass('tooltipped').should.be.false;
238 | });
239 |
240 | it('../', function() {
241 | var item = _.findWhere(result, {
242 | name: '../'
243 | });
244 |
245 | item.resolveLink.should.be.ok;
246 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
247 |
248 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
249 | item.el.hasClass('tooltipped').should.be.false;
250 | });
251 |
252 | it('../..', function() {
253 | var item = _.findWhere(result, {
254 | name: '../..'
255 | });
256 |
257 | item.resolveLink.should.be.ok;
258 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
259 |
260 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
261 | item.el.hasClass('tooltipped').should.be.false;
262 | });
263 |
264 | it('../../', function() {
265 | var item = _.findWhere(result, {
266 | name: '../../'
267 | });
268 |
269 | item.resolveLink.should.be.ok;
270 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
271 |
272 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
273 | item.el.hasClass('tooltipped').should.be.false;
274 | });
275 |
276 | it('.', function() {
277 | var item = _.findWhere(result, {
278 | name: '.'
279 | });
280 | (item.link === '').should.equal(true);
281 | item.el.hasClass('tooltipped').should.be.true;
282 | });
283 |
284 | it('...', function() {
285 | var item = _.findWhere(result, {
286 | name: '...'
287 | });
288 |
289 | (item.link === '').should.equal(true);
290 | item.el.hasClass('tooltipped').should.be.true;
291 | });
292 |
293 | it('/', function() {
294 | var item = _.findWhere(result, {
295 | name: '/'
296 | });
297 |
298 | (item.link === '').should.equal(true);
299 | item.el.hasClass('tooltipped').should.be.true;
300 | });
301 |
302 | it('resolve url', function() {
303 | var item = _.findWhere(result, {
304 | name: '../../file-or-folder'
305 | });
306 |
307 | item.el.trigger('click');
308 | });
309 |
310 | });
311 | });
312 |
--------------------------------------------------------------------------------
/test/test_require_local.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var githubLinkerCore = require('../');
4 | var fs = require('fs');
5 | var path = require('path');
6 | var assert = require('should');
7 | var _ = require('lodash');
8 | var env = require('jsdom').env;
9 |
10 | describe('require.js', function() {
11 |
12 | describe('local', function() {
13 | var $, result;
14 | var url = 'https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/require.js';
15 | var file = path.resolve(__dirname, 'fixtures/require.js.html');
16 |
17 | before(function(done) {
18 | $ = result = null;
19 | var html = fs.readFileSync(file, 'utf-8');
20 |
21 | env(html, function(err, window) {
22 | if (err) {
23 | return done(err);
24 | }
25 | $ = require('jquery')(window);
26 |
27 | githubLinkerCore(window, $, url, function(err, _result) {
28 | if (err) {
29 | throw err;
30 | }
31 | result = _result;
32 | done();
33 | });
34 | });
35 | });
36 |
37 | it('found dependencies', function() {
38 |
39 | // TODO Evaluate why this doesn't work
40 | // result.should.have.length(23);
41 |
42 | result.length.should.equal(23);
43 | });
44 |
45 | it('check link replacement', function() {
46 | $('a.github-linker').length.should.equal(20);
47 | });
48 |
49 | it('http://nodejs.org/api/path.html', function() {
50 | var item = _.findWhere(result, {
51 | name: 'path'
52 | });
53 |
54 | item.link.should.equal('http://nodejs.org/api/path.html');
55 |
56 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
57 | item.el.hasClass('tooltipped').should.be.false;
58 | });
59 |
60 | it('https://github.com/lodash/lodash', function() {
61 | var item = _.findWhere(result, {
62 | name: 'lodash'
63 | });
64 |
65 | item.link.should.equal('https://github.com/lodash/lodash');
66 |
67 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
68 | item.el.hasClass('tooltipped').should.be.false;
69 | });
70 |
71 | it('unknown-package-name', function() {
72 | var item = _.findWhere(result, {
73 | name: 'unknown-package-name'
74 | });
75 |
76 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
77 |
78 | item.el.data('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
79 | item.el.hasClass('tooltipped').should.be.false;
80 | });
81 |
82 | it('matthewmueller/uid', function() {
83 | var item = _.findWhere(result, {
84 | name: 'matthewmueller/uid'
85 | });
86 |
87 | item.resolveLink.should.be.ok;
88 | item.link.should.equal('https://github.com/matthewmueller/uid');
89 |
90 | item.el.data('href').should.equal('https://github.com/matthewmueller/uid');
91 | item.el.hasClass('tooltipped').should.be.false;
92 | });
93 |
94 | it('component/tip@master', function() {
95 | var item = _.findWhere(result, {
96 | name: 'component/tip@master'
97 | });
98 |
99 | item.resolveLink.should.be.ok;
100 | item.link.should.equal('https://github.com/component/tip/tree/master');
101 |
102 | item.el.data('href').should.equal('https://github.com/component/tip/tree/master');
103 | item.el.hasClass('tooltipped').should.be.false;
104 | });
105 |
106 | it('yields/shortcuts@0.0.1:/index.js', function() {
107 | var item = _.findWhere(result, {
108 | name: 'yields/shortcuts@0.0.1:/index.js'
109 | });
110 |
111 | item.resolveLink.should.be.ok;
112 | item.link.should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
113 |
114 | item.el.data('href').should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
115 | item.el.hasClass('tooltipped').should.be.false;
116 | });
117 |
118 | it('./file.js', function() {
119 | var item = _.findWhere(result, {
120 | name: './file.js'
121 | });
122 |
123 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
124 |
125 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
126 | item.el.hasClass('tooltipped').should.be.false;
127 | });
128 |
129 | it('./folder/file.js', function() {
130 | var item = _.findWhere(result, {
131 | name: './folder/file.js'
132 | });
133 |
134 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
135 |
136 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
137 | item.el.hasClass('tooltipped').should.be.false;
138 | });
139 |
140 | it('./file-or-folder', function() {
141 | var item = _.findWhere(result, {
142 | name: './file-or-folder'
143 | });
144 |
145 | item.resolveLink.should.be.ok;
146 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
147 |
148 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
149 | item.el.hasClass('tooltipped').should.be.false;
150 | });
151 |
152 | it('../file.js', function() {
153 | var item = _.findWhere(result, {
154 | name: '../file.js'
155 | });
156 |
157 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
158 |
159 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
160 | item.el.hasClass('tooltipped').should.be.false;
161 | });
162 |
163 | it('../folder/file.js', function() {
164 | var item = _.findWhere(result, {
165 | name: '../folder/file.js'
166 | });
167 |
168 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
169 |
170 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
171 | item.el.hasClass('tooltipped').should.be.false;
172 | });
173 |
174 | it('../file-or-folder', function() {
175 | var item = _.findWhere(result, {
176 | name: '../file-or-folder'
177 | });
178 |
179 | item.resolveLink.should.be.ok;
180 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
181 |
182 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
183 | item.el.hasClass('tooltipped').should.be.false;
184 | });
185 |
186 | it('../../file.js', function() {
187 | var item = _.findWhere(result, {
188 | name: '../../file.js'
189 | });
190 |
191 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
192 |
193 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
194 | item.el.hasClass('tooltipped').should.be.false;
195 | });
196 |
197 | it('../../folder/file.js', function() {
198 | var item = _.findWhere(result, {
199 | name: '../../folder/file.js'
200 | });
201 |
202 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
203 |
204 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
205 | item.el.hasClass('tooltipped').should.be.false;
206 | });
207 |
208 | it('../../file-or-folder', function() {
209 | var item = _.findWhere(result, {
210 | name: '../../file-or-folder'
211 | });
212 |
213 | item.resolveLink.should.be.ok;
214 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
215 |
216 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
217 | item.el.hasClass('tooltipped').should.be.false;
218 | });
219 |
220 | it('./', function() {
221 | var item = _.findWhere(result, {
222 | name: './'
223 | });
224 |
225 | item.resolveLink.should.be.ok;
226 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
227 |
228 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
229 | item.el.hasClass('tooltipped').should.be.false;
230 | });
231 |
232 | it('..', function() {
233 | var item = _.findWhere(result, {
234 | name: '..'
235 | });
236 |
237 | item.resolveLink.should.be.ok;
238 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
239 |
240 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
241 | item.el.hasClass('tooltipped').should.be.false;
242 | });
243 |
244 | it('../', function() {
245 | var item = _.findWhere(result, {
246 | name: '../'
247 | });
248 |
249 | item.resolveLink.should.be.ok;
250 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
251 |
252 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
253 | item.el.hasClass('tooltipped').should.be.false;
254 | });
255 |
256 | it('../..', function() {
257 | var item = _.findWhere(result, {
258 | name: '../..'
259 | });
260 |
261 | item.resolveLink.should.be.ok;
262 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
263 |
264 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
265 | item.el.hasClass('tooltipped').should.be.false;
266 | });
267 |
268 | it('../../', function() {
269 | var item = _.findWhere(result, {
270 | name: '../../'
271 | });
272 |
273 | item.resolveLink.should.be.ok;
274 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
275 |
276 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
277 | item.el.hasClass('tooltipped').should.be.false;
278 | });
279 |
280 | it('.', function() {
281 | var item = _.findWhere(result, {
282 | name: '.'
283 | });
284 | (item.link === '').should.equal(true);
285 | item.el.hasClass('tooltipped').should.be.true;
286 | });
287 |
288 | it('...', function() {
289 | var item = _.findWhere(result, {
290 | name: '...'
291 | });
292 |
293 | (item.link === '').should.equal(true);
294 | item.el.hasClass('tooltipped').should.be.true;
295 | });
296 |
297 | it('/', function() {
298 | var item = _.findWhere(result, {
299 | name: '/'
300 | });
301 |
302 | (item.link === '').should.equal(true);
303 | item.el.hasClass('tooltipped').should.be.true;
304 | });
305 |
306 | it('resolve url', function() {
307 | var item = _.findWhere(result, {
308 | name: '../../file-or-folder'
309 | });
310 |
311 | item.el.trigger('click');
312 | });
313 |
314 | });
315 | });
316 |
--------------------------------------------------------------------------------
/test/fixtures/require.coffee.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | github-linker-core/require.coffee at master · stefanbuck/github-linker-core · GitHub
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Skip to content
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
167 |
168 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
493 |
494 |
495 |
496 |
512 |
513 |
514 |
515 |
516 |
517 |
518 | Something went wrong with that request. Please try again.
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
--------------------------------------------------------------------------------
/test/fixtures/require.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | github-linker-core/require.js at master · stefanbuck/github-linker-core · GitHub
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Skip to content
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
167 |
168 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
582 |
583 |
584 |
585 |
601 |
602 |
603 |
604 |
605 |
606 |
607 | Something went wrong with that request. Please try again.
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
--------------------------------------------------------------------------------
/test/fixtures/bower.json.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | github-linker-core/bower.json at master · stefanbuck/github-linker-core · GitHub
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Skip to content
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
167 |
168 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
609 |
610 |
611 |
612 |
628 |
629 |
630 |
631 |
632 |
633 |
634 | Something went wrong with that request. Please try again.
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
--------------------------------------------------------------------------------
/test/fixtures/composer.json.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | github-linker-core/composer.json at master · stefanbuck/github-linker-core · GitHub
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Skip to content
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
167 |
168 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
642 |
643 |
644 |
645 |
661 |
662 |
663 |
664 |
665 |
666 |
667 | Something went wrong with that request. Please try again.
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
--------------------------------------------------------------------------------