diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..b608236 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# This file is for unifying the coding style for different editors and IDEs +# editorconfig.org + +root = true + +[*] +indent_style = tab +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore index 496ee2c..0bc7c71 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.DS_Store \ No newline at end of file +.DS_Store +node_modules +bower_components diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..fff0d5e --- /dev/null +++ b/.jshintrc @@ -0,0 +1,17 @@ +{ + "boss": true, + "curly": true, + "eqeqeq": true, + "eqnull": true, + "expr": true, + "immed": true, + "noarg": true, + "onevar": true, + "quotmark": "double", + "smarttabs": true, + "trailing": true, + "undef": false, + "unused": false, + "node": true, + "multistr": true +} diff --git a/.travis.yml b/.travis.yml index c2ba3f9..20fd86b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: node_js node_js: - - 0.8 \ No newline at end of file + - 0.10 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5fbd9fb --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing + +1. Fork it! +2. Create your feature branch: `git checkout -b my-new-feature` +3. Commit your changes: `git commit -m 'Add some feature'` +4. Push to the branch: `git push origin my-new-feature` +5. Submit a pull request :D + +Don't edit files under `dist` folder, those are generated after running `grunt` command, edit files under `src` folder instead. + +Also remember to follow [jQuery's Code Style](http://contribute.jquery.org/style-guide/js/). diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..5ccdd80 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,101 @@ +module.exports = function(grunt) { + + grunt.initConfig({ + + pkg: grunt.file.readJSON('bower.json'), + + meta: { + banner: '/*\n' + + ' * <%= pkg.title || pkg.name %> - v<%= pkg.version %>\n' + + ' * <%= pkg.description %>\n' + + ' * <%= pkg.homepage %>\n' + + ' *\n' + + ' * Copyright (c) <%= grunt.template.today("yyyy") %>\n' + + ' * MIT License\n' + + ' */\n' + }, + + bump: { + options: { + files: ['bower.json', 'github.jquery.json'], + commit: true, + commitMessage: 'Release v%VERSION%', + commitFiles: ['bower.json', 'github.jquery.json', 'dist'], + createTag: true, + tagName: '%VERSION%', + tagMessage: '', + push: true, + pushTo: 'origin' + } + }, + + concat: { + options: { + banner: '<%= meta.banner %>' + }, + dist: { + src: ['src/jquery.github.js'], + dest: 'dist/jquery.github.js' + } + }, + + lintspaces: { + all: { + src: [ + '*', 'src/*', 'spec/*', 'demo/*', 'assets/base.css', '!package.json' + ], + options: { + newline: true, + trailingspaces: true, + indentation: 'tabs', + spaces: 2 + } + } + }, + + jasmine: { + src: 'src/jquery.github.js', + options: { + specs: 'spec/*spec.js', + helpers: 'spec/helpers/*.js', + vendor: 'lib/jquery.min.js' + } + }, + + jshint: { + files: ['src/jquery.github.js'], + options: { + jshintrc: ".jshintrc" + } + }, + + uglify: { + options: { + banner: '<%= meta.banner %>' + }, + my_target: { + src: ['dist/jquery.github.js'], + dest: 'dist/jquery.github.min.js' + } + }, + + watch: { + files: ['**/*'], + tasks: ['jshint', 'concat', 'uglify'], + } + + }); + + grunt.loadNpmTasks('grunt-bump'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-jasmine'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-watch'); + grunt.loadNpmTasks('grunt-lintspaces'); + + grunt.registerTask('default', ['lintspaces', 'jshint', 'concat', 'uglify']); + grunt.registerTask('release', ['bump-only:patch', 'default', 'bump-commit']); + grunt.registerTask('test', ['lintspaces', 'jshint', 'jasmine']); + +}; diff --git a/README.md b/README.md index a4cfb42..2cb5712 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,51 @@ -# jQuery Github [![Build Status](https://secure.travis-ci.org/zenorocha/jquery-github.png?branch=master)](https://travis-ci.org/zenorocha/jquery-github) +# jQuery Github -[![Github Repo Demonstration](http://f.cl.ly/items/2I3u29002A1g2w1R1I0X/Screen%20Shot%202013-01-17%20at%202.16.36%20PM.png)](http://zenorocha.github.com/jquery-github/) +[![Bower version](http://img.shields.io/bower/v/jquery-github.svg?style=flat)](http://bower.io/search/?q=jquery-github) +[![Build Status](http://img.shields.io/travis/zenorocha/jquery-github/master.svg?style=flat)](https://travis-ci.org/zenorocha/jquery-github) +[![DevDependencies Status](http://img.shields.io/david/dev/zenorocha/jquery-github.svg?style=flat)](https://david-dm.org/zenorocha/jquery-github#info=devDependencies) + +[![Github Repo Demonstration](https://cloud.githubusercontent.com/assets/398893/3528396/064b1fa4-078f-11e4-8460-2593d190c2fc.png)](http://zenorocha.github.io/jquery-github/) + +> A jQuery plugin to display your Github Repositories. + +## Browser Support + +We do care about it. + +![IE](https://cloud.githubusercontent.com/assets/398893/3528325/20373e76-078e-11e4-8e3a-1cb86cf506f0.png) | ![Chrome](https://cloud.githubusercontent.com/assets/398893/3528328/23bc7bc4-078e-11e4-8752-ba2809bf5cce.png) | ![Firefox](https://cloud.githubusercontent.com/assets/398893/3528329/26283ab0-078e-11e4-84d4-db2cf1009953.png) | ![Opera](https://cloud.githubusercontent.com/assets/398893/3528330/27ec9fa8-078e-11e4-95cb-709fd11dac16.png) | ![Safari](https://cloud.githubusercontent.com/assets/398893/3528331/29df8618-078e-11e4-8e3e-ed8ac738693f.png) +--- | --- | --- | --- | --- | +IE 8+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | + +## Getting started + +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 jquery-github` + +## Setup + +Use [Bower](http://bower.io) to fetch all dependencies: + +```sh +$ bower install +``` + +Now you're ready to go! ## Usage Create an attribute called `data-repo`: ```html -
+
``` Include jQuery: ```html - + ``` Include plugin's CSS and JS: @@ -26,50 +58,153 @@ Include plugin's CSS and JS: Call the plugin: ```javascript -$('[data-repo]').github(); +$("[data-repo]").github(); ``` And that's it \o/ -[Check the full example here](https://github.com/zenorocha/jquery-github/blob/master/demo/index.html) +[Check full example's source code](https://github.com/zenorocha/jquery-github/blob/master/demo/index.html). + +## Options + +Here's a list of available settings. + +```javascript +$("[data-repo]").github({ + iconStars: true, + iconForks: true, + iconIssues: false +}); +``` + +Attribute | Type | Default | Description +--- | --- | --- | --- +`iconStars` | *Boolean* | `true` | Displays the number of stars in a repository. +`iconForks` | *Boolean* | `true` | Displays the number of forks in a repository. +`iconIssues` | *Boolean* | `false` | Displays the number of issues in a repository. + +## Structure + +The basic structure of the project is given in the following way: + +``` +. +|-- assets/ +|-- demo/ +| |-- index.html +| |-- index-zepto.html +|-- dist/ +| |-- jquery.boilerplate.js +| |-- jquery.boilerplate.min.js +|-- src/ +| |-- jquery.boilerplate.coffee +| |-- jquery.boilerplate.js +|-- .editorconfig +|-- .gitignore +|-- .jshintrc +|-- .travis.yml +|-- github.jquery.json +|-- Gruntfile.js +`-- package.json +``` + +#### [assets/](https://github.com/zenorocha/jquery-github/tree/master/assets) + +Contains CSS and Font files to create that lovely Github box. + +#### bower_components/ + +Contains all dependencies like jQuery and Zepto. + +#### [demo/](https://github.com/zenorocha/jquery-github/tree/master/demo) + +Contains a simple HTML file to demonstrate the plugin. + +#### [dist/](https://github.com/zenorocha/jquery-github/tree/master/dist) + +This is where the generated files are stored once Grunt runs JSHint and other stuff. + +#### [src/](https://github.com/zenorocha/jquery-github/tree/master/src) + +Contains the files responsible for the plugin. + +#### [.editorconfig](https://github.com/zenorocha/jquery-github/tree/master/.editorconfig) + +This file is for unifying the coding style for different editors and IDEs. + +> Check [editorconfig.org](http://editorconfig.org) if you haven't heard about this project yet. + +#### [.gitignore](https://github.com/zenorocha/jquery-github/tree/master/.gitignore) + +List of files that we don't want Git to track. + +> Check this [Git Ignoring Files Guide](https://help.github.com/articles/ignoring-files) for more details. + +#### [.jshintrc](https://github.com/zenorocha/jquery-github/tree/master/.jshintrc) + +List of rules used by JSHint to detect errors and potential problems in JavaScript. + +> Check [jshint.com](http://jshint.com/about/) if you haven't heard about this project yet. + +#### [.travis.yml](https://github.com/zenorocha/jquery-github/tree/master/.travis.yml) + +Definitions for continous integration using Travis. + +> Check [travis-ci.org](http://about.travis-ci.org/) if you haven't heard about this project yet. + +#### [github.jquery.json](https://github.com/zenorocha/jquery-github/tree/master/github.jquery.json) + +Package manifest file used to publish plugins in jQuery Plugin Registry. + +> Check this [Package Manifest Guide](http://plugins.jquery.com/docs/package-manifest/) for more details. + +#### [Gruntfile.js](https://github.com/zenorocha/jquery-github/tree/master/Gruntfile.js) + +Contains all automated tasks using Grunt. + +> Check [gruntjs.com](http://gruntjs.com) if you haven't heard about this project yet. + +#### [package.json](https://github.com/zenorocha/jquery-github/tree/master/package.json) + +Specify all dependencies loaded via Node.JS. + +> Check [NPM](https://npmjs.org/doc/json.html) for more details. + +## Showcase + +* [zenorocha.com/projects](http://zenorocha.com/projects/) +* [anasnakawa.com/projects](http://anasnakawa.com/projects/) + +**Have you used this plugin in your project?** + +Let me know! Send a [tweet](http://twitter.com/zenorocha) or [pull request](https://github.com/zenorocha/jquery-github/pull/new/master) and I'll add it here :) + +## Alternatives + +**Prefer a non-jquery version with pure JavaScript?** + +No problem, [@ricardobeat](https://github.com/ricardobeat) already did one. Check [his fork](https://github.com/ricardobeat/github-repos)! + +**Prefer Zepto instead of jQuery?** + +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). -## Forks +**Prefer AngularJS instead of jQuery?** -Prefer a non-jquery version with pure JavaScript? No problem, [@ricardobeat](https://github.com/ricardobeat) already did one :) Check [his fork!](https://github.com/ricardobeat/github-repos) +No problem, [@lucasconstantino](https://github.com/lucasconstantino) already did that. Check [his fork](https://github.com/lucasconstantino/angular-github-repo)! ## Contributing -1. Fork it! -2. Create your feature branch: `git checkout -b my-new-feature` -3. Commit your changes: `git commit -am 'Add some feature'` -4. Push to the branch: `git push origin my-new-feature` -5. Submit a pull request :D +Check [CONTRIBUTING.md](https://github.com/zenorocha/jquery-github/blob/master/CONTRIBUTING.md). ## History -* v0.2.4 January 17, 2013 - * Renamed from `jquery-github-repos` to `jquery-github` -* v0.2.3 January 17, 2013 - * Added to jQuery Plugins Registry - * Updated to jQuery v1.9 -* v0.2.2 January 15, 2013 - * Fixed "Last commit" date - * Cached repo data using sessionStorage - * Added error message if API exceeds its limits -* v0.2.1 January 13, 2013 - * Added live demo - * Replaced single images for a sprite - * Added minified version -* v0.2 September 11, 2012 - * Code wrapped into a jQuery plugin - * Demonstration page created -* v0.1 September 10, 2012 - * Initial commit +Check [Releases](https://github.com/zenorocha/jquery-github/releases) for detailed changelog. ## Credits -Built on top of [jQuery Boilerplate](http://jqueryboilerplate.com) +Built on top of [jQuery Boilerplate](http://jqueryboilerplate.com). ## License -[MIT License](http://zenorocha.mit-license.org/) \ No newline at end of file +[MIT License](http://zenorocha.mit-license.org/) © Zeno Rocha diff --git a/assets/Entypo-webfont.eot b/assets/Entypo-webfont.eot new file mode 100755 index 0000000..a754415 Binary files /dev/null and b/assets/Entypo-webfont.eot differ diff --git a/assets/Entypo-webfont.svg b/assets/Entypo-webfont.svg new file mode 100755 index 0000000..0bdb76b --- /dev/null +++ b/assets/Entypo-webfont.svg @@ -0,0 +1,141 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Creative Commons CC BYSA 2012 +Designer : Daniel Bruce +Foundry : Daniel Bruce +Foundry URL : wwwdanielbrucese + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/assets/Entypo-webfont.ttf b/assets/Entypo-webfont.ttf new file mode 100755 index 0000000..25438bd Binary files /dev/null and b/assets/Entypo-webfont.ttf differ diff --git a/assets/Entypo-webfont.woff b/assets/Entypo-webfont.woff new file mode 100755 index 0000000..b859168 Binary files /dev/null and b/assets/Entypo-webfont.woff differ diff --git a/assets/base.css b/assets/base.css index c992d35..157d2cd 100644 --- a/assets/base.css +++ b/assets/base.css @@ -1,156 +1,206 @@ /* Github Box */ +.github-box-wrap { + display: inline-block; + width: 46%; + margin-right: 0.6em; + margin-left: 0.6em; + margin-bottom: 2em; +} + .github-box { - font-family: "Helvetica Neue", Arial, sans-serif; - background: #fafafa; - border: 1px solid #ddd; - color: #666; - border-radius: 5px; - float: left; - margin-right: 1.2em; - margin-bottom: 2em; - width: 46%; + font-family: "Helvetica Neue", Arial, sans-serif; + background: #fafafa; + border: 1px solid #ddd; + color: #666; + border-radius: 5px; + width: 100%; } .github-box a { - color: #4183C4; - border: none; + color: #4183C4; + border: none; } /* Github Box Header */ .github-box .github-box-header { - position: relative; - border-bottom: 1px solid #ddd; - border-radius: 5px 5px 0 0; - background: #fcfcfc; - background: -moz-linear-gradient(#fcfcfc, #ebebeb); - background: -webkit-linear-gradient(#fcfcfc, #ebebeb); - -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfcfc',endColorstr='#ebebeb')"; + position: relative; + border-bottom: 1px solid #ddd; + border-radius: 5px 5px 0 0; + background: #fcfcfc; + background: -moz-linear-gradient(#fcfcfc, #ebebeb); + background: -webkit-linear-gradient(#fcfcfc, #ebebeb); + -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfcfc',endColorstr='#ebebeb')"; } .github-box .github-box-header h3 { - font-family: Helvetica, Arial, sans-serif; - font-weight: normal; - font-size: 16px; - color: gray; - margin: 0; - padding: 10px 10px 10px 10px; + font-family: Helvetica, Arial, sans-serif; + font-weight: normal; + font-size: 16px; + color: gray; + margin: 0; + padding: 10px 10px 10px 10px; } .github-box .github-box-header h3 a { - font-weight: bold + font-weight: bold } /* Github Box Header - Stats */ .github-box .github-box-header .github-stats { - position: absolute; - top: 10px; - right: 10px; - background: white; - border: 1px solid #ddd; - border-radius: 3px; - font-size: 11px; - font-weight: bold; - line-height: 21px; - height: 21px; + line-height: 36px; + position: absolute; + top: 10px; + right: 10px; + background: white; + border: 1px solid #ddd; + border-radius: 3px; + font-size: 11px; + font-weight: bold; + line-height: 21px; + height: 21px; } .github-box .github-box-header .github-stats a { - display: inline-block; - height: 21px; - color: #666; - padding: 0 5px 0 18px; - background: url('btn-sprite.png') no-repeat; - filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70); - opacity: 0.7; + display: inline-block; + height: 21px; + color: #666; + padding: 0 5px 0 5px; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=70); + opacity: 0.7; + vertical-align: top; } .github-box .github-box-header .github-stats a:hover { - filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); - opacity: 1; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + opacity: 1; +} + +.github-box .github-box-header .github-stats a:before { + font-family: 'EntypoRegular'; + content: attr(data-icon); + display: inline-block; + speak: none; + padding-right: 2px; + font-size: 2em; } -.github-box .github-box-header .github-stats .repo-watchers { - border-right: 1px solid #ddd; - background-position: 3px 4px; +.github-box .github-box-header .github-stats .repo-stars { + border-right: 1px solid #ddd; } .github-box .github-box-header .github-stats .repo-forks { - background-position: 2px -14px; - padding-left: 15px; + padding-left: 2px; + border-right: 1px solid #ddd; } /* Github Box Content */ .github-box .github-box-content { - padding: 10px; - font-weight: 300; - font-size: 0.7em; + padding: 10px; + font-weight: 300; + font-size: 0.7em; } .github-box .github-box-content p { - margin: 0; + margin: 0; + width: 100%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } .github-box .github-box-content .repo-link { - font-weight: bold; + font-weight: bold; } /* Github Box Download */ .github-box .github-box-download { - position: relative; - border-top: 1px solid #ddd; - background: white; - border-radius: 0 0 3px 3px; - padding: 10px; - height: 24px; + position: relative; + border-top: 1px solid #ddd; + background: white; + border-radius: 0 0 3px 3px; + padding: 10px; + height: 24px; } .github-box .github-box-download .repo-update { - margin: 0; - font-size: 11px; - color: #666; - line-height: 24px; + margin: 0; + font-size: 11px; + color: #666; + line-height: 24px; } .github-box .github-box-download .repo-update strong { - font-size: 12px; - font-weight: bold; - color: #000; + font-size: 12px; + font-weight: bold; + color: #000; } .github-box .github-box-download .repo-download { - position: absolute; - display: block; - top: 10px; - right: 10px; - height: 24px; - line-height: 24px; - font-size: 12px; - color: #666; - font-weight: bold; - text-shadow: 0 1px 0 rgba(255,255,255,0.9); - padding: 0 10px; - border: 1px solid #ddd; - border-bottom-color: #bbb; - border-radius: 3px; - display: block; - text-indent: -9999px; - width: 24px; - padding: 0; - background: url('btn-sprite.png') no-repeat 4px -31px,-webkit-linear-gradient(whiteSmoke, #E5E5E5); - background: url('btn-sprite.png') no-repeat 4px -31px,-moz-linear-gradient(#f1f7fa, #dbeaf1); - filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=70); - opacity: 0.7; + position: absolute; + display: block; + top: 10px; + right: 10px; + height: 24px; + line-height: 24px; + font-size: 12px; + color: #666; + font-weight: bold; + text-shadow: 0 1px 0 rgba(255,255,255,0.9); + padding: 0 10px; + border: 1px solid #ddd; + border-bottom-color: #bbb; + border-radius: 3px; + display: block; + width: 24px; + padding: 0; + background: -webkit-linear-gradient(whiteSmoke, #E5E5E5); + background: -moz-linear-gradient(#f1f7fa, #dbeaf1); + filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=70); + opacity: 1; } .github-box .github-box-download .repo-download:hover { - color: #527894; - border-color: #cfe3ed; - border-bottom-color: #9fc7db; - filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); - opacity: 1; -} \ No newline at end of file + color: #527894; + border-color: #cfe3ed; + border-bottom-color: #9fc7db; + filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100); + opacity: 1; +} + +.github-box .github-box-download .repo-download:before { + font-family: 'EntypoRegular'; + text-indent: 0px; + content: attr(data-icon); + display: inline-block; + speak: none; + font-size: 2.0em; + padding: 0 6px; +} + +/* Breakpoint content-driven */ + +@media all and (max-width: 678px) { + .github-box-wrap { + display: block; + width: inherit; + margin-right: 0; + } +} + +/* Fonts */ + +@font-face { + font-family: 'EntypoRegular'; + src: url('Entypo-webfont.eot'); + src: url('Entypo-webfont.eot?#iefix') format('embedded-opentype'), + url('Entypo-webfont.woff') format('woff'), + url('Entypo-webfont.ttf') format('truetype'), + url('Entypo-webfont.svg#EntypoRegular') format('svg'); + font-weight: normal; + font-style: normal; +} diff --git a/assets/btn-sprite.png b/assets/btn-sprite.png deleted file mode 100644 index b9e22c0..0000000 Binary files a/assets/btn-sprite.png and /dev/null differ diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..f804d76 --- /dev/null +++ b/bower.json @@ -0,0 +1,19 @@ +{ + "name": "jquery-github", + "version": "0.4.0", + "homepage": "https://github.com/zenorocha/jquery-github", + "authors": [ + "Zeno Rocha " + ], + "description": "A jQuery plugin to display your Github Repositories.", + "main": "src/jquery.github.js", + "keywords": [ + "jquery", + "github" + ], + "license": "MIT", + "dependencies": { + "jquery": "^2.1.1", + "zepto": "^1.1.4" + } +} diff --git a/demo/css/style.css b/demo/css/style.css index 6789118..8e3fc42 100644 --- a/demo/css/style.css +++ b/demo/css/style.css @@ -1,75 +1,72 @@ body { - background:#F8F8F8 url('../img/bg-noise.png') top left; + background: #F8F8F8 url('../img/bg-noise.png') top left; } a { - text-decoration: none; - font-weight: bold; - color: #999; + text-decoration: none; + font-weight: bold; + color: #999; } p { - font-size: 12px; - font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif; - line-height: 1.5em; + font-size: 12px; + font-family: 'Lucida Grande', 'Lucida Sans Unicode', sans-serif; + line-height: 1.5em; } h1 { - font-family: 'MuseoSlab500Regular', sans-serif; - text-align: center; - color: #999; - font-size: 42px; - margin: 30px 0 0 0; + font-family: 'MuseoSlab500Regular', sans-serif; + text-align: center; + color: #999; + font-size: 42px; + margin: 30px 0 0 0; } .title { - width: 700px; - margin: 0 auto; - padding-right: 35px; + width: 90%; + margin: 0 auto; } .title p { - text-align: center; + text-align: center; + margin-bottom: 40px; } .credits { - margin: 0 auto; - width: 700px; - text-align: center; - clear: both; + margin: 0 auto; + width: 90%; + text-align: center; + clear: both; } #github-logo { - position: fixed; - bottom: -5px; - right: 20px; - z-index: 1; - display: block; - opacity: 0.4; + position: fixed; + bottom: -5px; + right: 20px; + z-index: 1; + display: block; + opacity: 0.4; } .github-ribbon { - position: absolute; - top: 0; - right: 0; - border: 0; + position: absolute; + top: 0; + right: 0; + border: 0; } .projects{ - width: 700px; - margin: 0 auto; - padding: 30px; + width: 90%; + margin: 0 auto; } -/* Font-face */ - @font-face { - font-family: 'MuseoSlab500Regular'; - src: url('../font/Museo_Slab_500-webfont.eot'); - src: url('../font/Museo_Slab_500-webfont.eot?#iefix') format('embedded-opentype'), - url('../font/Museo_Slab_500-webfont.woff') format('woff'), - url('../font/Museo_Slab_500-webfont.ttf') format('truetype'), - url('../font/Museo_Slab_500-webfont.svg#MuseoSlab500Regular') format('svg'); - font-weight: normal; - font-style: normal; -} \ No newline at end of file + font-family: 'MuseoSlab500Regular'; + src: url('../font/Museo_Slab_500-webfont.eot'); + src: url('../font/Museo_Slab_500-webfont.eot?#iefix') format('embedded-opentype'), + url('../font/Museo_Slab_500-webfont.woff') format('woff'), + url('../font/Museo_Slab_500-webfont.ttf') format('truetype'), + url('../font/Museo_Slab_500-webfont.svg#MuseoSlab500Regular') format('svg'); + font-weight: normal; + font-style: normal; +} diff --git a/demo/index-zepto.html b/demo/index-zepto.html new file mode 100644 index 0000000..db9f5cd --- /dev/null +++ b/demo/index-zepto.html @@ -0,0 +1,45 @@ + + + + + + jQuery Github with Zepto + + + + + + + + + + + + Fork me on GitHub + + +
+

