Skip to content

Commit

Permalink
Merge 7f87f56 into d497fc7
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Dec 18, 2014
2 parents d497fc7 + 7f87f56 commit 69c3921
Show file tree
Hide file tree
Showing 23 changed files with 1,023 additions and 380 deletions.
47 changes: 14 additions & 33 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,45 +1,26 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": false,
"browser": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"eqnull": true,
"expr": true,
"esnext": true,
"exported": ["attempt"],
"globals": {
"Backbone": true,
"Minionette": true,
"_": true,
"attempt": true
},
"immed": true,
"indent": 4,
"jquery": true,
"latedef": true,
"newcap": true,
"noarg": true,
"regexp": true,
"undef": true,
"unused": true,
"node": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"jquery": true,
"white": false,
"globals": {
"jQuery": true,
"Backbone": true,
"_": true,
"Minionette": true,
"attempt": true,
"slice": true,
"define": true,
"sinon": true,
"chai": true,
"sinonChai": true,
"jqueryChai": true,
"describe": true,
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true,
"expect": true,
"it": true
},
"exported": ["attempt"]
"undef": true,
"unused": true
}
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ node_js:
- "0.11"
- "0.10"
before_script:
- npm install -g grunt-cli bower
- npm install -g bower coveralls codeclimate-test-reporter
- bower install --config.interactive=false
script:
- gulp test --coverage
after_success:
- grunt coverage
- coveralls < coverage/lcov.info
- codeclimate < coverage/lcov.info
env:
- secure: "DJ5P4TnXa6GL7GIZoZP2FAsHy6ivL9IPFJ08F3Z2B0nJ3DwM7D+3PeKgZOo0BwuV/H3enVlcRrfwCBdL00cbfna75JxFh8T8HeKRzYuOk7lQZUphHgftgyWuGHkIz7R4sAAYK7sbw2KRIIAVAjkxXjBhq1vG95S48RWpxr9DJO0="
96 changes: 0 additions & 96 deletions Gruntfile.js

This file was deleted.

36 changes: 36 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
var gulp = require('gulp');
var karma = require('karma').server;
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var preprocess = require('gulp-preprocess');
var esformatter = require('gulp-esformatter');
var minimist = require('minimist');

var opts = minimist(process.argv.slice(2));

gulp.task('test', function (done) {
karma.start({
configFile: __dirname + '/karma.conf.js',
singleRun: !opts.continuous
}, done);
});

gulp.task('jshint', function() {
return gulp.src('src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default', {verbose: true}))
.pipe(jshint.reporter('fail'));
});

gulp.task('build', ['default'], function() {
return gulp.src(['./src/build/*.js'])
.pipe(preprocess())
.pipe(esformatter({ indent: { value: ' ' } }))
.pipe(gulp.dest('lib'))
.pipe(uglify())
.pipe(rename({ suffix: '-min' }))
.pipe(gulp.dest('lib'));
});

gulp.task('default', ['jshint', 'test']);
32 changes: 23 additions & 9 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Karma configuration
// http://karma-runner.github.io/0.10/config/configuration-file.html
var minimist = require('minimist');

var opts = minimist(process.argv.slice(2));

module.exports = function(config) {
config.set({
var conf = {
// base path, that will be used to resolve files and exclude
basePath: '',

Expand Down Expand Up @@ -41,6 +44,7 @@ module.exports = function(config) {
'src/computed.js',
'src/model.js',
'src/router.js',
'src/trigger.js',

'test/specs/*.js'
],
Expand All @@ -55,9 +59,6 @@ module.exports = function(config) {
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
Expand All @@ -68,10 +69,6 @@ module.exports = function(config) {
// - IE (only Windows)
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,

client: {
mocha: {
ui: 'bdd',
Expand All @@ -80,5 +77,22 @@ module.exports = function(config) {
},

reportSlowerThan: 10
});
};

if (opts.coverage) {
conf.reporters.push('coverage');

conf.preprocessors = conf.preprocessors || {};
var covPre = conf.preprocessors['src/*.js'] || [];
covPre.push('coverage');
conf.preprocessors['src/*.js'] = covPre;

conf.coverageReporter = {
dir: 'coverage',
subdir: '.',
type: 'lcov'
};
}

config.set(conf);
};
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A Mini Marionette for Backbone.js",
"main": "lib/minonette.js",
"scripts": {
"test": "grunt travis"
"test": "gulp"
},
"repository": {
"type": "git",
Expand All @@ -25,18 +25,17 @@
"underscore": ">=1.7.0 <2.0"
},
"devDependencies": {
"grunt": "~0.4.3",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-uglify": "~0.4.0",
"grunt-indent": "~0.1.4",
"grunt-karma": "~0.8.0",
"grunt-karma-coveralls": "~2.4.0",
"grunt-plato": "~1.0.0",
"grunt-preprocess": "~4.0.0",
"karma-coverage": "~0.2.0",
"karma-mocha": "~0.1.1",
"karma-phantomjs-launcher": "~0.1.2",
"load-grunt-tasks": "^1.0.0",
"mocha": "~1.17.1"
"coveralls": "^2.11.2",
"gulp": "^3.8.10",
"gulp-esformatter": "^1.0.1",
"gulp-jshint": "^1.9.0",
"gulp-preprocess": "^1.2.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^1.0.2",
"karma-coverage": "^0.2.0",
"karma-mocha": "^0.1.1",
"karma-phantomjs-launcher": "^0.1.2",
"minimist": "^1.1.0",
"mocha": "^1.17.1"
}
}
34 changes: 8 additions & 26 deletions src/attempt.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
// A helper function, similar to _.result
// that will return the property on obj, unless obj
// is undefined or null. Passes the 3rd params
// as arguments to the property, if it is a method
function attempt(obj, property, args) {
// that will call the prop on obj, unless obj
// is undefined or null. Passes the 3rd param
// as arguments to the method.
function attempt(obj, prop, args) {
// Return undefined unless obj
// is not null or undefined
if (obj == null) { return void 0; }
var prop = obj[property];
var fn = obj[prop];

if (_.isFunction(prop)) {
var length;
if (_.isArray(args)) {
length = args.length;
} else {
length = (args == null) ? 0 : -1;
}
switch (length) {
case -1:
return obj[property](args);
case 0:
return obj[property]();
case 1:
return obj[property](args[0]);
case 2:
return obj[property](args[0], args[1]);
case 3:
return obj[property](args[0], args[1], args[2]);
}
return prop.apply(obj, args);
if (_.isFunction(fn)) {
var apply = _.isArray(args);
return apply ? fn.apply(obj, args) : obj[prop](args);
}
return prop;
}

0 comments on commit 69c3921

Please sign in to comment.