Skip to content

Commit

Permalink
adding in tutorial and todomvc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Jun 2, 2012
1 parent 63d0876 commit a7b67b0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 318 deletions.
2 changes: 1 addition & 1 deletion todomvc/root/assets/css/index.css
@@ -1,2 +1,2 @@
@import "style.css"; @import "h5bp.css";
@import "todo.css"; @import "todo.css";
1 change: 1 addition & 0 deletions todomvc/root/grunt.js
Expand Up @@ -60,6 +60,7 @@ module.exports = function(grunt) {
// only want to load one stylesheet in index.html. // only want to load one stylesheet in index.html.
mincss: { mincss: {
"dist/release/index.css": [ "dist/release/index.css": [
"assets/css/h5bp.css",
"assets/css/style.css", "assets/css/style.css",
"assets/css/todo.css" "assets/css/todo.css"
] ]
Expand Down
17 changes: 17 additions & 0 deletions tutorial.js
@@ -0,0 +1,17 @@
exports.description = "Backbone Boilerplate Tutorial";
exports.notes = "Generates the tutorial files.";

exports.template = function(grunt, init, done) {

// Files to copy (and process).
var files = init.filesToCopy({});

// Actually copy (and process). files.
init.copyAndProcess(files, {}, {
noProcess: [ "assets/**", "test/**", "favicon.ico" ]
});

// All done!
done();

};
32 changes: 8 additions & 24 deletions tutorial/root/app/main.js
@@ -1,49 +1,33 @@
require([ require([
"namespace", "app",


// Libs // Libs
"jquery", "jquery",
"use!backbone", "backbone",


// Modules // Modules
"modules/example" "modules/example"
], ],


function(namespace, $, Backbone, Example) { function(app, $, Backbone, Example) {


// Defining the application router, you can attach sub routers here. // Defining the application router, you can attach sub routers here.
var Router = Backbone.Router.extend({ var Router = Backbone.Router.extend({
routes: { routes: {
"": "index", "": "index"
":hash": "index"
}, },


index: function(hash) { index: function() {
var route = this;
var tutorial = new Example.Views.Tutorial(); var tutorial = new Example.Views.Tutorial();


// Attach the tutorial to the DOM // Attach the tutorial to the DOM
tutorial.render(function(el) { tutorial.$el.appendTo("#main");
$("#main").html(el);


// Fix for hashes in pushState and hash fragment // Render the tutorial.
if (hash && !route._alreadyTriggered) { tutorial.render();
// Reset to home, pushState support automatically converts hashes
Backbone.history.navigate("", false);

// Trigger the default browser behavior
location.hash = hash;

// Set an internal flag to stop recursive looping
route._alreadyTriggered = true;
}
});
} }
}); });


// Shorthand the application namespace
var app = namespace.app;

// Treat the jQuery ready function as the entry point to the application. // Treat the jQuery ready function as the entry point to the application.
// Inside this function, kick-off all initialization, everything up to this // Inside this function, kick-off all initialization, everything up to this
// point should be definitions. // point should be definitions.
Expand Down
27 changes: 8 additions & 19 deletions tutorial/root/app/modules/example.js
@@ -1,40 +1,29 @@
define([ define([
"namespace", "app",


// Libs // Libs
"use!backbone" "backbone"


// Modules // Modules


// Plugins // Plugins
], ],


function(namespace, Backbone) { function(app, Backbone) {


// Create a new module // Create a new module
var Example = namespace.module(); var Example = namespace.module();


// Example extendings
Example.Model = Backbone.Model.extend({ /* ... */ });
Example.Collection = Backbone.Collection.extend({ /* ... */ });
Example.Router = Backbone.Router.extend({ /* ... */ });

// This will fetch the tutorial template and render it. // This will fetch the tutorial template and render it.
Example.Views.Tutorial = Backbone.View.extend({ Example.Views.Tutorial = Backbone.View.extend({
template: "app/templates/example.html", template: "app/templates/example",


render: function(done) { render: function(done) {
var view = this; // Fetch the template.

var tmpl = app.fetchTemplate(this.template);
// Fetch the template, render it to the View element and call done.
namespace.fetchTemplate(this.template, function(tmpl) {
view.el.innerHTML = tmpl();


// If a done function is passed, call it with the element // Set the template contents.
if (_.isFunction(done)) { this.$el.html(tmpl());
done(view.el);
}
});
} }
}); });


Expand Down
1 change: 1 addition & 0 deletions tutorial/root/assets/css/index.css
@@ -1 +1,2 @@
@import "h5bp.css";
@import "style.css"; @import "style.css";

0 comments on commit a7b67b0

Please sign in to comment.