├── .gitignore ├── Gruntfile.js ├── LICENSE ├── README.md ├── dist └── backbone-jsonapi.min.js ├── package.json ├── src ├── backbone-jsonapi.js ├── toolbox.js └── umd.js └── test ├── mock └── samples.js └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { 2 | grunt.initConfig({ 3 | pkg: grunt.file.readJSON('package.json'), 4 | browserify: { 5 | dist: { 6 | files: { 7 | 'dist/backbone-jsonapi.js': ['src/umd.js'] 8 | }, 9 | } 10 | }, 11 | uglify: { 12 | options: { 13 | banner: '/*! <%= pkg.name %> - v <%= pkg.version %> - Copyright <%= pkg.author %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' 14 | }, 15 | dist: { 16 | files: { 17 | 'dist/backbone-jsonapi.min.js': ['dist/backbone-jsonapi.js'] 18 | } 19 | } 20 | }, 21 | replace: { 22 | example: { 23 | src: ['src/backbone-jsonapi.js'], 24 | dest: 'src/backbone-jsonapi.js', 25 | replacements: [{ 26 | from: /module.exports.VERSION = '[0-9]+\.[0-9]+\.[0-9]+';/, 27 | to: 'module.exports.VERSION = \'<%= pkg.version %>\';' 28 | }] 29 | } 30 | }, 31 | clean: ['dist/backbone-jsonapi.js'], 32 | mochaTest: { 33 | all: { 34 | options: { 35 | reporter: 'spec' 36 | }, 37 | src: ['test/**/*.js', '!test/mock/**'] 38 | } 39 | }, 40 | jshint: { 41 | options: { 42 | indent: 2, 43 | camelcase: true, 44 | nonew: true, 45 | plusplus: true, 46 | quotmark: true, 47 | bitwise: true, 48 | forin: true, 49 | curly: true, 50 | eqeqeq: true, 51 | immed: true, 52 | latedef: true, 53 | newcap: true, 54 | noarg: true, 55 | undef: true, 56 | unused: true, 57 | regexp: true, 58 | trailing: true, 59 | node: true, 60 | browser: true 61 | }, 62 | gruntfile: { 63 | files: { 64 | src: ['Gruntfile.js'] 65 | } 66 | }, 67 | dev: { 68 | files: { 69 | src: ['src/**/*.js'] 70 | }, 71 | options: { 72 | debug: true, 73 | devel: true 74 | } 75 | }, 76 | dist: { 77 | files: { 78 | src: ['src/**/*.js'] 79 | } 80 | }, 81 | test: { 82 | files: { 83 | src: ['test/**/*.js'] 84 | }, 85 | options: { 86 | globals: { 87 | describe: true, 88 | it: true, 89 | before: true, 90 | after: true, 91 | beforeEach: true, 92 | afterEach: true 93 | } 94 | } 95 | } 96 | } 97 | }); 98 | 99 | grunt.loadNpmTasks('grunt-contrib-jshint'); 100 | grunt.loadNpmTasks('grunt-mocha-test'); 101 | grunt.loadNpmTasks('grunt-browserify'); 102 | grunt.loadNpmTasks('grunt-contrib-uglify'); 103 | grunt.loadNpmTasks('grunt-text-replace'); 104 | grunt.loadNpmTasks('grunt-contrib-clean'); 105 | 106 | grunt.registerTask('lint', ['jshint']); 107 | grunt.registerTask('test', ['mochaTest']); 108 | grunt.registerTask('dist', ['replace', 'browserify', 'uglify', 'clean']); 109 | grunt.registerTask('default', ['jshint', 'mochaTest', 'dist']); 110 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 guillaumervls 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Backbone JSON-API 2 | ================= 3 | 4 | Backbone Model & Collection .parse() functions for data from a [JSON API](http://jsonapi.org/format/#url-based-json-api) 5 | 6 | ### Install 7 | 8 | ̀`npm install backbone-jsonapi` 9 | 10 | 11 | # Use 12 | 13 | The "ready to use" [script file](https://raw.github.com/guillaumervls/backbone-jsonapi/master/dist/backbone-jsonapi.min.js) 14 | is in the `dist` folder. 15 | 16 | ```html 17 | 18 | 22 | ``` 23 | 24 | Also works with [Browserify](https://github.com/substack/node-browserify) : 25 | 26 | ```javascript 27 | require('backbone-jsonapi')(Backbone, _); 28 | ``` 29 | 30 | 31 | ## (Re)build 32 | 33 | ``` 34 | npm install 35 | grunt dist 36 | ``` 37 | 38 | ## Test 39 | 40 | ``` 41 | npm install 42 | grunt lint 43 | grunt test 44 | ``` 45 | 46 | ### Licence 47 | 48 | **The MIT License (MIT)** 49 | 50 | *Copyright (c) 2013 guillaumervls* 51 | 52 | Permission is hereby granted, free of charge, to any person obtaining a copy of 53 | this software and associated documentation files (the "Software"), to deal in 54 | the Software without restriction, including without limitation the rights to 55 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 56 | the Software, and to permit persons to whom the Software is furnished to do so, 57 | subject to the following conditions: 58 | 59 | The above copyright notice and this permission notice shall be included in all 60 | copies or substantial portions of the Software. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 63 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 64 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 65 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 66 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 67 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | -------------------------------------------------------------------------------- /dist/backbone-jsonapi.min.js: -------------------------------------------------------------------------------- 1 | /*! backbone-jsonapi - v 0.1.6 - Copyright guillaumervls 2013-11-27 */ 2 | !function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g