Permalink
Browse files

initial commit

  • Loading branch information...
seanmoon committed Mar 28, 2011
0 parents commit 2210b59f6c9b9f0432385fb44f414d5be0d42b9e
Showing with 10,241 additions and 0 deletions.
  1. +6 −0 .gitignore
  2. +11 −0 Gemfile
  3. +106 −0 Gemfile.lock
  4. +1 −0 README
  5. +7 −0 Rakefile
  6. +3 −0 app/controllers/application_controller.rb
  7. +29 −0 app/controllers/matches_controller.rb
  8. +2 −0 app/helpers/application_helper.rb
  9. +24 −0 app/helpers/matches_helper.rb
  10. +13 −0 app/models/match.rb
  11. +13 −0 app/views/layouts/application.html.haml
  12. +23 −0 app/views/matches/index.html.haml
  13. +7 −0 app/views/matches/rankings.html.haml
  14. +4 −0 config.ru
  15. +42 −0 config/application.rb
  16. +6 −0 config/boot.rb
  17. +22 −0 config/database.yml
  18. +5 −0 config/environment.rb
  19. +26 −0 config/environments/development.rb
  20. +49 −0 config/environments/production.rb
  21. +35 −0 config/environments/test.rb
  22. +7 −0 config/initializers/backtrace_silencers.rb
  23. +10 −0 config/initializers/inflections.rb
  24. +5 −0 config/initializers/mime_types.rb
  25. +7 −0 config/initializers/secret_token.rb
  26. +8 −0 config/initializers/session_store.rb
  27. +5 −0 config/locales/en.yml
  28. +8 −0 config/routes.rb
  29. +15 −0 db/migrate/20110325082358_create_matches.rb
  30. +23 −0 db/schema.rb
  31. +7 −0 db/seeds.rb
  32. +26 −0 public/404.html
  33. +26 −0 public/422.html
  34. +26 −0 public/500.html
  35. 0 public/favicon.ico
  36. +2 −0 public/javascripts/application.js
  37. +965 −0 public/javascripts/controls.js
  38. +974 −0 public/javascripts/dragdrop.js
  39. +1,123 −0 public/javascripts/effects.js
  40. +6,001 −0 public/javascripts/prototype.js
  41. +191 −0 public/javascripts/rails.js
  42. +5 −0 public/robots.txt
  43. +86 −0 public/stylesheets/pong.css
  44. +103 −0 public/stylesheets/reset.css
  45. +6 −0 script/rails
  46. +54 −0 spec/controllers/matches_controller_spec.rb
  47. +39 −0 spec/helpers/matches_helper_spec.rb
  48. +10 −0 spec/models/match_spec.rb
  49. +27 −0 spec/spec_helper.rb
  50. +15 −0 spec/views/matches/index.html.haml_spec.rb
  51. +11 −0 spec/views/matches/rankings.html.haml_spec.rb
  52. +9 −0 test/performance/browsing_test.rb
  53. +13 −0 test/test_helper.rb