jQuery Github

+

A jQuery plugin to display your favorite Github Repositories.
For more informations, visit our repository.

+
+ +
+
+
+
+
+
+ +

Made with love by Zeno Rocha.

+ + + + + + + + + + diff --git a/demo/index.html b/demo/index.html index cd246d8..265417e 100644 --- a/demo/index.html +++ b/demo/index.html @@ -2,44 +2,44 @@ - - jQuery Github + + jQuery Github - - + + - - + + - - Fork me on GitHub - + + Fork me on GitHub + -
-

jQuery Github

-

A jQuery plugin to display your favorite Github Repositories.
For more informations, visit our repository.

-
+
+

jQuery Github

+

A jQuery plugin to display your favorite Github Repositories.
For more informations, visit our repository.

+
-
-
-
-
-
-
+
+
+
+
+
+
-

Made with love by Zeno Rocha.

+

Made with love by Zeno Rocha.

- + - - + + - + - \ No newline at end of file + diff --git a/dist/jquery.github.js b/dist/jquery.github.js new file mode 100644 index 0000000..27e6de9 --- /dev/null +++ b/dist/jquery.github.js @@ -0,0 +1,176 @@ +/* + * jquery-github - v0.4.0 + * A jQuery plugin to display your Github Repositories. + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 + * MIT License + */ +// -- Github Repository -------------------------------------------------------- + +function GithubRepo( repo ) { + this.description = repo.description; + 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.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 ); + + return $( + "
" + + "
" + + "

