diff --git a/.travis.yml b/.travis.yml
index baa0031..20fd86b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,3 @@
language: node_js
node_js:
- - 0.8
+ - 0.10
diff --git a/Gruntfile.js b/Gruntfile.js
index ac19fb3..5ccdd80 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -2,7 +2,7 @@ module.exports = function(grunt) {
grunt.initConfig({
- pkg: grunt.file.readJSON('package.json'),
+ pkg: grunt.file.readJSON('bower.json'),
meta: {
banner: '/*\n' +
@@ -17,10 +17,10 @@ module.exports = function(grunt) {
bump: {
options: {
- files: ['bower.json', 'package.json'],
+ files: ['bower.json', 'github.jquery.json'],
commit: true,
commitMessage: 'Release v%VERSION%',
- commitFiles: ['bower.json', 'package.json'],
+ commitFiles: ['bower.json', 'github.jquery.json', 'dist'],
createTag: true,
tagName: '%VERSION%',
tagMessage: '',
@@ -42,7 +42,7 @@ module.exports = function(grunt) {
lintspaces: {
all: {
src: [
- '*', 'src/*', 'spec/*', 'demo/*', 'assets/base.css'
+ '*', 'src/*', 'spec/*', 'demo/*', 'assets/base.css', '!package.json'
],
options: {
newline: true,
diff --git a/README.md b/README.md
index cf57e8a..2cb5712 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,10 @@
-# jQuery Github [](https://travis-ci.org/zenorocha/jquery-github) 
+# jQuery Github
-[](http://zenorocha.github.com/jquery-github/)
+[](http://bower.io/search/?q=jquery-github)
+[](https://travis-ci.org/zenorocha/jquery-github)
+[](https://david-dm.org/zenorocha/jquery-github#info=devDependencies)
+
+[](http://zenorocha.github.io/jquery-github/)
> A jQuery plugin to display your Github Repositories.
@@ -8,7 +12,7 @@
We do care about it.
- |  |  |  | 
+ |  |  |  | 
--- | --- | --- | --- | --- |
IE 8+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
@@ -18,7 +22,7 @@ Three quick start options are available:
* [Download latest release](https://github.com/zenorocha/jquery-github/releases)
* Clone the repo: `git@github.com:zenorocha/jquery-github.git`
-* Install with [Bower](http://bower.io): `bower install bootstrap`
+* Install with [Bower](http://bower.io): `bower install jquery-github`
## Setup
@@ -35,13 +39,13 @@ Now you're ready to go!
Create an attribute called `data-repo`:
```html
-
+
```
Include jQuery:
```html
-
+
```
Include plugin's CSS and JS:
@@ -185,6 +189,10 @@ No problem, [@ricardobeat](https://github.com/ricardobeat) already did one. Chec
No problem, [@igorlima](https://github.com/igorlima) already did that. Check [demo/index-zepto.html](https://github.com/zenorocha/jquery-github/tree/master/demo/index-zepto.html).
+**Prefer AngularJS instead of jQuery?**
+
+No problem, [@lucasconstantino](https://github.com/lucasconstantino) already did that. Check [his fork](https://github.com/lucasconstantino/angular-github-repo)!
+
## Contributing
Check [CONTRIBUTING.md](https://github.com/zenorocha/jquery-github/blob/master/CONTRIBUTING.md).
diff --git a/bower.json b/bower.json
index 874fcca..f804d76 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "jquery-github",
- "version": "0.3.3",
+ "version": "0.4.0",
"homepage": "https://github.com/zenorocha/jquery-github",
"authors": [
"Zeno Rocha "
@@ -13,7 +13,7 @@
],
"license": "MIT",
"dependencies": {
- "zepto": "~1.0.0",
- "jquery": "~2.0.3"
+ "jquery": "^2.1.1",
+ "zepto": "^1.1.4"
}
}
diff --git a/demo/index.html b/demo/index.html
index a7dc9d2..265417e 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -34,7 +34,7 @@ jQuery Github
-
+
diff --git a/dist/jquery.github.js b/dist/jquery.github.js
index 08bffce..27e6de9 100644
--- a/dist/jquery.github.js
+++ b/dist/jquery.github.js
@@ -1,7 +1,7 @@
/*
- * jQuery Github - v0.3.2
+ * jquery-github - v0.4.0
* A jQuery plugin to display your Github Repositories.
- * https://github.com/zenorocha/jquery-github/
+ * https://github.com/zenorocha/jquery-github
*
* Copyright (c) 2014
* MIT License
@@ -10,91 +10,84 @@
function GithubRepo( repo ) {
this.description = repo.description;
- this.forks = repo.forks;
+ this.forks = repo.forks_count;
this.name = repo.name;
this.open_issues = repo.open_issues;
this.pushed_at = repo.pushed_at;
this.url = repo.url;
- this.watchers = repo.watchers;
+ this.stargazers = repo.stargazers_count;
}
// Parses HTML template
GithubRepo.prototype.toHTML = function () {
- var self = this;
-
- self.pushed_at = self._parsePushedDate( self.pushed_at ),
- self.url = self._parseURL( self.url );
+ this.pushed_at = this._parsePushedDate( this.pushed_at ),
+ this.url = this._parseURL( this.url );
return $(
"" +
"" +
"
" +
- "
" + self.description + " — Read More
" +
+ "
" + this.description + " — Read More
" +
"
" +
"
" +
- "
Latest commit to master on " + self.pushed_at + "
" +
- "
" +
+ "
Latest commit to master on " + this.pushed_at + "
" +
+ "
" +
"
" +
"
");
};
// Parses pushed_at with date format
GithubRepo.prototype._parsePushedDate = function ( pushed_at ) {
- var self = this,
- date = new Date( pushed_at );
+ var date = new Date( pushed_at );
return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear();
};
// Parses URL to be friendly
GithubRepo.prototype._parseURL = function ( url ) {
- var self = this;
-
return url.replace( "api.", "" ).replace( "repos/", "" );
};
// -- Github Plugin ------------------------------------------------------------
function Github( element, options ) {
- var self = this,
- defaults = {
+ var defaults = {
iconStars: true,
iconForks: true,
iconIssues: false
};
- self.element = element;
- self.$container = $( element );
- self.repo = self.$container.attr( "data-repo" );
+ this.element = element;
+ this.$container = $( element );
+ this.repo = this.$container.attr( "data-repo" );
- self.options = $.extend( {}, defaults, options ) ;
+ this.options = $.extend( {}, defaults, options ) ;
- self._defaults = defaults;
+ this._defaults = defaults;
- self.init();
- self.displayIcons();
+ this.init();
+ this.displayIcons();
}
// Initializer
Github.prototype.init = function () {
- var self = this,
- cached = self.getCache();
+ var cached = this.getCache();
if ( cached !== null ) {
- self.applyTemplate( JSON.parse( cached ) );
- }
- else {
- self.requestData( self.repo );
+ this.applyTemplate( JSON.parse( cached ) );
+ return;
}
+
+ this.requestData( this.repo );
};
// Display or hide icons
@@ -111,57 +104,49 @@ Github.prototype.displayIcons = function () {
// Request repositories from Github
Github.prototype.requestData = function ( repo ) {
- var self = this;
+ var that = this;
$.ajax({
url: "https://api.github.com/repos/" + repo,
dataType: "jsonp",
success: function( results ) {
- var result_data = results.data;
+ var result_data = results.data,
+ isFailling = results.meta.status >= 400 && result_data.message;
- // Handle API failures
- if ( results.meta.status >= 400 && result_data.message ) {
- self.handleErrorRequest( result_data );
- }
- else {
- self.handleSuccessfulRequest( result_data );
+ if ( isFailling ) {
+ that.handleErrorRequest( result_data );
+ return;
}
+
+ that.handleSuccessfulRequest( result_data );
}
});
};
// Handle Errors requests
Github.prototype.handleErrorRequest = function ( result_data ) {
- var self = this;
-
console.warn( result_data.message );
return;
};
// Handle Successful request
Github.prototype.handleSuccessfulRequest = function ( result_data ) {
- var self = this;
-
- self.applyTemplate( result_data );
- self.setCache( result_data );
+ this.applyTemplate( result_data );
+ this.setCache( result_data );
};
// Stores repostories in sessionStorage if available
Github.prototype.setCache = function ( result_data ) {
- var self = this;
-
// Cache data
if ( window.sessionStorage ) {
- window.sessionStorage.setItem( "gh-repos:" + self.repo, JSON.stringify( result_data ) );
+ window.sessionStorage.setItem( "gh-repos:" + this.repo, JSON.stringify( result_data ) );
}
};
// Grab cached results
Github.prototype.getCache = function() {
- var self = this;
-
if ( window.sessionStorage ) {
- return window.sessionStorage.getItem( "gh-repos:" + self.repo );
+ return window.sessionStorage.getItem( "gh-repos:" + this.repo );
}
else {
return false;
@@ -170,11 +155,10 @@ Github.prototype.getCache = function() {
// Apply results to HTML template
Github.prototype.applyTemplate = function ( repo ) {
- var self = this,
- githubRepo = new GithubRepo( repo ),
- $widget = githubRepo.toHTML();
+ var githubRepo = new GithubRepo( repo ),
+ $widget = githubRepo.toHTML();
- $widget.appendTo( self.$container );
+ $widget.appendTo( this.$container );
};
// -- Attach plugin to jQuery's prototype --------------------------------------
diff --git a/dist/jquery.github.min.js b/dist/jquery.github.min.js
index 394d6bd..4d06fc4 100644
--- a/dist/jquery.github.min.js
+++ b/dist/jquery.github.min.js
@@ -1,9 +1,9 @@
/*
- * jQuery Github - v0.3.3
+ * jquery-github - v0.4.0
* A jQuery plugin to display your Github Repositories.
- * https://github.com/zenorocha/jquery-github/
+ * https://github.com/zenorocha/jquery-github
*
* Copyright (c) 2014
* MIT License
*/
-function GithubRepo(a){this.description=a.description,this.forks=a.forks,this.name=a.name,this.open_issues=a.open_issues,this.pushed_at=a.pushed_at,this.url=a.url,this.watchers=a.watchers}function Github(a,b){var c=this,d={iconStars:!0,iconForks:!0,iconIssues:!1};c.element=a,c.$container=$(a),c.repo=c.$container.attr("data-repo"),c.options=$.extend({},d,b),c._defaults=d,c.init(),c.displayIcons()}GithubRepo.prototype.toHTML=function(){var a=this;return a.pushed_at=a._parsePushedDate(a.pushed_at),a.url=a._parseURL(a.url),$(""+a.description+" — Read More
Latest commit to master on "+a.pushed_at+"
")},GithubRepo.prototype._parsePushedDate=function(a){var b=new Date(a);return b.getDate()+"/"+(b.getMonth()+1)+"/"+b.getFullYear()},GithubRepo.prototype._parseURL=function(a){return a.replace("api.","").replace("repos/","")},Github.prototype.init=function(){var a=this,b=a.getCache();null!==b?a.applyTemplate(JSON.parse(b)):a.requestData(a.repo)},Github.prototype.displayIcons=function(){var a=this.options,b=$(".repo-stars"),c=$(".repo-forks"),d=$(".repo-issues");b.css("display",a.iconStars?"inline-block":"none"),c.css("display",a.iconForks?"inline-block":"none"),d.css("display",a.iconIssues?"inline-block":"none")},Github.prototype.requestData=function(a){var b=this;$.ajax({url:"https://api.github.com/repos/"+a,dataType:"jsonp",success:function(a){var c=a.data;a.meta.status>=400&&c.message?b.handleErrorRequest(c):b.handleSuccessfulRequest(c)}})},Github.prototype.handleErrorRequest=function(a){console.warn(a.message)},Github.prototype.handleSuccessfulRequest=function(a){var b=this;b.applyTemplate(a),b.setCache(a)},Github.prototype.setCache=function(a){var b=this;window.sessionStorage&&window.sessionStorage.setItem("gh-repos:"+b.repo,JSON.stringify(a))},Github.prototype.getCache=function(){var a=this;return window.sessionStorage?window.sessionStorage.getItem("gh-repos:"+a.repo):!1},Github.prototype.applyTemplate=function(a){var b=this,c=new GithubRepo(a),d=c.toHTML();d.appendTo(b.$container)},function(a){a.fn.github=function(b){return this.each(function(){a(this).data("plugin_github")||a(this).data("plugin_github",new Github(this,b))})}}(window.jQuery||window.Zepto,window);
\ No newline at end of file
+function GithubRepo(a){this.description=a.description,this.forks=a.forks_count,this.name=a.name,this.open_issues=a.open_issues,this.pushed_at=a.pushed_at,this.url=a.url,this.stargazers=a.stargazers_count}function Github(a,b){var c={iconStars:!0,iconForks:!0,iconIssues:!1};this.element=a,this.$container=$(a),this.repo=this.$container.attr("data-repo"),this.options=$.extend({},c,b),this._defaults=c,this.init(),this.displayIcons()}GithubRepo.prototype.toHTML=function(){return this.pushed_at=this._parsePushedDate(this.pushed_at),this.url=this._parseURL(this.url),$(""+this.description+" — Read More
Latest commit to master on "+this.pushed_at+"
")},GithubRepo.prototype._parsePushedDate=function(a){var b=new Date(a);return b.getDate()+"/"+(b.getMonth()+1)+"/"+b.getFullYear()},GithubRepo.prototype._parseURL=function(a){return a.replace("api.","").replace("repos/","")},Github.prototype.init=function(){var a=this.getCache();return null!==a?void this.applyTemplate(JSON.parse(a)):void this.requestData(this.repo)},Github.prototype.displayIcons=function(){var a=this.options,b=$(".repo-stars"),c=$(".repo-forks"),d=$(".repo-issues");b.css("display",a.iconStars?"inline-block":"none"),c.css("display",a.iconForks?"inline-block":"none"),d.css("display",a.iconIssues?"inline-block":"none")},Github.prototype.requestData=function(a){var b=this;$.ajax({url:"https://api.github.com/repos/"+a,dataType:"jsonp",success:function(a){var c=a.data,d=a.meta.status>=400&&c.message;return d?void b.handleErrorRequest(c):void b.handleSuccessfulRequest(c)}})},Github.prototype.handleErrorRequest=function(a){console.warn(a.message)},Github.prototype.handleSuccessfulRequest=function(a){this.applyTemplate(a),this.setCache(a)},Github.prototype.setCache=function(a){window.sessionStorage&&window.sessionStorage.setItem("gh-repos:"+this.repo,JSON.stringify(a))},Github.prototype.getCache=function(){return window.sessionStorage?window.sessionStorage.getItem("gh-repos:"+this.repo):!1},Github.prototype.applyTemplate=function(a){var b=new GithubRepo(a),c=b.toHTML();c.appendTo(this.$container)},function(a){a.fn.github=function(b){return this.each(function(){a(this).data("plugin_github")||a(this).data("plugin_github",new Github(this,b))})}}(window.jQuery||window.Zepto,window);
\ No newline at end of file
diff --git a/github.jquery.json b/github.jquery.json
index 35f90ca..4e3a30c 100644
--- a/github.jquery.json
+++ b/github.jquery.json
@@ -7,7 +7,7 @@
"repositories",
"git"
],
- "version": "0.3.3",
+ "version": "0.4.0",
"author": {
"name": "Zeno Rocha",
"url": "https://github.com/zenorocha"
diff --git a/package.json b/package.json
index 6915421..84bf932 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,17 @@
{
- "private": true,
- "devDependencies": {
- "grunt": "~0.4.1",
- "grunt-bump": "~0.0.13",
- "grunt-cli": "~0.1.7",
- "grunt-contrib-concat": "~0.3.0",
- "grunt-contrib-jasmine": "~0.5.1",
- "grunt-contrib-jshint": "~0.7.2",
- "grunt-contrib-uglify": "~0.2.0",
- "grunt-contrib-watch": "~0.5.3",
- "grunt-lintspaces": "~0.2.301"
- },
- "scripts": {
- "test": "grunt test --verbose"
- }
+ "private": true,
+ "devDependencies": {
+ "grunt": "~0.4.1",
+ "grunt-bump": "~0.0.13",
+ "grunt-cli": "~0.1.7",
+ "grunt-contrib-concat": "~0.5.0",
+ "grunt-contrib-jasmine": "~0.8.1",
+ "grunt-contrib-jshint": "~0.10.0",
+ "grunt-contrib-uglify": "~0.6.0",
+ "grunt-contrib-watch": "~0.6.1",
+ "grunt-lintspaces": "~0.6.0"
+ },
+ "scripts": {
+ "test": "grunt test --verbose"
+ }
}
diff --git a/spec/jquery.github.repo-spec.js b/spec/jquery.github.repo-spec.js
index afbb34e..28c4d12 100644
--- a/spec/jquery.github.repo-spec.js
+++ b/spec/jquery.github.repo-spec.js
@@ -6,10 +6,10 @@ describe("jquery.github.repo", function() {
instance = new GithubRepo({
name: "jquery-github",
description: "A jQuery plugin to display your Github Repositories",
- forks: 33,
+ forks_count: 33,
pushed_at: "2013-07-02T12:08:36Z",
url: "https://api.github.com/repos/zenorocha/jquery-github",
- watchers: 131
+ stargazers_count: 131
});
});
@@ -34,13 +34,8 @@ describe("jquery.github.repo", function() {
.toEqual("2013-07-02T12:08:36Z");
});
- it("should be repository's api url", function() {
- expect(instance.url)
- .toEqual("https://api.github.com/repos/zenorocha/jquery-github");
- });
-
- it("should be repository's number of watchers", function() {
- expect(instance.watchers)
+ it("should be repository's number of stargazers", function() {
+ expect(instance.stargazers)
.toEqual(131);
});
});
@@ -52,14 +47,4 @@ describe("jquery.github.repo", function() {
});
});
- describe("execute _parseURL()", function() {
- it("should parse repository's url attribute", function() {
- expect(instance._parseURL(instance.url))
- .toEqual("https://github.com/zenorocha/jquery-github");
- });
- });
-
- describe("execute toHTML()", function() {
- // TODO
- });
});
diff --git a/src/jquery.github.js b/src/jquery.github.js
index 03f8e97..97f0871 100644
--- a/src/jquery.github.js
+++ b/src/jquery.github.js
@@ -2,18 +2,17 @@
function GithubRepo( repo ) {
this.description = repo.description;
- this.forks = repo.forks;
+ this.forks = repo.forks_count;
this.name = repo.name;
this.open_issues = repo.open_issues;
this.pushed_at = repo.pushed_at;
- this.url = repo.url;
- this.watchers = repo.watchers;
+ this.url = repo.html_url;
+ this.stargazers = repo.stargazers_count;
}
// Parses HTML template
GithubRepo.prototype.toHTML = function () {
- this.pushed_at = this._parsePushedDate( this.pushed_at ),
- this.url = this._parseURL( this.url );
+ this.pushed_at = this._parsePushedDate( this.pushed_at );
return $(
"" +
@@ -22,7 +21,7 @@ GithubRepo.prototype.toHTML = function () {
"
" + this.name + "" +
"" +
"
" +
@@ -44,11 +43,6 @@ GithubRepo.prototype._parsePushedDate = function ( pushed_at ) {
return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear();
};
-// Parses URL to be friendly
-GithubRepo.prototype._parseURL = function ( url ) {
- return url.replace( "api.", "" ).replace( "repos/", "" );
-};
-
// -- Github Plugin ------------------------------------------------------------
function Github( element, options ) {
@@ -67,7 +61,6 @@ function Github( element, options ) {
this._defaults = defaults;
this.init();
- this.displayIcons();
}
// Initializer
@@ -151,6 +144,8 @@ Github.prototype.applyTemplate = function ( repo ) {
$widget = githubRepo.toHTML();
$widget.appendTo( this.$container );
+
+ this.displayIcons();
};
// -- Attach plugin to jQuery's prototype --------------------------------------