Skip to content

Commit

Permalink
add plugin grunt
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredsang committed Feb 10, 2014
1 parent 08f96fc commit a39e9d8
Show file tree
Hide file tree
Showing 22 changed files with 12,540 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build.zip
1 change: 1 addition & 0 deletions build/examples/jquery_plugin/plugin_grunt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
14 changes: 14 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"sub": true,
"undef": true,
"unused": true,
"boss": true,
"eqnull": true,
"node": true
}
31 changes: 31 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contributing

## Important notes
Please don't edit files in the `dist` subdirectory as they are generated via Grunt. You'll find source code in the `src` subdirectory!

### Code style
Regarding code style like indentation and whitespace, **follow the conventions you see used in the source already.**

### PhantomJS
While Grunt can run the included unit tests via [PhantomJS](http://phantomjs.org/), this shouldn't be considered a substitute for the real thing. Please be sure to test the `test/*.html` unit test file(s) in _actual_ browsers.

## Modifying the code
First, ensure that you have the latest [Node.js](http://nodejs.org/) and [npm](http://npmjs.org/) installed.

Test that Grunt's CLI is installed by running `grunt --version`. If the command isn't found, run `npm install -g grunt-cli`. For more information about installing Grunt, see the [getting started guide](http://gruntjs.com/getting-started).

1. Fork and clone the repo.
1. Run `npm install` to install all dependencies (including Grunt).
1. Run `grunt` to grunt this project.

Assuming that you don't see any red, you're ready to go. Just be sure to run `grunt` after making any changes, to ensure that nothing is broken.

## Submitting pull requests

1. Create a new branch, please don't work in your `master` branch directly.
1. Add failing tests for the change you want to make. Run `grunt` to see the tests fail.
1. Fix stuff.
1. Run `grunt` to see if the tests pass. Repeat steps 2-4 until done.
1. Open `test/*.html` unit test file(s) in actual browser to ensure tests pass everywhere.
1. Update the documentation to reflect any changes.
1. Push to your fork and submit a pull request.
87 changes: 87 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
// Metadata.
pkg: grunt.file.readJSON('i5ting-mobile.jquery.json'),
banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
// Task configuration.
clean: {
files: ['dist']
},
concat: {
options: {
banner: '<%= banner %>',
stripBanners: true
},
dist: {
src: ['src/<%= pkg.name %>.js'],
dest: 'dist/<%= pkg.name %>.js'
},
},
uglify: {
options: {
banner: '<%= banner %>'
},
dist: {
src: '<%= concat.dist.dest %>',
dest: 'dist/<%= pkg.name %>.min.js'
},
},
qunit: {
files: ['test/**/*.html']
},
jshint: {
gruntfile: {
options: {
jshintrc: '.jshintrc'
},
src: 'Gruntfile.js'
},
src: {
options: {
jshintrc: 'src/.jshintrc'
},
src: ['src/**/*.js']
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/**/*.js']
},
},
watch: {
gruntfile: {
files: '<%= jshint.gruntfile.src %>',
tasks: ['jshint:gruntfile']
},
src: {
files: '<%= jshint.src.src %>',
tasks: ['jshint:src', 'qunit']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'qunit']
},
},
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');

// Default task.
grunt.registerTask('default', ['jshint', 'qunit', 'clean', 'concat', 'uglify']);

};
22 changes: 22 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 i5ting

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
30 changes: 30 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# I5ting Mobile

this is a test jq plugin

## Getting Started
Download the [production version][min] or the [development version][max].

[min]: https://raw.github.com/i5ting/How-to-write-jQuery-plugin/master/dist/i5ting-mobile.min.js
[max]: https://raw.github.com/i5ting/How-to-write-jQuery-plugin/master/dist/i5ting-mobile.js

In your web page:

```html
<script src="jquery.js"></script>
<script src="dist/i5ting-mobile.min.js"></script>
<script>
jQuery(function($) {
$.awesome(); // "awesome"
});
</script>
```

## Documentation
_(Coming soon)_

## Examples
_(Coming soon)_

## Release History
_(Nothing yet)_
33 changes: 33 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/dist/i5ting-mobile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*! I5ting Mobile - v0.1.0 - 2014-02-11
* https://github.com/i5ting/How-to-write-jQuery-plugin
* Copyright (c) 2014 i5ting; Licensed MIT */
(function($) {

// Collection method.
$.fn.awesome = function() {
return this.each(function(i) {
// Do something awesome to each selected element.
$(this).html('awesome' + i);
});
};

// Static method.
$.awesome = function(options) {
// Override default options with passed-in options.
options = $.extend({}, $.awesome.options, options);
// Return something awesome.
return 'awesome' + options.punctuation;
};

// Static method default options.
$.awesome.options = {
punctuation: '.'
};

// Custom selector.
$.expr[':'].awesome = function(elem) {
// Is this element awesome?
return $(elem).text().indexOf('awesome') !== -1;
};

}(jQuery));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*! I5ting Mobile - v0.1.0 - 2014-02-11
* https://github.com/i5ting/How-to-write-jQuery-plugin
* Copyright (c) 2014 i5ting; Licensed MIT */
!function(a){a.fn.awesome=function(){return this.each(function(b){a(this).html("awesome"+b)})},a.awesome=function(b){return b=a.extend({},a.awesome.options,b),"awesome"+b.punctuation},a.awesome.options={punctuation:"."},a.expr[":"].awesome=function(b){return-1!==a(b).text().indexOf("awesome")}}(jQuery);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "i5ting-mobile",
"title": "I5ting Mobile",
"description": "this is a test jq plugin",
"version": "0.1.0",
"homepage": "https://github.com/i5ting/How-to-write-jQuery-plugin",
"author": {
"name": "i5ting",
"email": "i5ting@126.com"
},
"repository": {
"type": "git",
"url": "git://github.com/i5ting/How-to-write-jQuery-plugin.git"
},
"bugs": "https://github.com/i5ting/How-to-write-jQuery-plugin/issues",
"licenses": [
{
"type": "MIT",
"url": "https://github.com/i5ting/How-to-write-jQuery-plugin/blob/master/LICENSE-MIT"
}
],
"dependencies": {
"jquery": "*"
},
"keywords": []
}
12 changes: 12 additions & 0 deletions build/examples/jquery_plugin/plugin_grunt/libs/jquery-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function() {
// Default to the local version.
var path = '../libs/jquery/jquery.js';
// Get any jquery=___ param from the query string.
var jqversion = location.search.match(/[?&]jquery=(.*?)(?=&|$)/);
// If a version was specified, use that version from code.jquery.com.
if (jqversion) {
path = 'http://code.jquery.com/jquery-' + jqversion[1] + '.js';
}
// This is the only time I'll ever use document.write, I promise!
document.write('<script src="' + path + '"></script>');
}());
Loading

0 comments on commit a39e9d8

Please sign in to comment.