" + + "" + this.name + "" + + "

" + + "" + + "
" + + "
" + + "

" + this.description + " — Read More

" + + "
" + + "
" + + "

Latest commit to master on " + this.pushed_at + "

" + + "" + + "
" + + "
"); +}; + +// Parses pushed_at with date format +GithubRepo.prototype._parsePushedDate = function ( 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 ) { + return url.replace( "api.", "" ).replace( "repos/", "" ); +}; + +// -- Github Plugin ------------------------------------------------------------ + +function Github( element, options ) { + var defaults = { + iconStars: true, + iconForks: true, + iconIssues: false + }; + + this.element = element; + this.$container = $( element ); + this.repo = this.$container.attr( "data-repo" ); + + this.options = $.extend( {}, defaults, options ) ; + + this._defaults = defaults; + + this.init(); + this.displayIcons(); +} + +// Initializer +Github.prototype.init = function () { + var cached = this.getCache(); + + if ( cached !== null ) { + this.applyTemplate( JSON.parse( cached ) ); + return; + } + + this.requestData( this.repo ); +}; + +// Display or hide icons +Github.prototype.displayIcons = function () { + var options = this.options, + $iconStars = $( ".repo-stars" ), + $iconForks = $( ".repo-forks" ), + $iconIssues = $( ".repo-issues" ); + + $iconStars.css( "display", options.iconStars ? "inline-block" : "none" ); + $iconForks.css( "display", options.iconForks ? "inline-block" : "none" ); + $iconIssues.css( "display", options.iconIssues ? "inline-block" : "none" ); +}; + +// Request repositories from Github +Github.prototype.requestData = function ( repo ) { + var that = this; + + $.ajax({ + url: "https://api.github.com/repos/" + repo, + dataType: "jsonp", + success: function( results ) { + var result_data = results.data, + isFailling = results.meta.status >= 400 && result_data.message; + + if ( isFailling ) { + that.handleErrorRequest( result_data ); + return; + } + + that.handleSuccessfulRequest( result_data ); + } + }); +}; + +// Handle Errors requests +Github.prototype.handleErrorRequest = function ( result_data ) { + console.warn( result_data.message ); + return; +}; + +// Handle Successful request +Github.prototype.handleSuccessfulRequest = function ( result_data ) { + this.applyTemplate( result_data ); + this.setCache( result_data ); +}; + +// Stores repostories in sessionStorage if available +Github.prototype.setCache = function ( result_data ) { + // Cache data + if ( window.sessionStorage ) { + window.sessionStorage.setItem( "gh-repos:" + this.repo, JSON.stringify( result_data ) ); + } +}; + +// Grab cached results +Github.prototype.getCache = function() { + if ( window.sessionStorage ) { + return window.sessionStorage.getItem( "gh-repos:" + this.repo ); + } + else { + return false; + } +}; + +// Apply results to HTML template +Github.prototype.applyTemplate = function ( repo ) { + var githubRepo = new GithubRepo( repo ), + $widget = githubRepo.toHTML(); + + $widget.appendTo( this.$container ); +}; + +// -- Attach plugin to jQuery's prototype -------------------------------------- + +;( function ( $, window, undefined ) { + + $.fn.github = function ( options ) { + return this.each(function () { + if ( !$( this ).data( "plugin_github" ) ) { + $( this ).data( "plugin_github", new Github( this, options ) ); + } + }); + }; + +}( window.jQuery || window.Zepto, window ) ); diff --git a/dist/jquery.github.min.js b/dist/jquery.github.min.js new file mode 100644 index 0000000..4d06fc4 --- /dev/null +++ b/dist/jquery.github.min.js @@ -0,0 +1,9 @@ +/* + * jquery-github - v0.4.0 + * A jQuery plugin to display your Github Repositories. + * https://github.com/zenorocha/jquery-github + * + * Copyright (c) 2014 + * MIT License + */ +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 d22ccc5..4e3a30c 100644 --- a/github.jquery.json +++ b/github.jquery.json @@ -1,35 +1,35 @@ { - "name": "github", - "title": "jQuery Github", - "description": "A jQuery plugin to display your Github Repositories.", - "keywords": [ - "github", - "repositories", - "git" - ], - "version": "0.2.3", - "author": { - "name": "Zeno Rocha", - "url": "https://github.com/zenorocha" - }, - "maintainers": [ - { - "name": "Zeno Rocha", - "email": "zno.rocha@gmail.com", - "url": "https://github.com/zenorocha" - } - ], - "licenses": [ - { - "type": "MIT", - "url": "http://zenorocha.mit-license.org/" - } - ], - "bugs": "https://github.com/zenorocha/jquery-github/issues", - "homepage": "https://github.com/zenorocha/jquery-github/", - "docs": "https://github.com/zenorocha/jquery-github#readme", - "download": "https://github.com/zenorocha/jquery-github/archive/master.zip", - "dependencies": { - "jquery": ">=1.9" - } -} \ No newline at end of file + "name": "github", + "title": "jQuery Github", + "description": "A jQuery plugin to display your Github Repositories.", + "keywords": [ + "github", + "repositories", + "git" + ], + "version": "0.4.0", + "author": { + "name": "Zeno Rocha", + "url": "https://github.com/zenorocha" + }, + "maintainers": [ + { + "name": "Zeno Rocha", + "email": "zno.rocha@gmail.com", + "url": "https://github.com/zenorocha" + } + ], + "licenses": [ + { + "type": "MIT", + "url": "http://zenorocha.mit-license.org/" + } + ], + "bugs": "https://github.com/zenorocha/jquery-github/issues", + "homepage": "https://github.com/zenorocha/jquery-github/", + "docs": "https://github.com/zenorocha/jquery-github#readme", + "download": "https://github.com/zenorocha/jquery-github/archive/master.zip", + "dependencies": { + "jquery": ">=1.9" + } +} diff --git a/grunt.js b/grunt.js deleted file mode 100644 index a1b8dc8..0000000 --- a/grunt.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = function(grunt) { - - grunt.initConfig({ - lint: { - files: ['jquery.github.js'] - } - }); - - grunt.registerTask('default', 'lint'); - grunt.registerTask('travis', 'lint'); - -}; \ No newline at end of file diff --git a/jquery.github.js b/jquery.github.js deleted file mode 100644 index f80f06d..0000000 --- a/jquery.github.js +++ /dev/null @@ -1,137 +0,0 @@ -/* - * jQuery Github v0.2.2 - * A jQuery plugin to display your Github Repositories. - * http://git.io/WUV4_Q - * - * Zeno Rocha - * MIT License - */ - -// the semi-colon before function invocation is a safety net against concatenated -// scripts and/or other plugins which may not be closed properly. -;(function ( $, window, undefined ) { - - // undefined is used here as the undefined global variable in ECMAScript 3 is - // mutable (ie. it can be changed by someone else). undefined isn't really being - // passed in so we can ensure the value of it is truly undefined. In ES5, undefined - // can no longer be modified. - - // window is passed through as local variable rather than global - // as this (slightly) quickens the resolution process and can be more efficiently - // minified (especially when both are regularly referenced in your plugin). - - // Create the defaults once - var pluginName = 'github', - document = window.document, - defaults = { - propertyName: "value" - }; - - // The actual plugin constructor - function Plugin( element, options ) { - this.element = element; - this.$container = $(element); - this.repo = this.$container.attr("data-repo"); - this.cached; - - // jQuery has an extend method which merges the contents of two or - // more objects, storing the result in the first object. The first object - // is generally empty as we don't want to alter the default options for - // future instances of the plugin - this.options = $.extend( {}, defaults, options) ; - - this._defaults = defaults; - this._name = pluginName; - - this.init(); - } - - Plugin.prototype.init = function () { - - var self = this; - var cached; - - // Attempt to get cached repo data - if (window.sessionStorage) { - cached = sessionStorage.getItem('gh-repos:' + this.repo); - } - - if (cached != null) { - self.applyTemplate(JSON.parse(cached)); - } - else { - - $.ajax({ - url: 'https://api.github.com/repos/' + this.repo, - dataType: 'jsonp', - success: function(results){ - - // Handle API failures - if (results.meta.status >= 400 && results.data.message){ - console.warn(results.data.message); - return; - } - else { - - self.applyTemplate(results.data); - - // Cache data - if (window.sessionStorage) { - sessionStorage.setItem('gh-repos:' + self.repo, JSON.stringify(results.data)); - } - - } - } - }); - - } - - }; - - Plugin.prototype.applyTemplate = function (repo) { - - var self = this; - var date = new Date(repo.pushed_at); - var pushed_at = date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear(); - - var $widget = $($.parseHTML(' \ -
\ - \ -
\ -

