Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
BUNDLE_DISABLE_SHARED_GEMS: "1"
--- {}

40 changes: 13 additions & 27 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
source 'http://rubygems.org'

gem 'rails', '2.3.8'
gem 'jammit'
gem 'rails', '3.1.0'
gem 'sqlite3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
platforms :mri_18 do
gem 'json'
end

gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'haml'

# Use unicorn as the web server
# gem 'unicorn'
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem 'jquery-rails'
gem "eco", "~> 1.0.0"
gem 'ejs'
145 changes: 115 additions & 30 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,38 +1,123 @@
GEM
remote: http://rubygems.org/
specs:
actionmailer (2.3.8)
actionpack (= 2.3.8)
actionpack (2.3.8)
activesupport (= 2.3.8)
rack (~> 1.1.0)
activerecord (2.3.8)
activesupport (= 2.3.8)
activeresource (2.3.8)
activesupport (= 2.3.8)
activesupport (2.3.8)
closure-compiler (1.0.0)
jammit (0.6.0)
closure-compiler (>= 0.1.0)
yui-compressor (>= 0.9.1)
rack (1.1.0)
rails (2.3.8)
actionmailer (= 2.3.8)
actionpack (= 2.3.8)
activerecord (= 2.3.8)
activeresource (= 2.3.8)
activesupport (= 2.3.8)
rake (>= 0.8.3)
rake (0.8.7)
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
yui-compressor (0.9.3)
actionmailer (3.1.0)
actionpack (= 3.1.0)
mail (~> 2.3.0)
actionpack (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
builder (~> 3.0.0)
erubis (~> 2.7.0)
i18n (~> 0.6)
rack (~> 1.3.2)
rack-cache (~> 1.0.3)
rack-mount (~> 0.8.2)
rack-test (~> 0.6.1)
sprockets (~> 2.0.0)
activemodel (3.1.0)
activesupport (= 3.1.0)
bcrypt-ruby (~> 3.0.0)
builder (~> 3.0.0)
i18n (~> 0.6)
activerecord (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
arel (~> 2.2.1)
tzinfo (~> 0.3.29)
activeresource (3.1.0)
activemodel (= 3.1.0)
activesupport (= 3.1.0)
activesupport (3.1.0)
multi_json (~> 1.0)
arel (2.2.1)
bcrypt-ruby (3.0.0)
builder (3.0.0)
coffee-rails (3.1.0)
coffee-script (>= 2.2.0)
railties (~> 3.1.0.rc1)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.1.2)
eco (1.0.0)
coffee-script
eco-source
execjs
eco-source (1.1.0.rc.1)
ejs (1.0.0)
erubis (2.7.0)
execjs (1.2.4)
multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
jquery-rails (1.0.13)
railties (~> 3.0)
thor (~> 0.14)
json (1.5.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
polyglot (0.3.2)
rack (1.3.2)
rack-cache (1.0.3)
rack (>= 0.4)
rack-mount (0.8.3)
rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
rails (3.1.0)
actionmailer (= 3.1.0)
actionpack (= 3.1.0)
activerecord (= 3.1.0)
activeresource (= 3.1.0)
activesupport (= 3.1.0)
bundler (~> 1.0)
railties (= 3.1.0)
railties (3.1.0)
actionpack (= 3.1.0)
activesupport (= 3.1.0)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.9.4)
sass (3.1.7)
sass-rails (3.1.0)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1)
sqlite3 (1.3.4)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.29)
uglifier (1.0.2)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)

PLATFORMS
ruby

DEPENDENCIES
jammit
rails (= 2.3.8)
sqlite3-ruby
coffee-rails (~> 3.1.0)
eco (~> 1.0.0)
ejs
jquery-rails
json
rails (= 3.1.0)
sass-rails (~> 3.1.0)
sqlite3
uglifier
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

This is just a simple Backbone.js example.

I forked just for fun and study cases.

Take a look at the tutorial here:
http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/

To run, simply clone, add your own database.yml, and rake db:migrate.
To run, simply clone, cp config/database.yml.sample config/database.yml, and rake db:migrate.

7 changes: 2 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
CloudEdit::Application.load_tasks
131 changes: 131 additions & 0 deletions app/assets/javascripts/application.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//= require templates/document
//= require templates/documents_collection

App =
Views: {}
Controllers: {}
Collections: {}

init: ->
new App.Controllers.Documents()
Backbone.history.start()

class App.Controllers.Documents extends Backbone.Router
routes:
"documents/:id": "edit"
"": "index"
"new": "newDoc"

edit: (id) ->
document = new Document(id: id)

document.fetch
success: (model, resp) ->
new App.Views.Edit(model: document)
error: ->
new Error(message: "")
window.location.hash = "#"

index: ->
documents = new App.Collections.Documents()

documents.fetch
success: ->
new App.Views.Index collection: documents
error: ->
new Error message: "Error loading documents."

newDoc: ->
new App.Views.Edit(model: new Document())

class Document extends Backbone.Model
url: ->
base = "documents"

if this.isNew()
base
else
if base.charAt(base.length - 1) == "/"
base + "" + this.id
else
base + "/" + this.id

class App.Collections.Documents extends Backbone.Collection
model: Document
url: '/documents'

class App.Views.Index extends Backbone.View
initialize: ->
this.render()

render: ->
$(this.el).html(JST['templates/documents_collection'](collection: this.collection))
$("#app").html(this.el)

class App.Views.Edit extends Backbone.View
events:
"submit form": "save"

initialize: ->
this.model.bind "change", this.render
this.render()

save: ->
self = this
message = if this.model.isNew()
"Successfuly created!"
else
"Saved!"

data = { }

this.model.save
title: this.$('[name=title]').val()
body: this.$('[name=body]').val()
,
success: (model, response) =>
new App.Views.Notice message: message
Backbone.history.navigate("documents/" + model.id)

error: ->
new App.Views.Error()

false

render: =>
$(this.el).html(JST["templates/document"](model: this.model))
$("#app").html(this.el)

this.$("[name=title]").val(this.model.get("title"))

this.delegateEvents()

class App.Views.Notice extends Backbone.View
className: "success"
displayLength: 5000
defaultMessage: ""

initialize: ->
this.message = this.options.message || this.defaultMessage
this.render()

render: =>
view = this

$(this.el).html(this.message)
$(this.el).hide()
$('#notice').html(this.el)
$(this.el).slideDown()

$.doTimeout this.displayLength, ->
$(view.el).slideUp()
$.doTimeout 2000, -> view.remove()

this

class App.Views.Error extends App.Views.Notice
className: "error"
defaultMessage: "Uh oh! Something went wrong. Please try again."

window.Document = Document
window.App = App
Loading