Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit 0084e529756c9876de0820e0273eb73087245297 @rsim committed Jun 3, 2011
Showing with 13,317 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +1 −0 .rspec
  3. +18 −0 Gemfile
  4. +129 −0 Gemfile.lock
  5. +33 −0 README.md
  6. +7 −0 Rakefile
  7. +2 −0 app/coffeescripts/application.coffee
  8. +48 −0 app/coffeescripts/models/todo.coffee
  9. +14 −0 app/coffeescripts/views/helpers.coffee
  10. +144 −0 app/coffeescripts/views/todo_view.coffee
  11. +3 −0 app/controllers/application_controller.rb
  12. +39 −0 app/controllers/todos_controller.rb
  13. +2 −0 app/helpers/application_helper.rb
  14. +6 −0 app/models/todo.rb
  15. +8 −0 app/views/layouts/application.html.haml
  16. +41 −0 app/views/todos/index.html.haml
  17. +4 −0 config.ru
  18. +49 −0 config/application.rb
  19. +14 −0 config/assets.yml
  20. +13 −0 config/boot.rb
  21. +22 −0 config/database.yml
  22. +5 −0 config/environment.rb
  23. +26 −0 config/environments/development.rb
  24. +49 −0 config/environments/production.rb
  25. +35 −0 config/environments/test.rb
  26. +2 −0 config/initializers/backbone.rb
  27. +7 −0 config/initializers/backtrace_silencers.rb
  28. +53 −0 config/initializers/barista_config.rb
  29. +10 −0 config/initializers/inflections.rb
  30. +5 −0 config/initializers/mime_types.rb
  31. +7 −0 config/initializers/secret_token.rb
  32. +8 −0 config/initializers/session_store.rb
  33. +5 −0 config/locales/en.yml
  34. +62 −0 config/routes.rb
  35. +15 −0 db/migrate/20101104122721_create_todos.rb
  36. +23 −0 db/schema.rb
  37. +7 −0 db/seeds.rb
  38. +2 −0 doc/README_FOR_APP
  39. 0 lib/tasks/.gitkeep
  40. +26 −0 public/404.html
  41. +26 −0 public/422.html
  42. +26 −0 public/500.html
  43. 0 public/favicon.ico
  44. BIN public/images/destroy.png
  45. +1,098 −0 public/javascripts/vendor/backbone.js
  46. +1,432 −0 public/javascripts/vendor/handlebars.js
  47. +8,374 −0 public/javascripts/vendor/jquery.js
  48. +807 −0 public/javascripts/vendor/underscore.js
  49. +5 −0 public/robots.txt
  50. 0 public/stylesheets/.gitkeep
  51. +56 −0 public/stylesheets/scaffold.css
  52. +311 −0 public/stylesheets/todos.css
  53. +6 −0 script/rails
  54. +5 −0 spec/coffeescripts/helpers/spec_helper.coffee
  55. +37 −0 spec/coffeescripts/models/todo_spec.coffee
  56. +82 −0 spec/javascripts/support/jasmine.yml
  57. +41 −0 spec/javascripts/support/jasmine_config.rb
  58. +21 −0 spec/javascripts/support/jasmine_runner.rb
  59. +10 −0 spec/models/todo_spec.rb
  60. +27 −0 spec/spec_helper.rb
  61. 0 vendor/plugins/.gitkeep
