Skip to content

Commit

Permalink
updating to use patched Backbone and Underscore builds, adding Jasmin…
Browse files Browse the repository at this point in the history
…e, updating to latest r.js so its no longer using edge, rewriting readme
  • Loading branch information
addyosmani committed Jan 24, 2012
1 parent 8fff2ea commit 7fc3701
Show file tree
Hide file tree
Showing 24 changed files with 3,239 additions and 24,462 deletions.
Binary file modified .DS_Store
Binary file not shown.
64 changes: 49 additions & 15 deletions Readme.rdoc
@@ -1,26 +1,60 @@
Template project for backbone with require.js:
==========================================

This project demonstrates how to use require.js with backbone.js and then replace require.js with almond.js in production.
See the app.build.js file in public/js to see how the project is built. Note that the included require.js is currently an edge version.
##Backback

To build the javascript files you can do:
Backpack is a boilerplate project for personal Backbone.js projects which includes some common items I use in my setup. It is based on a fork of jbasdf's Backbone.js template.

Included in the backpack are:
=============================

* Backbone.js (AMD patched)
* Underscore.js (AMD patched)
* jQuery.js
* Require.js (latest)
* i18n.js plugin for RequireJS
* text plugin for RequireJS
* jQuery Cookies plugin
* Almond
* r.js with instructions to build the project
* Jasmine for BDD testing


Summary
===========

The build process will run the application through r.js, replacing require.js with almond.js in production. Information about how the project is built can be found in the app.build.js file in ```public\js```.

Building
===========

If you have node installed, the project can be built by running:
node public/js/app.build.js

However I'm lazy and like to type less so there's also a rake task:
If you would prefer a rake task that completes this task, try:
rake build

Usage:
=============
This project comes with a basic sinatra app for serving assets. If you have ruby and bundler installed just do:

bundle install
Using the project
===================

The backpack comes with a Sinatra application for serving up assets. You'll need both [ruby](http://www.ruby-lang.org/en/downloads/) and bundler installed in order to run this. To get bundler, simply run:

To run the project
gem install bundler

Follow the instructions at the ruby link above to download and install that dependency. The project can then be run using:

ruby app.rb

Then visit the following 3 urls:

This will give you the ability to access three URLs:

http://localhost:4567
http://localhost:4567/dev
http://localhost:4567/jquery <-- this file demonstrates how currently require.js will prefer the jquery loaded in the page to the one explicitly defined in the project.
http://localhost:4567/jquery <-- this file demonstrates how currently require.js will prefer the jquery loaded in the page to the one explicitly defined in the project.

Patched AMD Backbone and Underscore builds
===========================================

Backpack already contains patched AMD-compatible versions of Backbone.js and Underscore.js but if wish to grab the latest patched versions of these libraries they can be accessed from:

* https://github.com/amdjs/underscore
* https://github.com/amdjs/backbone


3 changes: 2 additions & 1 deletion app.rb
Expand Up @@ -15,4 +15,5 @@

get '/bookmarklet' do
File.read('bookmarklet.html')
end
end

5 changes: 0 additions & 5 deletions bookmarklet.html
Expand Up @@ -3,11 +3,6 @@
<head>
<title></title>
<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="distribution" content="all" />
<meta name="robots" content="all" />
<meta name="resource-type" content="document" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
</head>
<body>
Expand Down
5 changes: 0 additions & 5 deletions dev.html
Expand Up @@ -3,11 +3,6 @@
<head>
<title></title>
<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="distribution" content="all" />
<meta name="robots" content="all" />
<meta name="resource-type" content="document" />
<meta name="MSSmartTagsPreventParsing" content="true" />
</head>
<body>
<div id="container">This file doesn't attempt to compress or merge the javascript</div>
Expand Down
4 changes: 0 additions & 4 deletions index.html
Expand Up @@ -4,10 +4,6 @@
<title></title>
<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="distribution" content="all" />
<meta name="robots" content="all" />
<meta name="resource-type" content="document" />
<meta name="MSSmartTagsPreventParsing" content="true" />
</head>
<body>
<div id="container">This shows all files built with almond</div>
Expand Down
5 changes: 0 additions & 5 deletions jquery.html
Expand Up @@ -3,11 +3,6 @@
<head>
<title></title>
<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="distribution" content="all" />
<meta name="robots" content="all" />
<meta name="resource-type" content="document" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
</head>
<body>
Expand Down
Empty file added npm-debug.log
Empty file.
Binary file modified public/.DS_Store
Binary file not shown.
Binary file modified public/js/.DS_Store
Binary file not shown.
14 changes: 7 additions & 7 deletions public/js/app.build.js
Expand Up @@ -12,17 +12,17 @@ var requirejs = require('./r.js');
//Set up basic config, include config that is
//common to all the requirejs.optimize() calls.
var basConfig = {
baseUrl: "public/js",
locale: "en-us",
optimize: "uglify",
baseUrl: "public/js",
locale: "en-us",
optimize: "uglify",
//optimize: "none", // If you need to debug the compiled script
//namespace: "test", // If using Almond then no need to namespace
wrap: true,
paths: {
'jquery': 'libs/jquery/jquery',
'underscore': 'libs/underscore/underscore',
'backbone': 'libs/backbone/backbone',
'templates': '../templates'
'jquery': 'libs/jquery/jquery',
'underscore': 'libs/underscore/underscore',
'backbone': 'libs/backbone/backbone',
'templates': '../templates'
},

//All the built layers will use almond.
Expand Down
6 changes: 3 additions & 3 deletions public/js/app_main.js
@@ -1,7 +1,7 @@
define(['jquery',
'underscore',
'backbone',
'./routers/main_router'], function($, _, Backbone, MainRouter){
'underscore',
'backbone',
'./routers/main_router'], function($, _, Backbone, MainRouter){
return {
init: function(){
new MainRouter();
Expand Down

0 comments on commit 7fc3701

Please sign in to comment.