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
watch: | |
watchy -w css/**/*.less -- make css |
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
grunt.initConfig({ | |
watch: { | |
less: { | |
files: ['css/**/*.less'], | |
tasks: ['css'] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-watch'); |
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
grunt.initConfig({ | |
less: { | |
src: ['styles.less'], | |
dest: 'styles.css' | |
}, | |
postcss: { | |
options: { | |
processors: [ | |
require('autoprefixer')(), | |
] |
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
css: | |
lessc style.less | autoprefixer-cli > style.css |
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
var Router = Backbone.Router.extend({ | |
before: function() { | |
console.log('before'); | |
}, | |
after: function() { | |
console.log('after'); | |
}, | |
routes: { |
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
// save a reference to route() method | |
var $route = Backbone.Router.prototype.route; | |
// then override it | |
Backbone.Router.prototype.before = function() {} | |
Backbone.Router.prototype.after = function() {} | |
Backbone.Router.prototype.route = function(route, name, callback) { | |
if (_.isFunction(name)) { | |
callback = name; | |
name = ''; |
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
var coll = new Backbone.Collection([model1, model2]); | |
console.log(coll.search('Jordan').first().get('last_name')); // Aslam | |
console.log(coll.search('John').first().get('last_name')); // Doe | |
console.log(coll.search(/Jo/).pluck('last_name')); // ['Aslam', 'Doe'] | |
console.log(coll.search(/Jordan|John/).pluck('last_name')): // ['Aslam', 'Doe'] |
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
Backbone.Collection.prototype.search = function(test) { | |
return this.filter(function(model) { | |
return model.match(test); | |
}); | |
} |
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
var model1 = new Backbone.Model({ first_name: 'Jordan', last_name: 'Aslam' }); | |
var model2 = new Backbone.Model({ first_name: 'John', last_name: 'Doe' }); | |
console.log(model1.match(‘Jordan’)); // true | |
console.log(model2.match(‘Doe’)); // true | |
console.log(model1.match(/Jo/)); // true | |
console.log(model2.match(/Jo/)); // 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
Backbone.Model.prototype.match = function(test) { | |
return _.any(this.attributes, function(attr) { | |
return _.isRegExp(test) ? test.test(attr) : attr == test; | |
}); | |
} |