Skip to content

Commit

Permalink
Merge branch 'amd' of github.com:tbranyen/backbone-boilerplate into amd
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Jan 14, 2012
2 parents 401fcd4 + 7d808ed commit bbb754b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 261 deletions.
27 changes: 27 additions & 0 deletions app/config.js
@@ -0,0 +1,27 @@
// Set the require.js configuration for your application.
require.config({
paths: {
// JavaScript folders
libs: "../assets/js/libs",
plugins: "../assets/js/plugins",

// Libraries
jquery: "../assets/js/libs/jquery",
underscore: "../assets/js/libs/underscore",
backbone: "../assets/js/libs/backbone",

// Shim Plugin
use: "../assets/js/plugins/use"
},

use: {
backbone: {
deps: ["use!underscore", "jquery"],
attach: "Backbone"
},

underscore: {
attach: "_"
}
}
});
84 changes: 27 additions & 57 deletions app/index.js
@@ -1,67 +1,39 @@
// Set the require.js configuration for your application.
require.config({
paths: {
libs: "../assets/js/libs",
jquery: "../assets/js/libs/jquery",
underscore: "../assets/js/libs/underscore",
backbone: "../assets/js/libs/backbone",

order: "../assets/js/plugins/order",
use: "../assets/js/plugins/use"
},

use: {
backbone: {
deps: ["use!underscore", "jquery"],
attach: function() {
return this.Backbone.noConflict();
}
},

underscore: {
attach: "_"
}
}
});

define("namespace", [
"jquery",
"use!underscore",
"use!backbone"
],

function($, _, Backbone) {
var exports = {};

// This is useful when developing if you don't want to use a
// build process every time you change a template.
//
// Delete if you are using a different template loading method.
exports.fetchTemplate = function(path, done) {
// Should be an instant synchronous way of getting the template, if it
// exists in the JST object.
var JST = this.JST = this.JST || {};
if (JST[path]) {
return done(JST[path]);
}

// Fetch it asynchronously if not available from JST
return $.get(path, function(contents) {
var tmpl = _.template(contents);
JST[path] = tmpl;
done(tmpl);
});
};
function($) {
return {
// This is useful when developing if you don't want to use a
// build process every time you change a template.
//
// Delete if you are using a different template loading method.
fetchTemplate: function(path, done) {
// Should be an instant synchronous way of getting the template, if it
// exists in the JST object.
var JST = this.JST = this.JST || {};
if (JST[path]) {
return done(JST[path]);
}

// Create a custom object with a nested Views object
exports.module = function(additionalProps) {
return _.extend({ Views: {} }, additionalProps);
};
// Fetch it asynchronously if not available from JST
return $.get(path, function(contents) {
var tmpl = _.template(contents);
JST[path] = tmpl;
done(tmpl);
});
},

// Keep active application instances namespaced under an app object.
exports.app = _.extend({}, Backbone.Events);
// Create a custom object with a nested Views object
module: function(additionalProps) {
return _.extend({ Views: {} }, additionalProps);
},

return exports;
// Keep active application instances namespaced under an app object.
app: _.extend({}, Backbone.Events)
};
});

require([
Expand All @@ -72,7 +44,6 @@ require([
],

function (namespace, jQuery, Backbone, Example) {

// Treat the jQuery ready function as the entry point to the application.
// Inside this function, kick-off all initialization, everything up to this
// point should be definitions.
Expand Down Expand Up @@ -141,5 +112,4 @@ function (namespace, jQuery, Backbone, Example) {
});

});

});
6 changes: 3 additions & 3 deletions app/templates/example.html
Expand Up @@ -136,11 +136,11 @@ <h3 id="cleaning">Cleaning out default files and code</h3>
<p>At the root level of the project simply change the <code>favicon.ico</code> file to point to your own branded icon.</p>

<li><h4 id="app-code">Removing default application code</h4>
<p>This tutorial is rendered in the <code>app/modules/example.js</code> file and written in <code>app/modules/templates/example.html</code>
both of these files are safe to remove.</p>
<p>This tutorial is rendered in the <code>app/modules/example.js</code> file and written in <code>app/templates/example.html</code>.
Both of these files are safe to remove.</p>

<li><h4 id="default-routes">Removing the default routes</h4>
<p>Routes are defined in the <code>app/index.js</code> file. Familiarize yourself with it's contents. You'll notice the default router has two existing rotues and callback defined, reset it to:
<p>Routes are defined in the <code>app/index.js</code> file. Familiarize yourself with it's contents. You'll notice the default router has two existing routes and callback defined, reset it to:

<pre><code>
// Defining the application router, you can attach sub routers here.
Expand Down
180 changes: 0 additions & 180 deletions assets/js/plugins/order.js

This file was deleted.

2 changes: 1 addition & 1 deletion assets/js/plugins/use.js
Expand Up @@ -22,7 +22,7 @@ define({
// },
//
// "libs/backbone": {
// deps: ["use!underscore", "jquery", "order!libs/backbone"],
// deps: ["use!underscore", "jquery"],
// attach: function(_, $) {
// return this.Backbone.noConflict();
// }
Expand Down
34 changes: 29 additions & 5 deletions build/config.js
@@ -1,5 +1,27 @@
// This is the main Backbone Boilerplate build configuration file.

// Custom function to read in require.config settings
function readRequireConfig(path) {
var _require = require;
var obj;
var config = require("fs").readFileSync(path).toString();

// Patch over require since jshint complains about using with...
require = {
config: function(_obj) {
obj = _obj;
}
};

// Yes I know what this is doing...
eval(config);

// Restore require
require = _require;

return obj || {};
}

// This is a JavaScript file, you can define any functions you would like in
// here.
config.init({
Expand All @@ -12,6 +34,12 @@ config.init({
files: ["build/config.js", "app/**/*.js"]
},

jshint: {
options: {
evil: true
}
},

watch: {
files: ["app/**/*", "assets/**/*"],
tasks: "lint:files requirejs",
Expand Down Expand Up @@ -49,11 +77,7 @@ config.init({
}
},

requirejs: {
// Put any valid require.js configuration options here.
// There are already plenty of defaults baked in to
// get you going!
}
requirejs: readRequireConfig("app/config.js")

});

Expand Down

0 comments on commit bbb754b

Please sign in to comment.