Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Added linting and minification
Browse files Browse the repository at this point in the history
  • Loading branch information
willurd committed Jul 9, 2013
1 parent aaea961 commit 9ea26eb
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
node_modules/
58 changes: 58 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var fs = require("fs");
var matchdep = require("matchdep");
var parse = require("uglify-js").parse;

module.exports = function(grunt) {
var main = "backbone.unclassified.js";
var ast = parse(fs.readFileSync(main).toString());
var banner = "/*" + ast.start.comments_before[0].value + "*/\n";

grunt.config.init({
pkg: grunt.file.readJSON("package.json"),

app: {
js: {
main: "<%= pkg.main %>",
gruntfile: "Gruntfile.js",
examples: "examples/!(coffeescript)/**/example.js",
minified: "<%= pkg.name %>.min.js",
all: [
"<%= app.js.main %>",
"<%= app.js.gruntfile %>",
"<%= app.js.examples %>"
]
},
banner: banner
},

jshint: {
files: "<%= app.js.all %>"
},

uglify: {
options: {
banner: "<%= app.banner %>"
},
main: {
files: {
"<%= app.js.minified %>": "<%= app.js.main %>"
}
}
},

watch: {
files: "<%= app.js.all %>",
tasks: ["lint", "min"]
}
});

// Load the tasks.
matchdep.filterDev("grunt-*").map(grunt.loadNpmTasks);

// Aliases
grunt.registerTask("lint", "jshint");
grunt.registerTask("min", "uglify");

// Default
grunt.registerTask("default", "watch");
};
6 changes: 4 additions & 2 deletions backbone.unclassified.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
* ways selector engines perform child selections.
*/
function findChildren(context, selector) {
var result;

if (typeof context.find === "function") {
// jQuery, Zepto.
return context.find(selector);
Expand All @@ -61,7 +63,7 @@
// This selector library takes at least two arguments, maybe they
// are a selector and context.
try {
var result = Backbone.$(selector, context);
result = Backbone.$(selector, context);

if (result.length > 0) {
// Qwery.
Expand All @@ -79,7 +81,7 @@
children.push.apply(children, Backbone.$(selector, context[i]));
}

var result = Backbone.$(children);
result = Backbone.$(children);

if (isArray(result) && result.length === 0) {
// Sizzle.
Expand Down
9 changes: 9 additions & 0 deletions backbone.unclassified.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions examples/collection/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ var ListView = Backbone.View.extend({
this.ui.list.refresh();

_.each(this.collection.models, function(item) {
var item = new ItemView({
var view = new ItemView({
model: item
});
this.ui.list.append(item.render().el);
this.ui.list.append(view.render().el);
}, this);

// Because the .item elements didn't exist when the list was initialized,
Expand All @@ -108,18 +108,20 @@ var ListView = Backbone.View.extend({
}
});

function makeItem(value) {
return {
name: "item " + value,
quantity: Math.round(Math.random() * 5)
};
}

var MainView = Backbone.View.extend({
el: "#main",

render: function() {
for (var i = 0; i < 3; i++) {
var list = new ListView({
collection: new Items(_.map([1, 2, 3], function(value) {
return {
name: "item " + value,
quantity: Math.round(Math.random() * 5)
};
}), {
collection: new Items(_.map([1, 2, 3], makeItem), {
name: "list " + (i + 1)
})
});
Expand Down
69 changes: 42 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
{
"name": "backbone.unclassified",
"description": "Declarative child elements for Backbone Views",
"version": "0.1.3",
"keywords": ["backbone", "plugin", "view", "dom", "element", "selector"],
"author": "William Bowers <[email protected]>",
"main": "backbone.unclassified.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/willurd/backbone.unclassified.js"
},
"dependencies": {
"underscore": ">=1.4.3",
"backbone": ">=1.0.0"
},
"jam": {
"main": "backbone.unclassified.js",
"dependencies": {
"underscore": ">=1.4.3",
"backbone": ">=1.0.0"
},
"include": [
"backbone.unclassified.js",
"LICENSE.txt",
"README.md"
]
}
"name": "backbone.unclassified",
"description": "Declarative child elements for Backbone Views",
"version": "0.1.3",
"keywords": [
"backbone",
"plugin",
"view",
"dom",
"element",
"selector"
],
"author": "William Bowers <[email protected]>",
"main": "backbone.unclassified.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/willurd/backbone.unclassified.js"
},
"dependencies": {
"underscore": ">=1.4.3",
"backbone": ">=1.0.0"
},
"devDependencies": {
"grunt": "*",
"grunt-contrib-jshint": "*",
"grunt-contrib-uglify": "*",
"grunt-contrib-watch": "*",
"matchdep": "*",
"uglify-js": "*"
},
"jam": {
"main": "backbone.unclassified.js",
"dependencies": {
"underscore": ">=1.4.3",
"backbone": ">=1.0.0"
},
"include": [
"backbone.unclassified.js",
"LICENSE.txt",
"README.md"
]
}
}

0 comments on commit 9ea26eb

Please sign in to comment.