@@ -0,0 +1,9 @@
+.bundle
+.livereload
+.rvmrc
+.DS_Store
+db/*.sqlite3
+log/*.log
+tmp/**/*
+/public/javascripts/compiled
+/spec/javascripts/compiled
1 .rspec
@@ -0,0 +1 @@
+--colour
18 Gemfile
@@ -0,0 +1,18 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.7'
+
+gem 'rake', '0.8.7'
+
+gem 'sqlite3', :require => 'sqlite3'
+
+gem 'haml'
+gem 'json'
+gem 'barista'
+gem 'jammit'
+
+group :development, :test do
+ gem 'awesome_print', :require => 'ap'
+ gem 'rspec-rails', '~> 2.0'
+ gem 'jasmine'
+end
@@ -0,0 +1,129 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ POpen4 (0.1.4)
+ Platform (>= 0.4.0)
+ open4
+ Platform (0.4.0)
+ abstract (1.0.0)
+ actionmailer (3.0.7)
+ actionpack (= 3.0.7)
+ mail (~> 2.2.15)
+ actionpack (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ activesupport (3.0.7)
+ arel (2.0.10)
+ awesome_print (0.4.0)
+ barista (1.0.0)
+ coffee-script (~> 2.1.1)
+ builder (2.1.2)
+ childprocess (0.1.9)
+ ffi (~> 1.0.6)
+ closure-compiler (1.1.1)
+ coffee-script (2.1.3)
+ coffee-script-source
+ coffee-script-source (1.1.1)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ ffi (1.0.9)
+ haml (3.1.1)
+ i18n (0.5.0)
+ jammit (0.6.0)
+ closure-compiler (>= 0.1.0)
+ yui-compressor (>= 0.9.1)
+ jasmine (1.0.2.1)
+ json_pure (>= 1.4.3)
+ rack (>= 1.1)
+ rspec (>= 1.3.1)
+ selenium-webdriver (>= 0.1.3)
+ json (1.5.1)
+ json_pure (1.5.1)
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ open4 (1.0.1)
+ polyglot (0.3.1)
+ rack (1.2.3)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.7)
+ actionmailer (= 3.0.7)
+ actionpack (= 3.0.7)
+ activerecord (= 3.0.7)
+ activeresource (= 3.0.7)
+ activesupport (= 3.0.7)
+ bundler (~> 1.0)
+ railties (= 3.0.7)
+ railties (3.0.7)
+ actionpack (= 3.0.7)
+ activesupport (= 3.0.7)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.3)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.2.0)
+ childprocess (>= 0.1.7)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+ sqlite3 (1.3.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.27)
+ yui-compressor (0.9.6)
+ POpen4 (>= 0.1.4)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ awesome_print
+ barista
+ haml
+ jammit
+ jasmine
+ json
+ rails (= 3.0.7)
+ rake (= 0.8.7)
+ rspec-rails (~> 2.0)
+ sqlite3
@@ -0,0 +1,33 @@
+Overview
+========
+
+This is sample Rails application that demonstrates usage of
+
+* [Backbone.js](http://documentcloud.github.com/backbone/)
+* [CoffeeScript](http://jashkenas.github.com/coffee-script/)
+* [Jasmine](http://pivotal.github.com/jasmine/)
+
+This demo was used during [RailsWayCon 2011](http://railswaycon.com/2011/sessions#session-17838) conference presentation [Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine](http://www.slideshare.net/rsim/railslike-javascript-using-coffeescript-backbonejs-and-jasmine-8196890).
+
+Source code is based on original [Todos application](http://documentcloud.github.com/backbone/docs/todos.html) by [Jérôme Gravel-Niquet](https://github.com/jeromegn).
+
+Running application
+===================
+
+Install gems, run migrations and start application with
+
+ bundle install
+ rake db:migrate
+ rails server
+
+And then visit `http://localhost:3000`.
+
+Running tests
+=============
+
+Run `rake jasmine` and then visit `http://localhost:8888` to execute Jasmine tests and see results.
+
+Application source code
+=======================
+
+Backbone.js models and views written in CoffeeScript are located in `app/coffeescripts` directory and Jasmine tests are located in `spec/coffeescripts` directory.
@@ -0,0 +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.expand_path('../config/application', __FILE__)
+require 'rake'
+
+BackboneTodo::Application.load_tasks
@@ -0,0 +1,2 @@
+# main namespace
+window.TodoApp = {}
@@ -0,0 +1,48 @@
+# Todo Model
+# ----------
+
+# Our basic **Todo** model has `content`, `order`, and `done` attributes.
+class TodoApp.Todo extends Backbone.Model
+
+ # If you don't provide a todo, one will be provided for you.
+ EMPTY: "empty todo..."
+
+ # Ensure that each todo created has `content`.
+ initialize: ->
+ unless @get "content"
+ @set content: @EMPTY
+
+ # Toggle the `done` state of this todo item.
+ toggle: ->
+ @save done: not @get "done"
+
+
+# Todo Collection
+# ---------------
+#
+# The collection of todos is backed by TodosController
+#
+class TodoApp.TodoList extends Backbone.Collection
+
+ # Reference to this collection's model.
+ model: TodoApp.Todo
+
+ # Save all of the todo items under the `"todos"` namespace.
+ url: '/todos'
+
+ # Filter down the list of all todo items that are finished.
+ done: ->
+ @filter (todo) -> todo.get 'done'
+
+ # Filter down the list to only todo items that are still not finished.
+ remaining: ->
+ @without this.done()...
+
+ # We keep the Todos in sequential order, despite being saved by unordered
+ # GUID in the database. This generates the next order number for new items.
+ nextOrder: ->
+ if @length then @last().get('order') + 1 else 1
+
+ # Todos are sorted by their original insertion order.
+ comparator: (todo) ->
+ todo.get 'order'
@@ -0,0 +1,14 @@
+# Compile and store template function from DOM element with specified selector
+TodoApp.template = (selector) ->
+ template = null
+ ->
+ template ?= Handlebars.compile(if selector.charAt(0) == "#" then $(selector).html() else selector)
+ template.apply this, arguments
+
+Handlebars.registerHelper 'debug', (ctx) ->
+ context = typeof ctx == "function" ? ctx.call this : ctx
+ console.log context
+
+
+Handlebars.registerHelper 'pluralize', (count, word, fn) ->
+ if count != 1 then word+"s" else word
Oops, something went wrong.

0 comments on commit 0084e52

Please sign in to comment.