Skip to content

Commit 01c6a2d

Browse files
committed
Merge pull request #110 from bartek/commonjs-friendly
Add support for CommonJS, AMD, and global namespace usage methods.
2 parents 7d22c38 + 27634ee commit 01c6a2d

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

Gruntfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ module.exports = function(grunt) {
2424
qunit: {
2525
index: ['test/index.html']
2626
},
27+
mochaTest: {
28+
test: {
29+
src: ['test/mocha-*.js']
30+
}
31+
},
2732
watch: {
2833
files: ['<config:lint.files>', 'test/**'],
2934
tasks: ['jshint', 'qunit']
@@ -32,7 +37,8 @@ module.exports = function(grunt) {
3237

3338
grunt.loadNpmTasks('grunt-contrib-jshint');
3439
grunt.loadNpmTasks('grunt-contrib-qunit');
40+
grunt.loadNpmTasks('grunt-mocha-test');
3541

3642
// Default task.
37-
grunt.registerTask('default', ['jshint', 'qunit']);
43+
grunt.registerTask('default', ['jshint', 'qunit', 'mochaTest']);
3844
};

backbone-nested.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66
* Copyright (c) 2011-2012 Aidan Feldman
77
* MIT Licensed (LICENSE)
88
*/
9-
/*global $, _, Backbone */
10-
(function(){
9+
/*global define, require, module */
10+
(function(root, factory){
11+
if (typeof exports !== 'undefined') {
12+
// Define as CommonJS export:
13+
module.exports = factory(require("jquery"), require("underscore"), require("backbone"));
14+
} else if (typeof define === 'function' && define.amd) {
15+
// Define as AMD:
16+
define(["jquery", "underscore", "backbone"], factory);
17+
} else {
18+
// Just run it:
19+
factory(root.$, root._, root.Backbone);
20+
}
21+
}(this, function($, _, Backbone) {
1122
'use strict';
1223

1324
var _delayedTriggers = [],
@@ -359,4 +370,5 @@
359370

360371
});
361372

362-
}());
373+
return Backbone;
374+
}));

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
"test": "grunt"
88
},
99
"dependencies": {
10+
"jquery": ">=1.8.3",
11+
"underscore": ">=1.5.0",
1012
"backbone": ">=0.9.2"
1113
},
1214
"devDependencies": {
1315
"grunt": "~0.4.1",
1416
"grunt-contrib-qunit": "~0.2.2",
1517
"grunt-contrib-jshint": "~0.6.4",
18+
"grunt-mocha-test": "~0.8.2",
1619
"grunt-contrib-watch": "~0.5.3",
17-
"jslitmus": "~0.1.0"
20+
"jslitmus": "~0.1.0",
21+
"mocha": "~1.17.1"
1822
},
1923
"peerDependencies": {
2024
"grunt-cli": "*",

test/mocha-require.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*global describe, it*/
2+
var assert = require('assert');
3+
4+
var Backbone = require('backbone');
5+
require('../backbone-nested');
6+
7+
describe("CommonJS support", function() {
8+
it('should attach to Backbone when require backbone-nested', function() {
9+
assert.ok(Backbone.NestedModel);
10+
});
11+
});

0 commit comments

Comments
 (0)