Navigation Menu

Skip to content

Commit

Permalink
[close #1] First spec, linkify simple value
Browse files Browse the repository at this point in the history
  • Loading branch information
cmilfont committed May 22, 2012
1 parent 00c4752 commit fc4179f
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build
@@ -0,0 +1,5 @@
#!/bin/bash
#
#https://github.com/dsimard/ready.js

readyjs ready.conf.js
16 changes: 16 additions & 0 deletions lib/linkify.js
@@ -0,0 +1,16 @@
(function($){

var noProtocolUrl = /(^|["'(\s]|<)(www\..+?\..+?)((?:[:?]|\.+)?(?=(?:\s|$)|>|[)"',]))/g,
httpOrMailtoUrl = /(^|["'(\s]|<)((?:(?:https?|ftp):\/\/|mailto:).+?)((?:[:?]|\.+)?(?=(?:\s|$)|>|[)"',]))/g;

$.fn.linkify = function() {
$(this).html(
$(this).html()
.replace( noProtocolUrl, '$1<a href="<``>://$2">$2</a>$3' )
.replace( httpOrMailtoUrl, '$1<a href="$2">$2</a>$3' )
.replace( /"<``>/g, '"http' )
);
return $(this);
};

})(jQuery);
2 changes: 2 additions & 0 deletions minified/linkify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions package.json
@@ -0,0 +1,18 @@
{ "name" : "linkify"
, "version" : "0.0.1"
, "description" : "Linkify plugin for jQuery"
, "main" : "runspecs.js"
, "scripts" :
{
"test": "node runspecs.js"
}
, "dependencies" :
{
"dox" : "0.0.5",
"ready.js" : "1.3.3",
"jsdom" : "0.2.0",
"jquery" : "1.5.1",
"jasmine-node" : "1.0.6"
}
, "engines" : { "node" : ">=v0.4.12" }
}
7 changes: 7 additions & 0 deletions ready.conf.js
@@ -0,0 +1,7 @@
{
"src" : "./lib"
, "dest" : "./minified"
, "runGCompiler" : true
, runJslint : true
, aggregateTo : "linkify.min.js"
}
15 changes: 15 additions & 0 deletions runspecs.js
@@ -0,0 +1,15 @@
global.window = require("jsdom")
.jsdom()
.createWindow();
global.jQuery = require("jquery").create(window);

var jasmine = require('jasmine-node');

require(__dirname + "/lib/linkify.js")

var isVerbose = true;
var showColors = true;
jasmine.executeSpecsInFolder(__dirname + '/specs', function(runner, log){
process.exit(runner.results().failedCount?1:0);
}, isVerbose, showColors);

35 changes: 35 additions & 0 deletions specs/linkifydiv.spec.js
@@ -0,0 +1,35 @@
var linkify = function(url) {
return jQuery("<div>").html(url).linkify();
},
linkifiedWithHttps = "<a href=\"https://www.mifont.org\">https://www.mifont.org</a>",
linkifiedWithHttp = "<a href=\"http://www.mifont.org\">http://www.mifont.org</a>",
linkified = "<a href=\"http://www.mifont.org\">www.mifont.org</a>";


describe("Linkify simple value", function() {

describe("When there is protocol in URL", function() {

beforeEach( function () {
jQuery("body").html("");
});

it('should url with http', function(){
expect( linkifiedWithHttp ).toEqual( linkify("http://www.mifont.org").html() );
});

it('should url with https', function(){
expect( linkifiedWithHttps ).toEqual( linkify("https://www.mifont.org").html() );
});

});

describe("When there isn't protocol in URL", function() {

it('should url with http', function(){
expect( linkified ).toEqual( linkify("www.mifont.org").html() );
});

});

});
14 changes: 14 additions & 0 deletions testrunner
@@ -0,0 +1,14 @@
#!/bin/bash
#
#instrument files
#https://github.com/visionmedia/node-jscoverage
#node-jscoverage lib lib-cov
#TODO

#dox --title JSONForm lib/jsonform.js > docs/index.html

#https://github.com/dsimard/ready.js
readyjs ready.conf.js

#execute tests
node runspecs.js
4 changes: 4 additions & 0 deletions vendor/jquery-1.7.1.min.js

Large diffs are not rendered by default.

0 comments on commit fc4179f

Please sign in to comment.