' + repo.description + ' — Read More

\ -
\ -
\ -

Latest commit to master on ' + pushed_at + '

\ - Download as zip \ -
\ -
\ - ')); - - self.appendTemplate($widget); - - }; - - Plugin.prototype.appendTemplate = function ($widget) { - var self = this; - $widget.appendTo(self.$container); - }; - - // A really lightweight plugin wrapper around the constructor, - // preventing against multiple instantiations - $.fn[pluginName] = function ( options ) { - return this.each(function () { - if (!$.data(this, 'plugin_' + pluginName)) { - $.data(this, 'plugin_' + pluginName, new Plugin( this, options )); - } - }); - }; - -}(jQuery, window)); \ No newline at end of file diff --git a/jquery.github.min.js b/jquery.github.min.js deleted file mode 100644 index 5e70f34..0000000 --- a/jquery.github.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/* - * jQuery Github v0.2.2 - * A jQuery plugin to display your Github Repositories. - * http://git.io/WUV4_Q - * - * Zeno Rocha - * MIT License - */ - -(function(a,b){function g(b,c){this.element=b,this.$container=a(b),this.repo=this.$container.attr("data-repo"),this.cached,this.options=a.extend({},f,c),this._defaults=f,this._name=d,this.init()}var d="github",f=(b.document,{propertyName:"value"});g.prototype.init=function(){var e,d=this;b.sessionStorage&&(e=sessionStorage.getItem("gh-repos:"+this.repo)),null!=e?d.applyTemplate(JSON.parse(e)):a.ajax({url:"https://api.github.com/repos/"+this.repo,dataType:"jsonp",success:function(a){return a.meta.status>=400&&a.data.message?(console.warn(a.data.message),c):(d.applyTemplate(a.data),b.sessionStorage&&sessionStorage.setItem("gh-repos:"+d.repo,JSON.stringify(a.data)),c)}})},g.prototype.applyTemplate=function(b){var c=this,d=new Date(b.pushed_at),e=d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear(),f=a(a.parseHTML('

