├── test
├── fixtures
│ ├── require_markdown.md
│ ├── require.coffee
│ ├── require.js
│ ├── bower.json
│ ├── composer.json
│ ├── package.json
│ ├── require_markdown.md.html
│ ├── require.coffee.html
│ ├── require.js.html
│ └── bower.json.html
├── test_require_markdown.js
├── helper.js
├── test_require_coffee.js
├── test_utils.js
├── test_manifest_bower.js
├── test_manifest_composer.js
├── test_manifest_package.js
└── test_require.js
├── .travis.yml
├── .gitignore
├── .editorconfig
├── .jshintrc
├── lib
├── flash.js
├── utils.js
├── link_builder.js
├── require.js
└── manifest.js
├── .jscsrc
├── README.md
├── CHANGELOG.md
├── package.json
├── index.js
└── gulpfile.js
/test/fixtures/require_markdown.md:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | env: CI=true
3 | node_js:
4 | - '0.10'
5 |
--------------------------------------------------------------------------------
/test/fixtures/require.coffee:
--------------------------------------------------------------------------------
1 | require "path"
2 | lodash = require("lodash")
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | temp/
3 | coverage/
4 | npm-debug.log
5 | .DS_Store
6 | .idea
7 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.jscsrc:
--------------------------------------------------------------------------------
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.text().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 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | ## v1.3.0 (2015-01-04)
4 | - Resolve `require()` in GitHub's Pull Request and Issues view.
5 | - Resolve `require()` in markdown files, if the [syntax highlighting](https://help.github.com/articles/github-flavored-markdown/#syntax-highlighting) is set to javascript.
6 |
7 | ## v1.2.0 (2014-12-04)
8 | - Add jsx support [#6](https://github.com/stefanbuck/github-linker-core/issues/6) ([Thanks @thejameskyle](https://github.com/thejameskyle))
9 | - Add options arg for the upcoming features [#7](https://github.com/stefanbuck/github-linker-core/issues/7)
10 |
11 | ## v1.1.2 (2014-10-30)
12 | - Fix selectors to solve this issue https://github.com/stefanbuck/github-linker/issues/20
13 |
14 | ## v1.1.0 (2014-10-22)
15 |
16 | - Add links to `directories` and `bin` field [#2](https://github.com/stefanbuck/github-linker-core/issues/2) ([Thanks @spacewander](https://github.com/spacewander))
17 |
18 | ## v1.0.2 (2014-10-10)
19 |
20 | - Fix css typo
21 |
22 | ## v1.0.0 (2014-09-25)
23 |
24 | - Initial version
25 |
--------------------------------------------------------------------------------
/test/test_require_markdown.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 |
7 | describe('require_markdown.md', function() {
8 |
9 | this.timeout(4000);
10 |
11 | before(function(done) {
12 | this.$ = this.result = null;
13 |
14 | helper('require_markdown.md', function(_jquery, _result) {
15 | this.$ = _jquery;
16 | this.result = _result;
17 | done();
18 | }.bind(this));
19 | });
20 |
21 | it('found dependencies', function() {
22 | this.result.length.should.equal(1);
23 | });
24 |
25 | it('check link replacement', function() {
26 | this.$('a.github-linker').length.should.equal(1);
27 | });
28 |
29 | it('https://github.com/lodash/lodash', function() {
30 | var item = _.findWhere(this.result, {
31 | name: 'lodash'
32 | });
33 |
34 | item.link.should.equal('https://github.com/lodash/lodash');
35 |
36 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
37 | item.el.hasClass('tooltipped').should.be.false;
38 | });
39 |
40 | });
41 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/test/helper.js:
--------------------------------------------------------------------------------
1 |
2 | var util = require('util');
3 | var fs = require('fs');
4 | var path = require('path');
5 | var env = require('jsdom').env;
6 | var GitHubLinkerCore = require('..');
7 |
8 | module.exports = function(file, url, done) {
9 | var $, content, baseUrl, filePath;
10 | baseUrl = 'https://github.com/stefanbuck/github-linker-core/';
11 |
12 | if (typeof url === 'function') {
13 | done = url;
14 | url = 'blob/master/test/fixtures/' + file;
15 | }
16 |
17 | url = baseUrl + url;
18 |
19 | if (process.env.TEST_ENV === 'remote') {
20 | content = url;
21 | console.log(' remote tests');
22 | } else {
23 | console.log(' local tests');
24 | filePath = util.format('./fixtures/%s.html', file);
25 | filePath = path.resolve(__dirname, filePath);
26 | content = fs.readFileSync(filePath, 'utf-8');
27 | }
28 |
29 | env(content, function(err, window) {
30 | if (err) {
31 | return done(err);
32 | }
33 | $ = require('jquery')(window);
34 |
35 | var options = {
36 | showUpdateNotification: false
37 | };
38 |
39 | new GitHubLinkerCore(window, url, options, function(err, result) {
40 | if (err) {
41 | throw err;
42 | }
43 | done($, result);
44 | });
45 | });
46 | };
47 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "github-linker-core",
3 | "description": "The GitHub Linker core",
4 | "version": "1.3.0",
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.2",
37 | "jshint-stylish": "^0.4.0",
38 | "should": "^4.0.4"
39 | },
40 | "scripts": {
41 | "test": "gulp test && TEST_ENV='remote' gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/test/test_require_coffee.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 |
7 | describe('require.coffee', function() {
8 |
9 | this.timeout(4000);
10 |
11 | before(function(done) {
12 | this.$ = this.result = null;
13 |
14 | helper('require.coffee', function(_jquery, _result) {
15 | this.$ = _jquery;
16 | this.result = _result;
17 | done();
18 | }.bind(this));
19 | });
20 |
21 | it('found dependencies', function() {
22 | // TODO Evaluate why this doesn't work
23 | // result.should.have.length(2);
24 | this.result.length.should.equal(2);
25 | });
26 |
27 | it('http://nodejs.org/api/path.html', function() {
28 | var item = _.findWhere(this.result, {
29 | name: 'path'
30 | });
31 |
32 | item.link.should.equal('http://nodejs.org/api/path.html');
33 |
34 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
35 | item.el.hasClass('tooltipped').should.be.false;
36 | });
37 |
38 | it('https://github.com/lodash/lodash', function() {
39 | var item = _.findWhere(this.result, {
40 | name: 'lodash'
41 | });
42 |
43 | item.link.should.equal('https://github.com/lodash/lodash');
44 |
45 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
46 | item.el.hasClass('tooltipped').should.be.false;
47 | });
48 | });
49 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 _ = require('lodash');
12 | var manifest = require('./lib/manifest');
13 | var reqr = require('./lib/require');
14 | var flash = require('./lib/flash');
15 | var utils = require('./lib/utils');
16 |
17 | var version = '3.2.x';
18 | var defaultOptions = {
19 | showUpdateNotification: false
20 | };
21 |
22 | var GitHubLinkerCore = function(global, url, options, cb) {
23 | options = options || {};
24 | cb = cb || function() {};
25 |
26 | this.global = global;
27 | var $ = this.global.$;
28 |
29 | if ($('.github-linker').length > 0) {
30 | return cb(null);
31 | }
32 |
33 | this.options = _.defaults(options, defaultOptions);
34 |
35 | if (this.showUpdateNotification() && this.isNewVersion()) {
36 | flash($);
37 | }
38 |
39 | if (manifest.supported(url)) {
40 | manifest.init($, url, cb);
41 | } else {
42 | reqr.init($, url, cb);
43 | }
44 | };
45 |
46 | GitHubLinkerCore.prototype.showUpdateNotification = function() {
47 | if (this.options.showUpdateNotification && utils.runInBrowser(this.global)) {
48 | return true;
49 | }
50 | return false;
51 | };
52 |
53 | GitHubLinkerCore.prototype.isNewVersion = function() {
54 | var installedVersion = this.global.localStorage.getItem('github-linker-version');
55 | if (installedVersion !== version) {
56 | this.global.localStorage.setItem('github-linker-version', version);
57 | if (installedVersion) {
58 | return true;
59 | }
60 | }
61 | return false;
62 | };
63 |
64 | module.exports = function(global, url, options, cb) {
65 | new GitHubLinkerCore(global, url, options, cb);
66 | };
67 |
--------------------------------------------------------------------------------
/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 | var onError = function(err) {
14 | plugins.util.beep();
15 |
16 | if (process.env.CI) {
17 | throw new Error(err);
18 | }
19 | };
20 |
21 | gulp.task('lint', function () {
22 | return gulp.src(paths.lint)
23 | .pipe(plugins.jshint('.jshintrc'))
24 | .pipe(plugins.plumber({
25 | errorHandler: onError
26 | }))
27 | .pipe(plugins.jscs())
28 | .pipe(plugins.jshint.reporter('jshint-stylish'));
29 | });
30 |
31 | gulp.task('istanbul', function (cb) {
32 | gulp.src(paths.source)
33 | .pipe(plugins.istanbul()) // Covering files
34 | .on('finish', function () {
35 | gulp.src(paths.tests, {cwd: __dirname})
36 | .pipe(plugins.plumber({
37 | errorHandler: onError
38 | }))
39 | .pipe(plugins.mocha())
40 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned
41 | .on('finish', function() {
42 | process.chdir(__dirname);
43 | cb();
44 | });
45 | });
46 | });
47 |
48 | gulp.task('bump', ['test'], function () {
49 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch
50 |
51 | return gulp.src(['./package.json'])
52 | .pipe(plugins.bump({ type: bumpType }))
53 | .pipe(gulp.dest('./'));
54 | });
55 |
56 | gulp.task('watch', ['istanbul'], function () {
57 | gulp.watch(paths.watch, ['istanbul']);
58 | });
59 |
60 | gulp.task('test', ['lint', 'istanbul']);
61 |
62 | gulp.task('release', ['bump']);
63 |
64 | gulp.task('default', ['test']);
65 |
--------------------------------------------------------------------------------
/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({text: function(){return 'lodash';}}).should.equal('lodash');
56 | });
57 |
58 | it('"lodash"', function() {
59 | utils.stripQuotes({text: function(){return '"lodash"';}}).should.equal('lodash');
60 | });
61 |
62 | it('\'lodash\'', function() {
63 | utils.stripQuotes({text: function(){return '\'lodash\'';}}).should.equal('lodash');
64 | });
65 |
66 | it('"lodash\'', function() {
67 | utils.stripQuotes({text: 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 |
--------------------------------------------------------------------------------
/test/test_manifest_bower.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 |
7 | describe('bower.json', function() {
8 |
9 | this.timeout(4000);
10 |
11 | before(function(done) {
12 | this.$ = this.result = null;
13 |
14 | helper('bower.json', function(_jquery, _result) {
15 | this.$ = _jquery;
16 | this.result = _result;
17 | done();
18 | }.bind(this));
19 | });
20 |
21 | it('found dependencies', function() {
22 | // TODO Evaluate why this doesn't work
23 | // this.result.should.have.length(10);
24 | this.result.length.should.equal(8);
25 | });
26 |
27 | it('check order', function() {
28 | this.result.length.should.equal(8);
29 | var pkgNames = ['lodash', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'should', 'lodash'];
30 | _.each(this.result, function(item, index) {
31 | item.name.should.equal( pkgNames[index] );
32 | });
33 | });
34 |
35 | it('check link replacement', function() {
36 | this.$('a.github-linker').length.should.equal(9);
37 | });
38 |
39 | it('link https://github.com/lodash/lodash', function() {
40 | var item = _.findWhere(this.result, {
41 | name: 'lodash'
42 | });
43 |
44 | (item.link === null).should.equal(false);
45 | item.link.should.equal('https://github.com/lodash/lodash');
46 |
47 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
48 | item.el.hasClass('tooltipped').should.be.false;
49 | });
50 |
51 | it('link https://github.com/Modernizr/Modernizr', function() {
52 | var item = _.findWhere(this.result, {
53 | name: 'modernizr'
54 | });
55 |
56 | (item.link === null).should.equal(false);
57 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
58 |
59 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
60 | item.el.hasClass('tooltipped').should.be.false;
61 | });
62 |
63 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
64 | var item = _.findWhere(this.result, {
65 | name: 'backbone'
66 | });
67 |
68 | (item.link === null).should.equal(false);
69 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
70 |
71 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
72 | item.el.hasClass('tooltipped').should.be.false;
73 | });
74 |
75 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
76 | var item = _.findWhere(this.result, {
77 | name: 'jquery'
78 | });
79 |
80 | (item.link === null).should.equal(false);
81 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
82 |
83 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
84 | item.el.hasClass('tooltipped').should.be.false;
85 | });
86 |
87 | it('link http://bower.io/search/?q=unknown-package-name', function() {
88 | var item = _.findWhere(this.result, {
89 | name: 'unknown-package-name'
90 | });
91 |
92 | (item.link === null).should.equal(false);
93 | item.link.should.equal('http://bower.io/search/?q=unknown-package-name');
94 | });
95 |
96 | it('entry file', function() {
97 | this.$('a.github-linker[href="index.js"]').length.should.equal(1);
98 | });
99 | });
100 |
--------------------------------------------------------------------------------
/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 | '.jsx': 'js',
23 | '.coffee': 'coffee'
24 | };
25 | return utils.urlMatch(url, lookup);
26 | };
27 |
28 | var attemptToLoadURL = function($, urls, cb) {
29 | var url = urls.shift();
30 | $.ajax({
31 | url: url,
32 | type: 'HEAD',
33 | timeout: 3000
34 | }).then(function() {
35 | cb(url);
36 | }).fail(function() {
37 | if (urls.length > 0) {
38 | attemptToLoadURL($, urls, cb);
39 | } else {
40 | cb(null);
41 | }
42 | });
43 | };
44 |
45 | var registerClickListener = function($, fileExtension) {
46 | fileExtension = '.' + fileExtension;
47 |
48 | $('body').on('click', 'a.github-linker', function(e) {
49 | utils.showLoader($);
50 | var $el = $(this);
51 | var link = $el.data('href');
52 |
53 | if (link) {
54 | e.stopPropagation();
55 |
56 | var urls = [];
57 | if (link.indexOf(GITHUBCOM) === 0) {
58 | if (path.extname(link)) {
59 | urls.push(link);
60 | } else {
61 | urls.push(link + fileExtension);
62 | }
63 | urls = urls.concat([
64 | link + '/index' + fileExtension,
65 | link.replace('blob', 'tree')
66 | ]);
67 | } else {
68 | urls = link.split(',');
69 | }
70 |
71 | $el.addClass('tooltipped tooltipped-e').attr('aria-label', 'Loading ...');
72 | attemptToLoadURL($, urls, function(link) {
73 | if (link) {
74 | window.location.href = link;
75 | } else {
76 | $el.attr('aria-label', SORRY);
77 | }
78 | });
79 | }
80 | });
81 | };
82 |
83 | var supported = function(url) {
84 | return !!getType(url);
85 | };
86 |
87 | var init = function($, url, cb) {
88 |
89 | var $requires, $item, name, link, resolveLink;
90 | var result = [];
91 | var type = getType(url);
92 |
93 | // Search for require dom elements
94 | $requires = $('.pl-s3').filter(function() {
95 | return $(this).text().indexOf('require') > -1;
96 | }).siblings('.pl-s1');
97 |
98 | $requires.each(function(index, item) {
99 | $item = $(item);
100 |
101 | name = utils.stripQuotes($item);
102 | link = linkBuilder(url, name);
103 | resolveLink = false;
104 |
105 | if (link) {
106 | if ( link.indexOf(RESOLVE_INDICATOR) === 0) {
107 | link = link.replace(RESOLVE_INDICATOR, '');
108 | resolveLink = true;
109 | $item = $item.wrap('').parent();
110 | } else {
111 | $item = $item.wrap('').parent();
112 | }
113 | } else {
114 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY);
115 | }
116 |
117 | result.push({
118 | el: $item,
119 | name: name,
120 | link: link,
121 | resolveLink: resolveLink
122 | });
123 | });
124 |
125 | registerClickListener($, type);
126 |
127 | cb(null, result);
128 | };
129 |
130 | module.exports = {
131 | init: init,
132 | supported: supported
133 | };
134 |
--------------------------------------------------------------------------------
/test/test_manifest_composer.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 |
7 | describe('composer.json', function() {
8 |
9 | this.timeout(4000);
10 |
11 | before(function(done) {
12 | this.$ = this.result = null;
13 |
14 | helper('composer.json', function(_jquery, _result) {
15 | this.$ = _jquery;
16 | this.result = _result;
17 | done();
18 | }.bind(this));
19 | });
20 |
21 | it('found dependencies', function() {
22 | // TODO Evaluate why this doesn't work
23 | // this.result.should.have.length(7);
24 | this.result.length.should.equal(7);
25 | });
26 |
27 | it('check order', function() {
28 | this.result.length.should.equal(7);
29 | var pkgNames = ['php', 'laravel/framework', 'unknown-package-name', 'phpunit/phpunit', 'doctrine/dbal', 'ext-openssl', 'doctrine/dbal'];
30 | _.each(this.result, function(item, index) {
31 | item.name.should.equal( pkgNames[index] );
32 | });
33 | });
34 |
35 | it('check link replacement', function() {
36 | this.$('a.github-linker').length.should.equal(4);
37 | });
38 |
39 | describe('require', function() {
40 |
41 | it('link php', function() {
42 | var item = _.findWhere(this.result, {
43 | name: 'php'
44 | });
45 |
46 | (item.link === '').should.equal(true);
47 | item.el.hasClass('tooltipped').should.be.true;
48 | });
49 |
50 | it('link laravel/framework', function() {
51 | var item = _.findWhere(this.result, {
52 | name: 'laravel/framework'
53 | });
54 |
55 | (item.link === null).should.equal(false);
56 | item.link.should.equal('https://github.com/laravel/framework');
57 |
58 | item.el.attr('href').should.equal('https://github.com/laravel/framework');
59 | item.el.hasClass('tooltipped').should.be.false;
60 | });
61 |
62 | it('link unknown-package-name', function() {
63 | var item = _.findWhere(this.result, {
64 | name: 'unknown-package-name'
65 | });
66 |
67 | (item.link === '').should.equal(true);
68 | item.el.hasClass('tooltipped').should.be.true;
69 | });
70 | });
71 |
72 | describe('require-dev', function() {
73 |
74 | it('link phpunit/phpunit', function() {
75 | var item = _.findWhere(this.result, {
76 | name: 'phpunit/phpunit'
77 | });
78 |
79 | (item.link === null).should.equal(false);
80 | item.link.should.equal('https://github.com/sebastianbergmann/phpunit');
81 |
82 | item.el.attr('href').should.equal('https://github.com/sebastianbergmann/phpunit');
83 | item.el.hasClass('tooltipped').should.be.false;
84 | });
85 |
86 | it('link doctrine/dbal', function() {
87 | var item = _.findWhere(this.result, {
88 | name: 'doctrine/dbal'
89 | });
90 |
91 | (item.link === null).should.equal(false);
92 | item.link.should.equal('https://github.com/doctrine/dbal');
93 |
94 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
95 | item.el.hasClass('tooltipped').should.be.false;
96 | });
97 | });
98 |
99 | describe('suggest', function() {
100 |
101 | it('link ext-openssl', function() {
102 | var item = _.findWhere(this.result, {
103 | name: 'ext-openssl'
104 | });
105 |
106 | (item.link === '').should.equal(true);
107 | item.el.hasClass('tooltipped').should.be.true;
108 | });
109 |
110 | it('doctrine/dbal', function() {
111 | var item = this.result[this.result.length - 1];
112 |
113 | (item.link === null).should.equal(false);
114 | item.link.should.equal('https://github.com/doctrine/dbal');
115 |
116 | item.el.attr('href').should.equal('https://github.com/doctrine/dbal');
117 | item.el.hasClass('tooltipped').should.be.false;
118 | });
119 | });
120 | });
121 |
--------------------------------------------------------------------------------
/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 getRootElement = function($, content) {
30 | return $('span.pl-s1').filter(function(){
31 | var $el = $(this);
32 | return utils.stripQuotes($el) === content && $el.index() === 0;
33 | });
34 | };
35 |
36 | var valueToLink = function($, content) {
37 | var $el = getRootElement($, content);
38 |
39 | if ($el && $el.length > 0) {
40 | $el = $el.next('*:not(".github-linker")');
41 |
42 | if ($el && $el.length > 0) {
43 | var entryFile = utils.stripQuotes($el);
44 | if (entryFile) {
45 | $el.wrap('');
46 | }
47 | }
48 | }
49 | };
50 |
51 | var mainField = function($, type) {
52 | if (type === 'npm' || type === 'bower') {
53 | valueToLink($, 'main');
54 | }
55 | };
56 |
57 | var binField = function($, type) {
58 | if (type === 'npm') {
59 | valueToLink($, 'bin');
60 | }
61 | };
62 |
63 | var directoriesField = function($) {
64 | var $dirname, $dir;
65 | var $directories = getRootElement($, 'directories');
66 |
67 | if ($directories && $directories.length > 0) {
68 | $dirname = $directories.closest('tr').next();
69 |
70 | while ($dirname) {
71 | $dir = $dirname.find('.pl-s1').eq(1);
72 | if (!$dir || !$dir.length) {
73 | return;
74 | }
75 | var entryFile = utils.stripQuotes($dir);
76 | if (entryFile) {
77 | $dir.wrap('');
78 | }
79 |
80 | $dirname = $dirname.next();
81 | }
82 | }
83 | };
84 |
85 | var dependencieField = function($, type) {
86 | var $root, $row, $item, $version, name, version, link;
87 | var selectors = [];
88 | if (type === 'npm') {
89 | selectors = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
90 | } else if (type === 'bower') {
91 | selectors = ['dependencies', 'devDependencies', 'resolutions'];
92 | } else if (type === 'composer') {
93 | selectors = ['require', 'require-dev', 'conflict', 'replace', 'provide', 'suggest'];
94 | }
95 |
96 | var result = [];
97 |
98 | selectors.forEach(function(selector) {
99 | $root = getRootElement($, selector);
100 |
101 | if (!$root || $root.length === 0) {
102 | return;
103 | }
104 |
105 | $row = $root.closest('tr').next();
106 |
107 | while ($row) {
108 | $item = $row.find('.pl-s1').eq(0);
109 | $version = $row.find('.pl-s1').eq(1);
110 |
111 | if (!$item.length || !$version.length) {
112 | return;
113 | }
114 |
115 | name = utils.stripQuotes($item);
116 | version = utils.stripQuotes($version);
117 |
118 | link = linkBuilder(type, name, version);
119 |
120 | if (link) {
121 | $item = $item.wrap('').parent();
122 | } else {
123 | $item.addClass('tooltipped tooltipped-e').attr('aria-label', SORRY);
124 | }
125 |
126 | result.push({
127 | el: $item,
128 | version: version,
129 | name: name,
130 | link: link
131 | });
132 |
133 | $row = $row.next();
134 | }
135 | });
136 | return result;
137 | };
138 |
139 | var init = function($, url, cb) {
140 |
141 | var type = getType(url);
142 | if (type === 'npm') {
143 | directoriesField($);
144 | }
145 | var result = dependencieField($, type);
146 | // put them below dependencieField to avoid conflict
147 | mainField($, type);
148 | binField($, type);
149 |
150 | cb(null, result);
151 | };
152 |
153 | module.exports = {
154 | init: init,
155 | supported: supported
156 | };
157 |
--------------------------------------------------------------------------------
/test/test_manifest_package.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var assert = require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 | var registries = require('github-linker-cache');
7 |
8 | describe('package.json', function() {
9 |
10 | this.timeout(4000);
11 |
12 | before(function(done) {
13 | this.$ = this.result = null;
14 |
15 | registries.npm = {
16 | lodash: 'https://github.com/lodash/lodash'
17 | };
18 |
19 | helper('package.json', function(_jquery, _result) {
20 | this.$ = _jquery;
21 | this.result = _result;
22 | done();
23 | }.bind(this));
24 | });
25 |
26 | it('found dependencies', function() {
27 | // TODO Evaluate why this doesn't work
28 | // this.result.should.have.length(10);
29 | this.result.length.should.equal(10);
30 | });
31 |
32 | it('check order', function() {
33 | this.result.length.should.equal(10);
34 | var pkgNames = ['lodash', 'request', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'gulp', 'yo', 'should'];
35 | _.each(this.result, function(item, index) {
36 | item.name.should.equal( pkgNames[index] );
37 | });
38 | });
39 |
40 | it('check link replacement', function() {
41 | this.$('a.github-linker').length.should.equal(14);
42 | });
43 |
44 | it('link https://github.com/lodash/lodash', function() {
45 | var item = _.findWhere(this.result, {
46 | name: 'lodash'
47 | });
48 |
49 | (item.link === null).should.equal(false);
50 | item.link.should.equal('https://github.com/lodash/lodash');
51 |
52 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
53 | item.el.hasClass('tooltipped').should.be.false;
54 | });
55 |
56 | it('link https://www.npmjs.org/package/request', function() {
57 | var item = _.findWhere(this.result, {
58 | name: 'request'
59 | });
60 |
61 | (item.link === null).should.equal(false);
62 | item.link.should.equal('https://www.npmjs.org/package/request');
63 |
64 | item.el.attr('href').should.equal('https://www.npmjs.org/package/request');
65 | item.el.hasClass('tooltipped').should.be.false;
66 | });
67 |
68 | it('link https://github.com/Modernizr/Modernizr', function() {
69 | var item = _.findWhere(this.result, {
70 | name: 'modernizr'
71 | });
72 |
73 | (item.link === null).should.equal(false);
74 | item.link.should.equal('https://github.com/Modernizr/Modernizr');
75 |
76 | item.el.attr('href').should.equal('https://github.com/Modernizr/Modernizr');
77 | item.el.hasClass('tooltipped').should.be.false;
78 | });
79 |
80 | it('link https://github.com/jashkenas/backbone/tree/master', function() {
81 | var item = _.findWhere(this.result, {
82 | name: 'backbone'
83 | });
84 |
85 | (item.link === null).should.equal(false);
86 | item.link.should.equal('https://github.com/jashkenas/backbone/tree/master');
87 |
88 | item.el.attr('href').should.equal('https://github.com/jashkenas/backbone/tree/master');
89 | item.el.hasClass('tooltipped').should.be.false;
90 | });
91 |
92 | it('link https://github.com/jquery/jquery/tree/1.x-master', function() {
93 | var item = _.findWhere(this.result, {
94 | name: 'jquery'
95 | });
96 |
97 | (item.link === null).should.equal(false);
98 | item.link.should.equal('https://github.com/jquery/jquery/tree/1.x-master');
99 |
100 | item.el.attr('href').should.equal('https://github.com/jquery/jquery/tree/1.x-master');
101 | item.el.hasClass('tooltipped').should.be.false;
102 | });
103 |
104 | it('link https://www.npmjs.org/package/unknown-package-name', function() {
105 | var item = _.findWhere(this.result, {
106 | name: 'unknown-package-name'
107 | });
108 |
109 | (item.link === null).should.equal(false);
110 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
111 |
112 | item.el.attr('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
113 | item.el.hasClass('tooltipped').should.be.false;
114 | });
115 |
116 | it('link directories', function() {
117 | this.$('a.github-linker[href="./main"]').length.should.equal(1);
118 | this.$('a.github-linker[href="./bin"]').length.should.equal(1);
119 | });
120 |
121 | it('entry file', function() {
122 | this.$('a.github-linker[href="index.js"]').length.should.equal(1);
123 | });
124 |
125 | it('bin file', function() {
126 | this.$('a.github-linker[href="./index.js"]').length.should.equal(1);
127 | });
128 | });
129 |
--------------------------------------------------------------------------------
/test/test_require.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | require('should');
4 | var _ = require('lodash');
5 | var helper = require('./helper');
6 |
7 | describe('require.js', function() {
8 |
9 | this.timeout(4000);
10 |
11 | before(function(done) {
12 | this.$ = this.result = null;
13 |
14 | helper('require.js', function(_jquery, _result) {
15 | this.$ = _jquery;
16 | this.result = _result;
17 | done();
18 | }.bind(this));
19 | });
20 |
21 | it('found dependencies', function() {
22 | // TODO Evaluate why this doesn't work
23 | // this.result.should.have.length(23);
24 | this.result.length.should.equal(23);
25 | });
26 |
27 | it('check link replacement', function() {
28 | this.$('a.github-linker').length.should.equal(20);
29 | });
30 |
31 | it('http://nodejs.org/api/path.html', function() {
32 | var item = _.findWhere(this.result, {
33 | name: 'path'
34 | });
35 |
36 | item.link.should.equal('http://nodejs.org/api/path.html');
37 |
38 | item.el.attr('href').should.equal('http://nodejs.org/api/path.html');
39 | item.el.hasClass('tooltipped').should.be.false;
40 | });
41 |
42 | it('https://github.com/lodash/lodash', function() {
43 | var item = _.findWhere(this.result, {
44 | name: 'lodash'
45 | });
46 |
47 | item.link.should.equal('https://github.com/lodash/lodash');
48 |
49 | item.el.attr('href').should.equal('https://github.com/lodash/lodash');
50 | item.el.hasClass('tooltipped').should.be.false;
51 | });
52 |
53 | it('unknown-package-name', function() {
54 | var item = _.findWhere(this.result, {
55 | name: 'unknown-package-name'
56 | });
57 |
58 | item.link.should.equal('https://www.npmjs.org/package/unknown-package-name');
59 |
60 | item.el.data('href').should.equal('https://www.npmjs.org/package/unknown-package-name');
61 | item.el.hasClass('tooltipped').should.be.false;
62 | });
63 |
64 | it('matthewmueller/uid', function() {
65 | var item = _.findWhere(this.result, {
66 | name: 'matthewmueller/uid'
67 | });
68 |
69 | item.resolveLink.should.be.ok;
70 | item.link.should.equal('https://github.com/matthewmueller/uid');
71 |
72 | item.el.data('href').should.equal('https://github.com/matthewmueller/uid');
73 | item.el.hasClass('tooltipped').should.be.false;
74 | });
75 |
76 | it('component/tip@master', function() {
77 | var item = _.findWhere(this.result, {
78 | name: 'component/tip@master'
79 | });
80 |
81 | item.resolveLink.should.be.ok;
82 | item.link.should.equal('https://github.com/component/tip/tree/master');
83 |
84 | item.el.data('href').should.equal('https://github.com/component/tip/tree/master');
85 | item.el.hasClass('tooltipped').should.be.false;
86 | });
87 |
88 | it('yields/shortcuts@0.0.1:/index.js', function() {
89 | var item = _.findWhere(this.result, {
90 | name: 'yields/shortcuts@0.0.1:/index.js'
91 | });
92 |
93 | item.resolveLink.should.be.ok;
94 | item.link.should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
95 |
96 | item.el.data('href').should.equal('https://github.com/yields/shortcuts/blob/0.0.1/index.js');
97 | item.el.hasClass('tooltipped').should.be.false;
98 | });
99 |
100 | it('./file.js', function() {
101 | var item = _.findWhere(this.result, {
102 | name: './file.js'
103 | });
104 |
105 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
106 |
107 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file.js');
108 | item.el.hasClass('tooltipped').should.be.false;
109 | });
110 |
111 | it('./folder/file.js', function() {
112 | var item = _.findWhere(this.result, {
113 | name: './folder/file.js'
114 | });
115 |
116 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
117 |
118 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/folder/file.js');
119 | item.el.hasClass('tooltipped').should.be.false;
120 | });
121 |
122 | it('./file-or-folder', function() {
123 | var item = _.findWhere(this.result, {
124 | name: './file-or-folder'
125 | });
126 |
127 | item.resolveLink.should.be.ok;
128 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
129 |
130 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures/file-or-folder');
131 | item.el.hasClass('tooltipped').should.be.false;
132 | });
133 |
134 | it('../file.js', function() {
135 | var item = _.findWhere(this.result, {
136 | name: '../file.js'
137 | });
138 |
139 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
140 |
141 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file.js');
142 | item.el.hasClass('tooltipped').should.be.false;
143 | });
144 |
145 | it('../folder/file.js', function() {
146 | var item = _.findWhere(this.result, {
147 | name: '../folder/file.js'
148 | });
149 |
150 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
151 |
152 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/folder/file.js');
153 | item.el.hasClass('tooltipped').should.be.false;
154 | });
155 |
156 | it('../file-or-folder', function() {
157 | var item = _.findWhere(this.result, {
158 | name: '../file-or-folder'
159 | });
160 |
161 | item.resolveLink.should.be.ok;
162 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
163 |
164 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/file-or-folder');
165 | item.el.hasClass('tooltipped').should.be.false;
166 | });
167 |
168 | it('../../file.js', function() {
169 | var item = _.findWhere(this.result, {
170 | name: '../../file.js'
171 | });
172 |
173 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
174 |
175 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file.js');
176 | item.el.hasClass('tooltipped').should.be.false;
177 | });
178 |
179 | it('../../folder/file.js', function() {
180 | var item = _.findWhere(this.result, {
181 | name: '../../folder/file.js'
182 | });
183 |
184 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
185 |
186 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/folder/file.js');
187 | item.el.hasClass('tooltipped').should.be.false;
188 | });
189 |
190 | it('../../file-or-folder', function() {
191 | var item = _.findWhere(this.result, {
192 | name: '../../file-or-folder'
193 | });
194 |
195 | item.resolveLink.should.be.ok;
196 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
197 |
198 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/file-or-folder');
199 | item.el.hasClass('tooltipped').should.be.false;
200 | });
201 |
202 | it('./', function() {
203 | var item = _.findWhere(this.result, {
204 | name: './'
205 | });
206 |
207 | item.resolveLink.should.be.ok;
208 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
209 |
210 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test/fixtures');
211 | item.el.hasClass('tooltipped').should.be.false;
212 | });
213 |
214 | it('..', function() {
215 | var item = _.findWhere(this.result, {
216 | name: '..'
217 | });
218 |
219 | item.resolveLink.should.be.ok;
220 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
221 |
222 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
223 | item.el.hasClass('tooltipped').should.be.false;
224 | });
225 |
226 | it('../', function() {
227 | var item = _.findWhere(this.result, {
228 | name: '../'
229 | });
230 |
231 | item.resolveLink.should.be.ok;
232 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
233 |
234 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master/test');
235 | item.el.hasClass('tooltipped').should.be.false;
236 | });
237 |
238 | it('../..', function() {
239 | var item = _.findWhere(this.result, {
240 | name: '../..'
241 | });
242 |
243 | item.resolveLink.should.be.ok;
244 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
245 |
246 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
247 | item.el.hasClass('tooltipped').should.be.false;
248 | });
249 |
250 | it('../../', function() {
251 | var item = _.findWhere(this.result, {
252 | name: '../../'
253 | });
254 |
255 | item.resolveLink.should.be.ok;
256 | item.link.should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
257 |
258 | item.el.data('href').should.equal('https://github.com/stefanbuck/github-linker-core/blob/master');
259 | item.el.hasClass('tooltipped').should.be.false;
260 | });
261 |
262 | it('.', function() {
263 | var item = _.findWhere(this.result, {
264 | name: '.'
265 | });
266 | (item.link === '').should.equal(true);
267 | item.el.hasClass('tooltipped').should.be.true;
268 | });
269 |
270 | it('...', function() {
271 | var item = _.findWhere(this.result, {
272 | name: '...'
273 | });
274 |
275 | (item.link === '').should.equal(true);
276 | item.el.hasClass('tooltipped').should.be.true;
277 | });
278 |
279 | it('/', function() {
280 | var item = _.findWhere(this.result, {
281 | name: '/'
282 | });
283 |
284 | (item.link === '').should.equal(true);
285 | item.el.hasClass('tooltipped').should.be.true;
286 | });
287 |
288 | it('resolve url', function() {
289 | var item = _.findWhere(this.result, {
290 | name: '../../file-or-folder'
291 | });
292 |
293 | item.el.trigger('click');
294 | });
295 | });
296 |
--------------------------------------------------------------------------------
/test/fixtures/require_markdown.md.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | github-linker-core/require_markdown.md at master · stefanbuck/github-linker-core · GitHub
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 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | Skip to content
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
176 |
177 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
525 |
526 |
527 |
528 |
547 |
548 |
549 |
550 |
551 |
552 |
553 | Something went wrong with that request. Please try again.
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
--------------------------------------------------------------------------------
/test/fixtures/require.coffee.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | github-linker-core/require.coffee at master · stefanbuck/github-linker-core · GitHub
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 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | Skip to content
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
176 |
177 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
514 |
515 |
516 |
517 |
536 |
537 |
538 |
539 |
540 |
541 |
542 | Something went wrong with that request. Please try again.
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
--------------------------------------------------------------------------------
/test/fixtures/require.js.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | github-linker-core/require.js at master · stefanbuck/github-linker-core · GitHub
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 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | Skip to content
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
176 |
177 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
624 |
625 |
626 |
627 |
646 |
647 |
648 |
649 |
650 |
651 |
652 | Something went wrong with that request. Please try again.
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
--------------------------------------------------------------------------------
/test/fixtures/bower.json.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | github-linker-core/bower.json at master · stefanbuck/github-linker-core · GitHub
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 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | Skip to content
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
176 |
177 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
630 |
631 |
632 |
633 |
652 |
653 |
654 |
655 |
656 |
657 |
658 | Something went wrong with that request. Please try again.
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
--------------------------------------------------------------------------------