Oct 16 2010
- 04/10/2011 - Updated application.js and application.rb thanks to @rebo's comments
In this article, I will walk through some simple steps to get a [demo app][2] up and running with [Backbone.js][3] and [Sinatra][4] on [Heroku][5].
## | |
# This file should be renamed ".gitconfig" and placed inside your home directory. | |
## | |
[user] | |
name = YOUR_NAME | |
email = YOUR_EMAIL | |
[github] | |
user = YOUR_GITHUB_USERNAME | |
token = YOUR_GITHUB_TOKEN |
## | |
# Bash completion scripts | |
## | |
if [ -f /usr/local/git/contrib/completion/git-completion.bash ]; then | |
# Git OS X Installer: http://code.google.com/p/git-osx-installer/ | |
. /usr/local/git/contrib/completion/git-completion.bash | |
elif type brew > /dev/null 2>&1 && [ -f `brew --prefix`/etc/bash_completion ]; then | |
# Homebrew: http://mxcl.github.com/homebrew/ | |
. `brew --prefix`/etc/bash_completion | |
elif [ -f /opt/local/etc/bash_completion.d/git ]; then |
/* Scaled-down Backbone.js demonstration | |
* By Jacob Oscarson (http://twitter.com/jacob414), 2010 | |
* MIT Licenced, see http://www.opensource.org/licenses/mit-license.php */ | |
$(function() { | |
window.ulog = function(msg) { $('#log').append($('<div>'+msg+'</div>')); } | |
// Faking a little bit of Backbone.sync functionallity | |
Backbone.sync = function(method, model, succeeded) { | |
ulog('<strong>'+method + ":</strong> " + model.get('label')); | |
if(typeof model.cid != 'undefined') { |
importTemplate: => | |
if C2.user.credentials.length | |
@renderImportConfig() | |
# when creds are missing, create an error popup | |
else | |
content = | |
message: "Warning: Missing Credentials" | |
body: "AWS Credentials are required to import Templates" |
// render() function is a no-op (an empty function). | |
// Your view should call this function whenever the view needs to be redrawn. | |
var UserView = Backbone.View.extend( | |
initialize: function(){ | |
/* ... */ | |
} | |
render: function(){ | |
/* ... */ | |
} | |
); |
/*el is created using the attributes from the view’s tagName, className, or id properties. If none of these is specified, el is an empty div: | |
*/ | |
var UserView = Backbone.View.extend({ | |
tagName: "span", | |
className: "users" | |
}); | |
// Binding a view onto an existing element in the page. | |
// Make sure the view is set up after the page has loaded. |
/* | |
_.bindAll() ensures that all the functions you indicate are always invoked in the specified context. This is especially useful for event callbacks, as their context is always changing. | |
*/ | |
Account = Backbone.Model.extend({ | |
initialize: function() { | |
_.bindAll(this, 'removeElement'); | |
}, | |
removeElement: function() { |
body { | |
font-family: Helvetica, Verdana | |
} | |
p { | |
padding: 7px 10px; | |
} | |
#demo { | |
border: 1px solid #999; | |
} |
jQuery.fn.shuffleChildren = (function(){ | |
function fisherYatesShuffle(arr) { | |
// Fisher-Yates shuffle has been proven | |
// to be more random than the conventional | |
// arr.sort(function(){return Math.random()-.5}) | |
// http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html | |
var i = arr.length, |