'+b.description+' — Read More

Latest commit to master on '+e+'

Download as zip
'));c.appendTemplate(f)},g.prototype.appendTemplate=function(a){var b=this;a.appendTo(b.$container)},a.fn[d]=function(b){return this.each(function(){a.data(this,"plugin_"+d)||a.data(this,"plugin_"+d,new g(this,b))})}})(jQuery,window); \ No newline at end of file diff --git a/package.json b/package.json index 1334faf..84bf932 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,17 @@ { - "name": "jquery-github", - "description": "A jQuery plugin to display your Github Repositories.", - "author": "Zeno Rocha", - "version": "0.2.3", + "private": true, "devDependencies": { - "grunt": "~0.3.17" + "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 travis --verbose" + "test": "grunt test --verbose" } -} \ No newline at end of file +} diff --git a/spec/jquery.github.repo-spec.js b/spec/jquery.github.repo-spec.js new file mode 100644 index 0000000..28c4d12 --- /dev/null +++ b/spec/jquery.github.repo-spec.js @@ -0,0 +1,50 @@ +describe("jquery.github.repo", function() { + + var instance; + + beforeEach(function() { + instance = new GithubRepo({ + name: "jquery-github", + description: "A jQuery plugin to display your Github Repositories", + forks_count: 33, + pushed_at: "2013-07-02T12:08:36Z", + url: "https://api.github.com/repos/zenorocha/jquery-github", + stargazers_count: 131 + }); + }); + + describe("initialize GithubRepo", function() { + it("should be repository's name", function() { + expect(instance.name) + .toEqual("jquery-github"); + }); + + it("should be repository's description", function() { + expect(instance.description) + .toEqual("A jQuery plugin to display your Github Repositories"); + }); + + it("should be repository's number of forks", function() { + expect(instance.forks) + .toEqual(33); + }); + + it("should be repository's last update date", function() { + expect(instance.pushed_at) + .toEqual("2013-07-02T12:08:36Z"); + }); + + it("should be repository's number of stargazers", function() { + expect(instance.stargazers) + .toEqual(131); + }); + }); + + describe("execute _parsePushedDate()", function() { + it("should parse repository's pushed_at attribute", function() { + expect(instance._parsePushedDate(instance.pushed_at)) + .toEqual("2/7/2013"); + }); + }); + +}); diff --git a/src/jquery.github.js b/src/jquery.github.js new file mode 100644 index 0000000..97f0871 --- /dev/null +++ b/src/jquery.github.js @@ -0,0 +1,163 @@ +// -- Github Repository -------------------------------------------------------- + +function GithubRepo( repo ) { + this.description = repo.description; + this.forks = repo.forks_count; + this.name = repo.name; + this.open_issues = repo.open_issues; + this.pushed_at = repo.pushed_at; + 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 ); + + return $( + "
" + + "
" + + "

