Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup grunt & qunit, add extensions and tests
- Loading branch information
Showing
23 changed files
with
13,159 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true, | ||
"es5": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('package.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']); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2013 Nathan Bubna | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,82 @@ | ||
store | ||
===== | ||
# store.js | ||
|
||
A better way to use localStorage and sessionStorage | ||
A much more developer-friendly API for localStorage and sessionStorage and friends. The API is rich and extensible, yet simple to use. It supports JSON, namespacing and more. | ||
|
||
## Getting Started | ||
Download the [production version][min] or the [development version][max]. | ||
|
||
[min]: https://raw.github.com/nbubna/store/master/dist/store.min.js | ||
[max]: https://raw.github.com/nbubna/store/master/dist/store.js | ||
|
||
In your web page: | ||
|
||
```html | ||
<script src="jquery.js"></script> | ||
<script src="dist/store.min.js"></script> | ||
<script> | ||
store('greeting', 'hello world!'); | ||
</script> | ||
``` | ||
|
||
## Documentation | ||
The main store function handles set, get, setAll, getAll and clear actions; respectively, these are called like so: | ||
|
||
store(key, data); | ||
store(key); | ||
store({key: data, key2: data2}); | ||
store(); | ||
store(false); | ||
|
||
There are also more explicit and versatile functions available: | ||
|
||
store.set(key, data[, overwrite=true]); | ||
store.setAll(data[, overwrite=true]); | ||
store.get(key[, alt]); | ||
store.getAll(); | ||
store.remove(key); | ||
store.has(key); | ||
store.key(index); | ||
store.keys(); | ||
store.each(fn[, end]); | ||
store.size(); | ||
store.clear(); | ||
store.clearAll(); | ||
|
||
Passing in false for the optional overwrite parameters will cause "set" actions to be skipped if the storage already has a value for that key. All "set" action methods return the previous value for that key, by default. If overwrite is false and there is a previous value, the unused new value will be returned. | ||
|
||
All of the above functions are act upon the storage area currently being used. By default, that will be localStorage (aka "local") until you tell store to use a different storage facility, like this: | ||
|
||
store.use("session"); | ||
|
||
The 'use' function is one of five general-purpose functions: | ||
|
||
store.area(id[, storageArea]);// selects and/or creates a new store API | ||
store.isFake();//are things really persistent? | ||
store.namespace(prefix);// creates store API that prefixes all key-based functions | ||
store.bind([key, ]handler);// registers a storage event listener | ||
|
||
Two facilities are available automatically: "local" and "session". The "session" store uses sessionStorage. If these are unavailable, they will be faked to prevent errors, but data stored will NOT persist beyond the life of the current document/page. | ||
|
||
Of course, you don't have to rely on area() for 'local' and 'session'. You can just use their specific store API and do things like: | ||
|
||
store.session.remove(key); | ||
store.local({lots: 'of', data: 'altogether'}); | ||
|
||
All the specific get, set, etc. functions are directly callable on both store.session and store.local, as well as any other storage facility registered via store.use(name, customStorageObject), where customStorageObject implements the [Storage interface][storage] for all store functions to work properly. | ||
|
||
[storage]: http://dev.w3.org/html5/webstorage/#the-storage-interface | ||
|
||
Finally, if you want to put stored data from different pages or areas of your site into separate namespaces, the store.namespace is your friend: | ||
|
||
var cart = store.namespace('cart').use('local'); | ||
cart('total', 23.25);// stores in localStorage as 'cart.total' | ||
console.log(store('cart.total') == cart('total'));// logs true | ||
console.log(store.cart.getAll());// logs {total: 23.25} | ||
|
||
The namespace created provides the same API and defaults to the parent's underlying storage but silently adds/removes the namespace prefix as needed. It also makes the namespace accessible directly via store[namespace] as long as it does not conflict with an existing property. | ||
|
||
## Examples | ||
_(Coming soon)_ | ||
|
||
## Release History | ||
_(Nothing yet)_ |
Oops, something went wrong.