@@ -0,0 +1,6 @@
+.DS_Store
+.bundle
+.rspec
+tmp/
+log/
+*.sqlite3
11 Gemfile
@@ -0,0 +1,11 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.5'
+gem 'sqlite3'
+
+gem 'haml-rails'
+gem 'heroku'
+
+group :test, :development do
+ gem 'rspec-rails', '~> 2.4'
+end
@@ -0,0 +1,106 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.5)
+ actionpack (= 3.0.5)
+ mail (~> 2.2.15)
+ actionpack (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.5)
+ activesupport (= 3.0.5)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.5)
+ activemodel (= 3.0.5)
+ activesupport (= 3.0.5)
+ activesupport (3.0.5)
+ arel (2.0.9)
+ builder (2.1.2)
+ configuration (1.2.0)
+ diff-lcs (1.1.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ haml (3.0.25)
+ haml-rails (0.3.4)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ haml (~> 3.0)
+ railties (~> 3.0)
+ heroku (1.19.1)
+ activesupport (>= 2.1.0)
+ launchy (~> 0.3.2)
+ rest-client (>= 1.4.0, < 1.7.0)
+ i18n (0.5.0)
+ launchy (0.3.7)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ mail (2.2.15)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ polyglot (0.3.1)
+ rack (1.2.2)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.5)
+ actionmailer (= 3.0.5)
+ actionpack (= 3.0.5)
+ activerecord (= 3.0.5)
+ activeresource (= 3.0.5)
+ activesupport (= 3.0.5)
+ bundler (~> 1.0)
+ railties (= 3.0.5)
+ railties (3.0.5)
+ actionpack (= 3.0.5)
+ activesupport (= 3.0.5)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ rest-client (1.6.1)
+ mime-types (>= 1.16)
+ rspec (2.5.0)
+ rspec-core (~> 2.5.0)
+ rspec-expectations (~> 2.5.0)
+ rspec-mocks (~> 2.5.0)
+ rspec-core (2.5.1)
+ rspec-expectations (2.5.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.5.0)
+ rspec-rails (2.5.0)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.5.0)
+ sqlite3 (1.3.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.25)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ haml-rails
+ heroku
+ rails (= 3.0.5)
+ rspec-rails (~> 2.4)
+ sqlite3
1 README
@@ -0,0 +1 @@
+Pong, yo
@@ -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'
+
+Pong::Application.load_tasks
@@ -0,0 +1,3 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+end
@@ -0,0 +1,29 @@
+class MatchesController < ApplicationController
+ include MatchesHelper
+
+ def create
+ match = Match.new(params[:match])
+ match.save
+ redirect_to matches_path
+ end
+
+ def index
+ @match = Match.new
+ @matches = Match.order("date")
+ end
+
+ def new
+ @match = Match.new
+ end
+
+ def rankings
+ matches = Match.order("date")
+ @rankings = calculate_rankings(matches)
+ end
+
+ def update
+ match = Match.find_by_id(params[:id])
+ match.update_attributes(params[:match])
+ redirect_to matches_path
+ end
+end
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
@@ -0,0 +1,24 @@
+module MatchesHelper
+ def calculate_rankings(matches)
+ ranking = []
+
+ matches.each do |match|
+ winner = match.winner
+ loser = match.loser
+
+ ranking << winner unless ranking.include? winner
+ ranking << loser unless ranking.include? loser
+
+ winner_index = ranking.index(winner)
+ loser_index = ranking.index(loser)
+
+ if winner_index > loser_index
+ new_index = (winner_index + loser_index) / 2
+ ranking.delete_at(winner_index)
+ ranking.insert(new_index, winner)
+ end
+ end
+
+ ranking
+ end
+end
@@ -0,0 +1,13 @@
+class Match < ActiveRecord::Base
+ validates :winner, presence: true
+ validates :loser, presence: true
+ validates :date, presence: true
+
+ before_validation :set_default_date, on: :create
+
+ private
+
+ def set_default_date
+ self.date ||= Time.now
+ end
+end
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+%html
+ %head
+ %title Pivot Pong - NYC
+ = stylesheet_link_tag :all
+ = javascript_include_tag :defaults
+ = csrf_meta_tag
+
+ %body
+ #page
+ #content
+ %h1 pivot pong
+ = yield
@@ -0,0 +1,23 @@
+%h2 Match history
+
+%table
+ %tr
+ %th.date Date
+ %th Winner
+ %th Loser
+ - @matches.each do |m|
+ %tr{class: cycle("even", "odd")}
+ %td.date= m.date.to_s
+ %td= m.winner
+ %td= m.loser
+
+= form_for(@match) do |f|
+ = f.label :winner
+ = f.text_field :winner
+ = f.label :loser
+ = f.text_field :loser
+ = f.label :date
+ = f.text_field :date, value: Time.now.strftime("%Y-%m-%d")
+ = submit_tag "Add match"
+
+= link_to "Rankings", rankings_matches_path
@@ -0,0 +1,7 @@
+%h2 Rankings
+
+%ol.rankings
+ - @rankings.each do |player|
+ %li{class: cycle("even", "odd")}= player
+
+= link_to "Match history", matches_path
@@ -0,0 +1,4 @@
+# This file is used by Rack-based servers to start the application.
+
+require ::File.expand_path('../config/environment', __FILE__)
+run Pong::Application
@@ -0,0 +1,42 @@
+require File.expand_path('../boot', __FILE__)
+
+require 'rails/all'
+
+# If you have a Gemfile, require the gems listed there, including any gems
+# you've limited to :test, :development, or :production.
+Bundler.require(:default, Rails.env) if defined?(Bundler)
+
+module Pong
+ class Application < Rails::Application
+ # Settings in config/environments/* take precedence over those specified here.
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+
+ # Custom directories with classes and modules you want to be autoloadable.
+ # config.autoload_paths += %W(#{config.root}/extras)
+
+ # Only load the plugins named here, in the order given (default is alphabetical).
+ # :all can be used as a placeholder for all plugins not explicitly named.
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
+ # Activate observers that should always be running.
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
+
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
+ # config.time_zone = 'Central Time (US & Canada)'
+
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+ # config.i18n.default_locale = :de
+
+ # JavaScript files you want as :defaults (application.js is always included).
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
+
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
+ # Configure sensitive parameters which will be filtered from the log file.
+ config.filter_parameters += [:password]
+ end
+end
@@ -0,0 +1,6 @@
+require 'rubygems'
+
+# Set up gems listed in the Gemfile.
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
+
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,22 @@
+# SQLite version 3.x
+# gem install sqlite3
+development:
+ adapter: sqlite3
+ database: db/development.sqlite3
+ pool: 5
+ timeout: 5000
+
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+test:
+ adapter: sqlite3
+ database: db/test.sqlite3
+ pool: 5
+ timeout: 5000
+
+production:
+ adapter: sqlite3
+ database: db/production.sqlite3
+ pool: 5
+ timeout: 5000
@@ -0,0 +1,5 @@
+# Load the rails application
+require File.expand_path('../application', __FILE__)
+
+# Initialize the rails application
+Pong::Application.initialize!
@@ -0,0 +1,26 @@
+Pong::Application.configure do
+ # Settings specified here will take precedence over those in config/application.rb
+
+ # In the development environment your application's code is reloaded on
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the webserver when you make code changes.
+ config.cache_classes = false
+
+ # Log error messages when you accidentally call methods on nil.
+ config.whiny_nils = true
+
+ # Show full error reports and disable caching
+ config.consider_all_requests_local = true
+ config.action_view.debug_rjs = true
+ config.action_controller.perform_caching = false
+
+ # Don't care if the mailer can't send
+ config.action_mailer.raise_delivery_errors = false
+
+ # Print deprecation notices to the Rails logger
+ config.active_support.deprecation = :log
+
+ # Only use best-standards-support built into browsers
+ config.action_dispatch.best_standards_support = :builtin
+end
+
Oops, something went wrong.

0 comments on commit 2210b59

Please sign in to comment.