" + + "" + this.name + "" + + "

" + + "" + + "
" + + "
" + + "

" + this.description + " — Read More

" + + "
" + + "
" + + "

Latest commit to master on " + this.pushed_at + "

" + + "" + + "
" + + "
"); +}; + +// Parses pushed_at with date format +GithubRepo.prototype._parsePushedDate = function ( pushed_at ) { + var date = new Date( pushed_at ); + + return date.getDate() + "/" + ( date.getMonth() + 1 ) + "/" + date.getFullYear(); +}; + +// -- Github Plugin ------------------------------------------------------------ + +function Github( element, options ) { + var defaults = { + iconStars: true, + iconForks: true, + iconIssues: false + }; + + this.element = element; + this.$container = $( element ); + this.repo = this.$container.attr( "data-repo" ); + + this.options = $.extend( {}, defaults, options ) ; + + this._defaults = defaults; + + this.init(); +} + +// Initializer +Github.prototype.init = function () { + var cached = this.getCache(); + + if ( cached !== null ) { + this.applyTemplate( JSON.parse( cached ) ); + return; + } + + this.requestData( this.repo ); +}; + +// Display or hide icons +Github.prototype.displayIcons = function () { + var options = this.options, + $iconStars = $( ".repo-stars" ), + $iconForks = $( ".repo-forks" ), + $iconIssues = $( ".repo-issues" ); + + $iconStars.css( "display", options.iconStars ? "inline-block" : "none" ); + $iconForks.css( "display", options.iconForks ? "inline-block" : "none" ); + $iconIssues.css( "display", options.iconIssues ? "inline-block" : "none" ); +}; + +// Request repositories from Github +Github.prototype.requestData = function ( repo ) { + var that = this; + + $.ajax({ + url: "https://api.github.com/repos/" + repo, + dataType: "jsonp", + success: function( results ) { + var result_data = results.data, + isFailling = results.meta.status >= 400 && result_data.message; + + if ( isFailling ) { + that.handleErrorRequest( result_data ); + return; + } + + that.handleSuccessfulRequest( result_data ); + } + }); +}; + +// Handle Errors requests +Github.prototype.handleErrorRequest = function ( result_data ) { + console.warn( result_data.message ); + return; +}; + +// Handle Successful request +Github.prototype.handleSuccessfulRequest = function ( result_data ) { + this.applyTemplate( result_data ); + this.setCache( result_data ); +}; + +// Stores repostories in sessionStorage if available +Github.prototype.setCache = function ( result_data ) { + // Cache data + if ( window.sessionStorage ) { + window.sessionStorage.setItem( "gh-repos:" + this.repo, JSON.stringify( result_data ) ); + } +}; + +// Grab cached results +Github.prototype.getCache = function() { + if ( window.sessionStorage ) { + return window.sessionStorage.getItem( "gh-repos:" + this.repo ); + } + else { + return false; + } +}; + +// Apply results to HTML template +Github.prototype.applyTemplate = function ( repo ) { + var githubRepo = new GithubRepo( repo ), + $widget = githubRepo.toHTML(); + + $widget.appendTo( this.$container ); + + this.displayIcons(); +}; + +// -- Attach plugin to jQuery's prototype -------------------------------------- + +;( function ( $, window, undefined ) { + + $.fn.github = function ( options ) { + return this.each(function () { + if ( !$( this ).data( "plugin_github" ) ) { + $( this ).data( "plugin_github", new Github( this, options ) ); + } + }); + }; + +}( window.jQuery || window.Zepto, window ) );