Permalink
Browse files

Removed deprecated jshint rules and added jscs task to handle code st…

…yle validation. Added new options "partialsNamespace" and "templatesNamespace" to allow for user defined namespaces instead of requiring the default Handlebars namespaces, but still defaults to "Handlebars.partials" and "Handlebars.templates". Updated README options and converted them to display in GFM table format. Added .travis.yml and associated "test" command.
  • Loading branch information...
pklauzinski committed Feb 26, 2016
1 parent 31ec77d commit 64b23b40db7ef7fd3dd62cbcf66b22f2a16d4c13
Showing with 189 additions and 84 deletions.
  1. +76 −0 .jscsrc
  2. +5 −0 .travis.yml
  3. +14 −6 Gruntfile.js
  4. +23 −19 README.md
  5. +1 −1 bower.json
  6. +9 −5 package.json
  7. +61 −53 payload.js
View
76 .jscsrc
@@ -0,0 +1,76 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"maximumLineLength": {
"value": 200,
"allExcept": ["comments", "regex"]
},
"validateIndentation": 4,
"validateQuoteMarks": "'",
"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"requireMultipleVarDecl": "onevar",
"disallowKeywordsOnNewLine": ["else"],
"disallowSpaceBeforeComma": true,
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=", "+=",
"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInForStatement": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,
"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true,
"disallowKeywords": ["with"],
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInCallExpression": true,
"disallowSpaceAfterObjectKeys": true,
"requireSpaceBeforeObjectValues": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"requireSemicolons": true,
"validateParameterSeparator": ", "
}
View
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "stable"
before_script:
- npm install -g grunt-cli
View
@@ -15,21 +15,27 @@ module.exports = function(grunt) {
eqeqeq: true,
eqnull: true,
browser: true,
newcap: false,
es3: true,
forin: true,
indent: 4,
unused: 'vars',
strict: true,
trailing: true,
quotmark: 'single',
latedef: true,
globals: {
jQuery: true
}
},
files: {
src: ['Grunfile.js', 'payload.js']
src: ['Gruntfile.js', 'payload.js']
}
},
/**
* https://github.com/jscs-dev/grunt-jscs
*/
jscs: {
src: ['Gruntfile.js', 'payload.js'],
options: {
config: '.jscsrc'
}
},
@@ -52,7 +58,9 @@ module.exports = function(grunt) {
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', ['jshint', 'uglify']);
grunt.registerTask('default', ['jshint', 'jscs', 'uglify']);
grunt.registerTask('test', ['jshint', 'jscs']);
};
View
@@ -23,24 +23,28 @@ Payload.js selectors can also contain the "data-auto-load" attribute to cause th
## Payload.js Options
- **apiCallback** (params) - Called during API request handling before XHR requests (but after loading a template if no XHR request is required). See "API Callback Params" above for more information about the arguments.
- **apiOnClick** ($origin, jqEvent) - Invoked on API link activation; if it returns a false value is returned Payload.js will skip performing an API request.
- **apiOnSubmit** ($origin, jqEvent) - Invoked on API form submission; if it returns a false value is returned Payload.js will skip performing an API request.
- **apiBeforeRender** (params) - Invoked just before rendering a template or fetching cached HTML.
- **apiAfterRender** (params) - Invoked just after rendering a template or fetching cached HTML.
- **apiResponseParent** - If set, unserialized XHR response objects will use the specified property as the response data (e.g. if all API responses contain '{"response": ...}').
- **context** - Payload.js will only monitor events on the given DOM object. Defaults to "document.body".
- **dataNamespace** - If set, Payload will look for "data-$prefix-" attributes instead of "data-" attributes.
- **debug** -
- **loadingHtml** - The default HTML to insert into API $targets with the "loading" flag set (default: '<small>Loading...</small>')
- **loadingDefault** - If set to false, the API $target will not be cleared at the start (default: true)
- **subscribers** - List of events and callback functions to pass to "Payload.addSubscribers" method.
- **timeout** - Timeout value, in seconds, before XHR requests are aborted.
- **xhrAlways** (params) - Called after each XHR request, regardless of success/failure.
- **xhrBeforeSend** (params) - Called before each XHR request.
- **xhrDone** (params) - Called after each successful XHR request.
- **xhrFail** (params) - Called after each failed XHR request.
| Option | Type | Default | Description |
|----------------------|----------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `apiCallback` | `function` | `$.noop` | Called during API request handling before XHR requests (but after loading a template if no XHR request is required). See "API Callback Params" above for more information about the arguments. |
| `apiOnClick` | `function` | `function() { return true; }` | Invoked on API link activation; if it returns a false value, Payload.js will skip performing an API request. |
| `apiOnSubmit` | `function` | `function() { return true; }` | Invoked on API form submission; if it returns a false value, Payload.js will skip performing an API request. |
| `apiBeforeRender` | `function` | `$.noop` | Invoked just before rendering a template or fetching cached HTML. |
| `apiAfterRender` | `function` | `$.noop` | Invoked just after rendering a template or fetching cached HTML. |
| `apiAccessToken` | `string` | `''` | Supply an access token for your application and it will be added to the request header as an OAuth 2.0 Bearer token. |
| `apiResponseParent` | `string` | `''` | If set, unserialized XHR response objects will use the specified property as the parent key for response data (e.g. if all API responses contain `{"response": {}}`). |
| `context` | `object` or `string` | `document.body` | Payload.js will only monitor events on the given DOM object. |
| `dataNamespace` | `string` | `''` | If set, Payload will look for `data-[dataNamespace]-` attributes instead of `data-` attributes. This can be used to prevent `data-` attribute naming conflicts. |
| `debug` | `boolean` | `false` | If `true`, outputs useful debugging information to the `console`. |
| `loadingHtml` | `string` | `<small>Loading...</small>` | The default HTML to insert into API `$target` if the `loading` flag for the request is `true`. |
| `loadingDefault` | `boolean` | `true` | Sets the default behavior for all XHR requests to clear the `$target` element and show the `loadingHtml` within it. If `false`, the `$target` element's content will not be cleared until updated by the `$api` response. This can be overridden for any API request using the `data-loading` attribute. |
| `partialsNamespace` | `object` | `Handlebars.partials` | The namespace containing precompiled Handlebars partials. |
| `subscribers` | `array` | `[]` | List of events and callback functions to pass to `Payload.addSubscribers` method. These subscribers are initialized upon the `Payload.delivery` call. |
| `templatesNamespace` | `object` | `Handlebars.templates` | The namespace containing precompiled Handlebars templates. |
| `timeout` | `number` | `0` | Timeout value, in milliseconds, before XHR requests are aborted. This can be overridden for any API request using the `data-timeout` attribute. |
| `xhrAlways` | `function` | `$.noop` | Called after each XHR request, regardless of success/failure. |
| `xhrBeforeSend` | `function` | `$.noop` | Called before each XHR request. |
| `xhrDone` | `function` | `$.noop` | Called after each successful XHR request. |
| `xhrFail` | `function` | `$.noop` | Called after each failed XHR request. |
## Primary Methods
@@ -135,4 +139,4 @@ Every Handlebars template always has the following data available:
- **options** - Current set of options (see Options below)
- **appData** -Object for storing custom application data; provided as "app" within template data
- **cache** - Object containing "response" and "view" caches.
- **cache** - Object containing "response" and "view" caches.
View
@@ -1,6 +1,6 @@
{
"name": "payloadjs",
"version": "0.2.6",
"version": "0.3.0",
"homepage": "https://github.com/payloadjs/payload",
"authors": [
{
View
@@ -1,10 +1,10 @@
{
"name": "payloadjs",
"version": "0.2.6",
"version": "0.3.0",
"description": "HTML5-data-driven behavioral layer designed to interact intuitively with REST APIs from within SPAs (single-page-applications) and mobile apps.",
"main": "payload.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "grunt test"
},
"repository": {
"type": "git",
@@ -28,10 +28,14 @@
"bugs": {
"url": "https://github.com/pklauzinski/payload/issues"
},
"homepage": "https://github.com/pklauzinski/payload",
"homepage": "http://payloadjs.com",
"dependencies": {
"jquery": ">=1.7"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.1",
"grunt-contrib-uglify": "^0.9.1"
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "^0.11.1",
"grunt-jscs": "^2.7.0"
}
}
Oops, something went wrong.

0 comments on commit 64b23b4

Please sign in to comment.