Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial commit

  • Loading branch information...
commit 2210b59f6c9b9f0432385fb44f414d5be0d42b9e 0 parents
Sean Moon authored March 27, 2011

Showing 53 changed files with 10,241 additions and 0 deletions. Show diff stats Hide diff stats

  1. 6  .gitignore
  2. 11  Gemfile
  3. 106  Gemfile.lock
  4. 1  README
  5. 7  Rakefile
  6. 3  app/controllers/application_controller.rb
  7. 29  app/controllers/matches_controller.rb
  8. 2  app/helpers/application_helper.rb
  9. 24  app/helpers/matches_helper.rb
  10. 13  app/models/match.rb
  11. 13  app/views/layouts/application.html.haml
  12. 23  app/views/matches/index.html.haml
  13. 7  app/views/matches/rankings.html.haml
  14. 4  config.ru
  15. 42  config/application.rb
  16. 6  config/boot.rb
  17. 22  config/database.yml
  18. 5  config/environment.rb
  19. 26  config/environments/development.rb
  20. 49  config/environments/production.rb
  21. 35  config/environments/test.rb
  22. 7  config/initializers/backtrace_silencers.rb
  23. 10  config/initializers/inflections.rb
  24. 5  config/initializers/mime_types.rb
  25. 7  config/initializers/secret_token.rb
  26. 8  config/initializers/session_store.rb
  27. 5  config/locales/en.yml
  28. 8  config/routes.rb
  29. 15  db/migrate/20110325082358_create_matches.rb
  30. 23  db/schema.rb
  31. 7  db/seeds.rb
  32. 26  public/404.html
  33. 26  public/422.html
  34. 26  public/500.html
  35. 0  public/favicon.ico
  36. 2  public/javascripts/application.js
  37. 965  public/javascripts/controls.js
  38. 974  public/javascripts/dragdrop.js
  39. 1,123  public/javascripts/effects.js
  40. 6,001  public/javascripts/prototype.js
  41. 191  public/javascripts/rails.js
  42. 5  public/robots.txt
  43. 86  public/stylesheets/pong.css
  44. 103  public/stylesheets/reset.css
  45. 6  script/rails
  46. 54  spec/controllers/matches_controller_spec.rb
  47. 39  spec/helpers/matches_helper_spec.rb
  48. 10  spec/models/match_spec.rb
  49. 27  spec/spec_helper.rb
  50. 15  spec/views/matches/index.html.haml_spec.rb
  51. 11  spec/views/matches/rankings.html.haml_spec.rb
  52. 9  test/performance/browsing_test.rb
  53. 13  test/test_helper.rb
6  .gitignore
... ...
@@ -0,0 +1,6 @@
  1
+.DS_Store
  2
+.bundle
  3
+.rspec
  4
+tmp/
  5
+log/
  6
+*.sqlite3
11  Gemfile
... ...
@@ -0,0 +1,11 @@
  1
+source 'http://rubygems.org'
  2
+
  3
+gem 'rails', '3.0.5'
  4
+gem 'sqlite3'
  5
+
  6
+gem 'haml-rails'
  7
+gem 'heroku'
  8
+
  9
+group :test, :development do
  10
+  gem 'rspec-rails', '~> 2.4'
  11
+end
106  Gemfile.lock
... ...
@@ -0,0 +1,106 @@
  1
+GEM
  2
+  remote: http://rubygems.org/
  3
+  specs:
  4
+    abstract (1.0.0)
  5
+    actionmailer (3.0.5)
  6
+      actionpack (= 3.0.5)
  7
+      mail (~> 2.2.15)
  8
+    actionpack (3.0.5)
  9
+      activemodel (= 3.0.5)
  10
+      activesupport (= 3.0.5)
  11
+      builder (~> 2.1.2)
  12
+      erubis (~> 2.6.6)
  13
+      i18n (~> 0.4)
  14
+      rack (~> 1.2.1)
  15
+      rack-mount (~> 0.6.13)
  16
+      rack-test (~> 0.5.7)
  17
+      tzinfo (~> 0.3.23)
  18
+    activemodel (3.0.5)
  19
+      activesupport (= 3.0.5)
  20
+      builder (~> 2.1.2)
  21
+      i18n (~> 0.4)
  22
+    activerecord (3.0.5)
  23
+      activemodel (= 3.0.5)
  24
+      activesupport (= 3.0.5)
  25
+      arel (~> 2.0.2)
  26
+      tzinfo (~> 0.3.23)
  27
+    activeresource (3.0.5)
  28
+      activemodel (= 3.0.5)
  29
+      activesupport (= 3.0.5)
  30
+    activesupport (3.0.5)
  31
+    arel (2.0.9)
  32
+    builder (2.1.2)
  33
+    configuration (1.2.0)
  34
+    diff-lcs (1.1.2)
  35
+    erubis (2.6.6)
  36
+      abstract (>= 1.0.0)
  37
+    haml (3.0.25)
  38
+    haml-rails (0.3.4)
  39
+      actionpack (~> 3.0)
  40
+      activesupport (~> 3.0)
  41
+      haml (~> 3.0)
  42
+      railties (~> 3.0)
  43
+    heroku (1.19.1)
  44
+      activesupport (>= 2.1.0)
  45
+      launchy (~> 0.3.2)
  46
+      rest-client (>= 1.4.0, < 1.7.0)
  47
+    i18n (0.5.0)
  48
+    launchy (0.3.7)
  49
+      configuration (>= 0.0.5)
  50
+      rake (>= 0.8.1)
  51
+    mail (2.2.15)
  52
+      activesupport (>= 2.3.6)
  53
+      i18n (>= 0.4.0)
  54
+      mime-types (~> 1.16)
  55
+      treetop (~> 1.4.8)
  56
+    mime-types (1.16)
  57
+    polyglot (0.3.1)
  58
+    rack (1.2.2)
  59
+    rack-mount (0.6.14)
  60
+      rack (>= 1.0.0)
  61
+    rack-test (0.5.7)
  62
+      rack (>= 1.0)
  63
+    rails (3.0.5)
  64
+      actionmailer (= 3.0.5)
  65
+      actionpack (= 3.0.5)
  66
+      activerecord (= 3.0.5)
  67
+      activeresource (= 3.0.5)
  68
+      activesupport (= 3.0.5)
  69
+      bundler (~> 1.0)
  70
+      railties (= 3.0.5)
  71
+    railties (3.0.5)
  72
+      actionpack (= 3.0.5)
  73
+      activesupport (= 3.0.5)
  74
+      rake (>= 0.8.7)
  75
+      thor (~> 0.14.4)
  76
+    rake (0.8.7)
  77
+    rest-client (1.6.1)
  78
+      mime-types (>= 1.16)
  79
+    rspec (2.5.0)
  80
+      rspec-core (~> 2.5.0)
  81
+      rspec-expectations (~> 2.5.0)
  82
+      rspec-mocks (~> 2.5.0)
  83
+    rspec-core (2.5.1)
  84
+    rspec-expectations (2.5.0)
  85
+      diff-lcs (~> 1.1.2)
  86
+    rspec-mocks (2.5.0)
  87
+    rspec-rails (2.5.0)
  88
+      actionpack (~> 3.0)
  89
+      activesupport (~> 3.0)
  90
+      railties (~> 3.0)
  91
+      rspec (~> 2.5.0)
  92
+    sqlite3 (1.3.3)
  93
+    thor (0.14.6)
  94
+    treetop (1.4.9)
  95
+      polyglot (>= 0.3.1)
  96
+    tzinfo (0.3.25)
  97
+
  98
+PLATFORMS
  99
+  ruby
  100
+
  101
+DEPENDENCIES
  102
+  haml-rails
  103
+  heroku
  104
+  rails (= 3.0.5)
  105
+  rspec-rails (~> 2.4)
  106
+  sqlite3
1  README
... ...
@@ -0,0 +1 @@
  1
+Pong, yo
7  Rakefile
... ...
@@ -0,0 +1,7 @@
  1
+# Add your own tasks in files placed in lib/tasks ending in .rake,
  2
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
  3
+
  4
+require File.expand_path('../config/application', __FILE__)
  5
+require 'rake'
  6
+
  7
+Pong::Application.load_tasks
3  app/controllers/application_controller.rb
... ...
@@ -0,0 +1,3 @@
  1
+class ApplicationController < ActionController::Base
  2
+  protect_from_forgery
  3
+end
29  app/controllers/matches_controller.rb
... ...
@@ -0,0 +1,29 @@
  1
+class MatchesController < ApplicationController
  2
+  include MatchesHelper
  3
+
  4
+  def create
  5
+    match = Match.new(params[:match])
  6
+    match.save
  7
+    redirect_to matches_path
  8
+  end
  9
+
  10
+  def index
  11
+    @match = Match.new
  12
+    @matches = Match.order("date")
  13
+  end
  14
+
  15
+  def new
  16
+    @match = Match.new
  17
+  end
  18
+
  19
+  def rankings
  20
+    matches = Match.order("date")
  21
+    @rankings = calculate_rankings(matches)
  22
+  end
  23
+
  24
+  def update
  25
+    match = Match.find_by_id(params[:id])
  26
+    match.update_attributes(params[:match])
  27
+    redirect_to matches_path
  28
+  end
  29
+end
2  app/helpers/application_helper.rb
... ...
@@ -0,0 +1,2 @@
  1
+module ApplicationHelper
  2
+end
24  app/helpers/matches_helper.rb
... ...
@@ -0,0 +1,24 @@
  1
+module MatchesHelper
  2
+  def calculate_rankings(matches)
  3
+    ranking = []
  4
+
  5
+    matches.each do |match|
  6
+      winner = match.winner
  7
+      loser  = match.loser
  8
+
  9
+      ranking << winner unless ranking.include? winner
  10
+      ranking << loser  unless ranking.include? loser
  11
+
  12
+      winner_index = ranking.index(winner)
  13
+      loser_index  = ranking.index(loser)
  14
+
  15
+      if winner_index > loser_index
  16
+        new_index = (winner_index + loser_index) / 2
  17
+        ranking.delete_at(winner_index)
  18
+        ranking.insert(new_index, winner)
  19
+      end
  20
+    end
  21
+
  22
+    ranking
  23
+  end
  24
+end
13  app/models/match.rb
... ...
@@ -0,0 +1,13 @@
  1
+class Match < ActiveRecord::Base
  2
+  validates :winner, presence: true
  3
+  validates :loser,  presence: true
  4
+  validates :date,  presence: true
  5
+
  6
+  before_validation :set_default_date, on: :create
  7
+
  8
+  private
  9
+
  10
+  def set_default_date
  11
+    self.date ||= Time.now
  12
+  end
  13
+end
13  app/views/layouts/application.html.haml
... ...
@@ -0,0 +1,13 @@
  1
+<!DOCTYPE html>
  2
+%html
  3
+  %head
  4
+    %title Pivot Pong - NYC
  5
+    = stylesheet_link_tag :all
  6
+    = javascript_include_tag :defaults
  7
+    = csrf_meta_tag
  8
+
  9
+  %body
  10
+    #page
  11
+      #content
  12
+        %h1 pivot pong
  13
+        = yield
23  app/views/matches/index.html.haml
... ...
@@ -0,0 +1,23 @@
  1
+%h2 Match history
  2
+
  3
+%table
  4
+  %tr
  5
+    %th.date Date
  6
+    %th Winner
  7
+    %th Loser
  8
+  - @matches.each do |m|
  9
+    %tr{class: cycle("even", "odd")}
  10
+      %td.date= m.date.to_s
  11
+      %td= m.winner
  12
+      %td= m.loser
  13
+
  14
+= form_for(@match) do |f|
  15
+  = f.label :winner
  16
+  = f.text_field :winner
  17
+  = f.label :loser
  18
+  = f.text_field :loser
  19
+  = f.label :date
  20
+  = f.text_field :date, value: Time.now.strftime("%Y-%m-%d")
  21
+  = submit_tag "Add match"
  22
+
  23
+= link_to "Rankings", rankings_matches_path
7  app/views/matches/rankings.html.haml
... ...
@@ -0,0 +1,7 @@
  1
+%h2 Rankings
  2
+
  3
+%ol.rankings
  4
+  - @rankings.each do |player|
  5
+    %li{class: cycle("even", "odd")}= player
  6
+
  7
+= link_to "Match history", matches_path
4  config.ru
... ...
@@ -0,0 +1,4 @@
  1
+# This file is used by Rack-based servers to start the application.
  2
+
  3
+require ::File.expand_path('../config/environment',  __FILE__)
  4
+run Pong::Application
42  config/application.rb
... ...
@@ -0,0 +1,42 @@
  1
+require File.expand_path('../boot', __FILE__)
  2
+
  3
+require 'rails/all'
  4
+
  5
+# If you have a Gemfile, require the gems listed there, including any gems
  6
+# you've limited to :test, :development, or :production.
  7
+Bundler.require(:default, Rails.env) if defined?(Bundler)
  8
+
  9
+module Pong
  10
+  class Application < Rails::Application
  11
+    # Settings in config/environments/* take precedence over those specified here.
  12
+    # Application configuration should go into files in config/initializers
  13
+    # -- all .rb files in that directory are automatically loaded.
  14
+
  15
+    # Custom directories with classes and modules you want to be autoloadable.
  16
+    # config.autoload_paths += %W(#{config.root}/extras)
  17
+
  18
+    # Only load the plugins named here, in the order given (default is alphabetical).
  19
+    # :all can be used as a placeholder for all plugins not explicitly named.
  20
+    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
  21
+
  22
+    # Activate observers that should always be running.
  23
+    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
  24
+
  25
+    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  26
+    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
  27
+    # config.time_zone = 'Central Time (US & Canada)'
  28
+
  29
+    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  30
+    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
  31
+    # config.i18n.default_locale = :de
  32
+
  33
+    # JavaScript files you want as :defaults (application.js is always included).
  34
+    # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
  35
+
  36
+    # Configure the default encoding used in templates for Ruby 1.9.
  37
+    config.encoding = "utf-8"
  38
+
  39
+    # Configure sensitive parameters which will be filtered from the log file.
  40
+    config.filter_parameters += [:password]
  41
+  end
  42
+end
6  config/boot.rb
... ...
@@ -0,0 +1,6 @@
  1
+require 'rubygems'
  2
+
  3
+# Set up gems listed in the Gemfile.
  4
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
  5
+
  6
+require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
22  config/database.yml
... ...
@@ -0,0 +1,22 @@
  1
+# SQLite version 3.x
  2
+#   gem install sqlite3
  3
+development:
  4
+  adapter: sqlite3
  5
+  database: db/development.sqlite3
  6
+  pool: 5
  7
+  timeout: 5000
  8
+
  9
+# Warning: The database defined as "test" will be erased and
  10
+# re-generated from your development database when you run "rake".
  11
+# Do not set this db to the same as development or production.
  12
+test:
  13
+  adapter: sqlite3
  14
+  database: db/test.sqlite3
  15
+  pool: 5
  16
+  timeout: 5000
  17
+
  18
+production:
  19
+  adapter: sqlite3
  20
+  database: db/production.sqlite3
  21
+  pool: 5
  22
+  timeout: 5000
5  config/environment.rb
... ...
@@ -0,0 +1,5 @@
  1
+# Load the rails application
  2
+require File.expand_path('../application', __FILE__)
  3
+
  4
+# Initialize the rails application
  5
+Pong::Application.initialize!
26  config/environments/development.rb
... ...
@@ -0,0 +1,26 @@
  1
+Pong::Application.configure do
  2
+  # Settings specified here will take precedence over those in config/application.rb
  3
+
  4
+  # In the development environment your application's code is reloaded on
  5
+  # every request.  This slows down response time but is perfect for development
  6
+  # since you don't have to restart the webserver when you make code changes.
  7
+  config.cache_classes = false
  8
+
  9
+  # Log error messages when you accidentally call methods on nil.
  10
+  config.whiny_nils = true
  11
+
  12
+  # Show full error reports and disable caching
  13
+  config.consider_all_requests_local       = true
  14
+  config.action_view.debug_rjs             = true
  15
+  config.action_controller.perform_caching = false
  16
+
  17
+  # Don't care if the mailer can't send
  18
+  config.action_mailer.raise_delivery_errors = false
  19
+
  20
+  # Print deprecation notices to the Rails logger
  21
+  config.active_support.deprecation = :log
  22
+
  23
+  # Only use best-standards-support built into browsers
  24
+  config.action_dispatch.best_standards_support = :builtin
  25
+end
  26
+
49  config/environments/production.rb
... ...
@@ -0,0 +1,49 @@
  1
+Pong::Application.configure do
  2
+  # Settings specified here will take precedence over those in config/application.rb
  3
+
  4
+  # The production environment is meant for finished, "live" apps.
  5
+  # Code is not reloaded between requests
  6
+  config.cache_classes = true
  7
+
  8
+  # Full error reports are disabled and caching is turned on
  9
+  config.consider_all_requests_local       = false
  10
+  config.action_controller.perform_caching = true
  11
+
  12
+  # Specifies the header that your server uses for sending files
  13
+  config.action_dispatch.x_sendfile_header = "X-Sendfile"
  14
+
  15
+  # For nginx:
  16
+  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  17
+
  18
+  # If you have no front-end server that supports something like X-Sendfile,
  19
+  # just comment this out and Rails will serve the files
  20
+
  21
+  # See everything in the log (default is :info)
  22
+  # config.log_level = :debug
  23
+
  24
+  # Use a different logger for distributed setups
  25
+  # config.logger = SyslogLogger.new
  26
+
  27
+  # Use a different cache store in production
  28
+  # config.cache_store = :mem_cache_store
  29
+
  30
+  # Disable Rails's static asset server
  31
+  # In production, Apache or nginx will already do this
  32
+  config.serve_static_assets = false
  33
+
  34
+  # Enable serving of images, stylesheets, and javascripts from an asset server
  35
+  # config.action_controller.asset_host = "http://assets.example.com"
  36
+
  37
+  # Disable delivery errors, bad email addresses will be ignored
  38
+  # config.action_mailer.raise_delivery_errors = false
  39
+
  40
+  # Enable threaded mode
  41
+  # config.threadsafe!
  42
+
  43
+  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
  44
+  # the I18n.default_locale when a translation can not be found)
  45
+  config.i18n.fallbacks = true
  46
+
  47
+  # Send deprecation notices to registered listeners
  48
+  config.active_support.deprecation = :notify
  49
+end
35  config/environments/test.rb
... ...
@@ -0,0 +1,35 @@
  1
+Pong::Application.configure do
  2
+  # Settings specified here will take precedence over those in config/application.rb
  3
+
  4
+  # The test environment is used exclusively to run your application's
  5
+  # test suite.  You never need to work with it otherwise.  Remember that
  6
+  # your test database is "scratch space" for the test suite and is wiped
  7
+  # and recreated between test runs.  Don't rely on the data there!
  8
+  config.cache_classes = true
  9
+
  10
+  # Log error messages when you accidentally call methods on nil.
  11
+  config.whiny_nils = true
  12
+
  13
+  # Show full error reports and disable caching
  14
+  config.consider_all_requests_local       = true
  15
+  config.action_controller.perform_caching = false
  16
+
  17
+  # Raise exceptions instead of rendering exception templates
  18
+  config.action_dispatch.show_exceptions = false
  19
+
  20
+  # Disable request forgery protection in test environment
  21
+  config.action_controller.allow_forgery_protection    = false
  22
+
  23
+  # Tell Action Mailer not to deliver emails to the real world.
  24
+  # The :test delivery method accumulates sent emails in the
  25
+  # ActionMailer::Base.deliveries array.
  26
+  config.action_mailer.delivery_method = :test
  27
+
  28
+  # Use SQL instead of Active Record's schema dumper when creating the test database.
  29
+  # This is necessary if your schema can't be completely dumped by the schema dumper,
  30
+  # like if you have constraints or database-specific column types
  31
+  # config.active_record.schema_format = :sql
  32
+
  33
+  # Print deprecation notices to the stderr
  34
+  config.active_support.deprecation = :stderr
  35
+end
7  config/initializers/backtrace_silencers.rb
... ...
@@ -0,0 +1,7 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
  4
+# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
  5
+
  6
+# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
  7
+# Rails.backtrace_cleaner.remove_silencers!
10  config/initializers/inflections.rb
... ...
@@ -0,0 +1,10 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# Add new inflection rules using the following format
  4
+# (all these examples are active by default):
  5
+# ActiveSupport::Inflector.inflections do |inflect|
  6
+#   inflect.plural /^(ox)$/i, '\1en'
  7
+#   inflect.singular /^(ox)en/i, '\1'
  8
+#   inflect.irregular 'person', 'people'
  9
+#   inflect.uncountable %w( fish sheep )
  10
+# end
5  config/initializers/mime_types.rb
... ...
@@ -0,0 +1,5 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# Add new mime types for use in respond_to blocks:
  4
+# Mime::Type.register "text/richtext", :rtf
  5
+# Mime::Type.register_alias "text/html", :iphone
7  config/initializers/secret_token.rb
... ...
@@ -0,0 +1,7 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+# Your secret key for verifying the integrity of signed cookies.
  4
+# If you change this key, all old signed cookies will become invalid!
  5
+# Make sure the secret is at least 30 characters and all random,
  6
+# no regular words or you'll be exposed to dictionary attacks.
  7
+Pong::Application.config.secret_token = 'e05438b9313580c48220f2c44eff23531d0f40e372cf0294f7fa6c93c696729fb87db4735fc6eeb54c02b038118e3c67063a037df81e8c6f411d42da3c002609'
8  config/initializers/session_store.rb
... ...
@@ -0,0 +1,8 @@
  1
+# Be sure to restart your server when you modify this file.
  2
+
  3
+Pong::Application.config.session_store :cookie_store, :key => '_pong_session'
  4
+
  5
+# Use the database for sessions instead of the cookie-based default,
  6
+# which shouldn't be used to store highly confidential information
  7
+# (create the session table with "rails generate session_migration")
  8
+# Long::Application.config.session_store :active_record_store
5  config/locales/en.yml
... ...
@@ -0,0 +1,5 @@
  1
+# Sample localization file for English. Add more files in this directory for other locales.
  2
+# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
  3
+
  4
+en:
  5
+  hello: "Hello world"
8  config/routes.rb
... ...
@@ -0,0 +1,8 @@
  1
+Pong::Application.routes.draw do
  2
+  resources :matches do
  3
+    collection do
  4
+      get 'rankings'
  5
+    end
  6
+  end
  7
+  root to: 'matches#rankings'
  8
+end
15  db/migrate/20110325082358_create_matches.rb
... ...
@@ -0,0 +1,15 @@
  1
+class CreateMatches < ActiveRecord::Migration
  2
+  def self.up
  3
+    create_table :matches do |t|
  4
+      t.string :winner
  5
+      t.string :loser
  6
+      t.date :date
  7
+
  8
+      t.timestamps
  9
+    end
  10
+  end
  11
+
  12
+  def self.down
  13
+    drop_table :matches
  14
+  end
  15
+end
23  db/schema.rb
... ...
@@ -0,0 +1,23 @@
  1
+# This file is auto-generated from the current state of the database. Instead
  2
+# of editing this file, please use the migrations feature of Active Record to
  3
+# incrementally modify your database, and then regenerate this schema definition.
  4
+#
  5
+# Note that this schema.rb definition is the authoritative source for your
  6
+# database schema. If you need to create the application database on another
  7
+# system, you should be using db:schema:load, not running all the migrations
  8
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
  9
+# you'll amass, the slower it'll run and the greater likelihood for issues).
  10
+#
  11
+# It's strongly recommended to check this file into your version control system.
  12
+
  13
+ActiveRecord::Schema.define(:version => 20110325082358) do
  14
+
  15
+  create_table "matches", :force => true do |t|
  16
+    t.string   "winner"
  17
+    t.string   "loser"
  18
+    t.date     "date"
  19
+    t.datetime "created_at"
  20
+    t.datetime "updated_at"
  21
+  end
  22
+
  23
+end
7  db/seeds.rb
... ...
@@ -0,0 +1,7 @@
  1
+# This file should contain all the record creation needed to seed the database with its default values.
  2
+# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
  3
+#
  4
+# Examples:
  5
+#
  6
+#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
  7
+#   Mayor.create(:name => 'Daley', :city => cities.first)
26  public/404.html
... ...
@@ -0,0 +1,26 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+  <title>The page you were looking for doesn't exist (404)</title>
  5
+  <style type="text/css">
  6
+    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7
+    div.dialog {
  8
+      width: 25em;
  9
+      padding: 0 4em;
  10
+      margin: 4em auto 0 auto;
  11
+      border: 1px solid #ccc;
  12
+      border-right-color: #999;
  13
+      border-bottom-color: #999;
  14
+    }
  15
+    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16
+  </style>
  17
+</head>
  18
+
  19
+<body>
  20
+  <!-- This file lives in public/404.html -->
  21
+  <div class="dialog">
  22
+    <h1>The page you were looking for doesn't exist.</h1>
  23
+    <p>You may have mistyped the address or the page may have moved.</p>
  24
+  </div>
  25
+</body>
  26
+</html>
26  public/422.html
... ...
@@ -0,0 +1,26 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+  <title>The change you wanted was rejected (422)</title>
  5
+  <style type="text/css">
  6
+    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7
+    div.dialog {
  8
+      width: 25em;
  9
+      padding: 0 4em;
  10
+      margin: 4em auto 0 auto;
  11
+      border: 1px solid #ccc;
  12
+      border-right-color: #999;
  13
+      border-bottom-color: #999;
  14
+    }
  15
+    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16
+  </style>
  17
+</head>
  18
+
  19
+<body>
  20
+  <!-- This file lives in public/422.html -->
  21
+  <div class="dialog">
  22
+    <h1>The change you wanted was rejected.</h1>
  23
+    <p>Maybe you tried to change something you didn't have access to.</p>
  24
+  </div>
  25
+</body>
  26
+</html>
26  public/500.html
... ...
@@ -0,0 +1,26 @@
  1
+<!DOCTYPE html>
  2
+<html>
  3
+<head>
  4
+  <title>We're sorry, but something went wrong (500)</title>
  5
+  <style type="text/css">
  6
+    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
  7
+    div.dialog {
  8
+      width: 25em;
  9
+      padding: 0 4em;
  10
+      margin: 4em auto 0 auto;
  11
+      border: 1px solid #ccc;
  12
+      border-right-color: #999;
  13
+      border-bottom-color: #999;
  14
+    }
  15
+    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
  16
+  </style>
  17
+</head>
  18
+
  19
+<body>
  20
+  <!-- This file lives in public/500.html -->
  21
+  <div class="dialog">
  22
+    <h1>We're sorry, but something went wrong.</h1>
  23
+    <p>We've been notified about this issue and we'll take a look at it shortly.</p>
  24
+  </div>
  25
+</body>
  26
+</html>
0  public/favicon.ico
No changes.
2  public/javascripts/application.js
... ...
@@ -0,0 +1,2 @@
  1
+// Place your application-specific JavaScript functions and classes here
  2
+// This file is automatically included by javascript_include_tag :defaults
965  public/javascripts/controls.js
... ...
@@ -0,0 +1,965 @@
  1
+// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
  2
+
  3
+// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
  4
+//           (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
  5
+//           (c) 2005-2009 Jon Tirsen (http://www.tirsen.com)
  6
+// Contributors:
  7
+//  Richard Livsey
  8
+//  Rahul Bhargava
  9
+//  Rob Wills
  10
+//
  11
+// script.aculo.us is freely distributable under the terms of an MIT-style license.
  12
+// For details, see the script.aculo.us web site: http://script.aculo.us/
  13
+
  14
+// Autocompleter.Base handles all the autocompletion functionality
  15
+// that's independent of the data source for autocompletion. This
  16
+// includes drawing the autocompletion menu, observing keyboard
  17
+// and mouse events, and similar.
  18
+//
  19
+// Specific autocompleters need to provide, at the very least,
  20
+// a getUpdatedChoices function that will be invoked every time
  21
+// the text inside the monitored textbox changes. This method
  22
+// should get the text for which to provide autocompletion by
  23
+// invoking this.getToken(), NOT by directly accessing
  24
+// this.element.value. This is to allow incremental tokenized
  25
+// autocompletion. Specific auto-completion logic (AJAX, etc)
  26
+// belongs in getUpdatedChoices.
  27
+//
  28
+// Tokenized incremental autocompletion is enabled automatically
  29
+// when an autocompleter is instantiated with the 'tokens' option
  30
+// in the options parameter, e.g.:
  31
+// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
  32
+// will incrementally autocomplete with a comma as the token.
  33
+// Additionally, ',' in the above example can be replaced with
  34
+// a token array, e.g. { tokens: [',', '\n'] } which
  35
+// enables autocompletion on multiple tokens. This is most
  36
+// useful when one of the tokens is \n (a newline), as it
  37
+// allows smart autocompletion after linebreaks.
  38
+
  39
+if(typeof Effect == 'undefined')
  40
+  throw("controls.js requires including script.aculo.us' effects.js library");
  41
+
  42
+var Autocompleter = { };
  43
+Autocompleter.Base = Class.create({
  44
+  baseInitialize: function(element, update, options) {
  45
+    element          = $(element);
  46
+    this.element     = element;
  47
+    this.update      = $(update);
  48
+    this.hasFocus    = false;
  49
+    this.changed     = false;
  50
+    this.active      = false;
  51
+    this.index       = 0;
  52
+    this.entryCount  = 0;
  53
+    this.oldElementValue = this.element.value;
  54
+
  55
+    if(this.setOptions)
  56
+      this.setOptions(options);
  57
+    else
  58
+      this.options = options || { };
  59
+
  60
+    this.options.paramName    = this.options.paramName || this.element.name;
  61
+    this.options.tokens       = this.options.tokens || [];
  62
+    this.options.frequency    = this.options.frequency || 0.4;
  63
+    this.options.minChars     = this.options.minChars || 1;
  64
+    this.options.onShow       = this.options.onShow ||
  65
+      function(element, update){
  66
+        if(!update.style.position || update.style.position=='absolute') {
  67
+          update.style.position = 'absolute';
  68
+          Position.clone(element, update, {
  69
+            setHeight: false,
  70
+            offsetTop: element.offsetHeight
  71
+          });
  72
+        }
  73
+        Effect.Appear(update,{duration:0.15});
  74
+      };
  75
+    this.options.onHide = this.options.onHide ||
  76
+      function(element, update){ new Effect.Fade(update,{duration:0.15}) };
  77
+
  78
+    if(typeof(this.options.tokens) == 'string')
  79
+      this.options.tokens = new Array(this.options.tokens);
  80
+    // Force carriage returns as token delimiters anyway
  81
+    if (!this.options.tokens.include('\n'))
  82
+      this.options.tokens.push('\n');
  83
+
  84
+    this.observer = null;
  85
+
  86
+    this.element.setAttribute('autocomplete','off');
  87
+
  88
+    Element.hide(this.update);
  89
+
  90
+    Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
  91
+    Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
  92
+  },
  93
+
  94
+  show: function() {
  95
+    if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
  96
+    if(!this.iefix &&
  97
+      (Prototype.Browser.IE) &&
  98
+      (Element.getStyle(this.update, 'position')=='absolute')) {
  99
+      new Insertion.After(this.update,
  100
+       '<iframe id="' + this.update.id + '_iefix" '+
  101
+       'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
  102
+       'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
  103
+      this.iefix = $(this.update.id+'_iefix');
  104
+    }
  105
+    if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
  106
+  },
  107
+
  108
+  fixIEOverlapping: function() {
  109
+    Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
  110
+    this.iefix.style.zIndex = 1;
  111
+    this.update.style.zIndex = 2;
  112
+    Element.show(this.iefix);
  113
+  },
  114
+
  115
+  hide: function() {
  116
+    this.stopIndicator();
  117
+    if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
  118
+    if(this.iefix) Element.hide(this.iefix);
  119
+  },
  120
+
  121
+  startIndicator: function() {
  122
+    if(this.options.indicator) Element.show(this.options.indicator);
  123
+  },
  124
+
  125
+  stopIndicator: function() {
  126
+    if(this.options.indicator) Element.hide(this.options.indicator);
  127
+  },
  128
+
  129
+  onKeyPress: function(event) {
  130
+    if(this.active)
  131
+      switch(event.keyCode) {
  132
+       case Event.KEY_TAB:
  133
+       case Event.KEY_RETURN:
  134
+         this.selectEntry();
  135
+         Event.stop(event);
  136
+       case Event.KEY_ESC:
  137
+         this.hide();
  138
+         this.active = false;
  139
+         Event.stop(event);
  140
+         return;
  141
+       case Event.KEY_LEFT:
  142
+       case Event.KEY_RIGHT:
  143
+         return;
  144
+       case Event.KEY_UP:
  145
+         this.markPrevious();
  146
+         this.render();
  147
+         Event.stop(event);
  148
+         return;
  149
+       case Event.KEY_DOWN:
  150
+         this.markNext();
  151
+         this.render();
  152
+         Event.stop(event);
  153
+         return;
  154
+      }
  155
+     else
  156
+       if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
  157
+         (Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
  158
+
  159
+    this.changed = true;
  160
+    this.hasFocus = true;
  161
+
  162
+    if(this.observer) clearTimeout(this.observer);
  163
+      this.observer =
  164
+        setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
  165
+  },
  166
+
  167
+  activate: function() {
  168
+    this.changed = false;
  169
+    this.hasFocus = true;
  170
+    this.getUpdatedChoices();
  171
+  },
  172
+
  173
+  onHover: function(event) {
  174
+    var element = Event.findElement(event, 'LI');
  175
+    if(this.index != element.autocompleteIndex)
  176
+    {
  177
+        this.index = element.autocompleteIndex;
  178
+        this.render();
  179
+    }
  180
+    Event.stop(event);
  181
+  },
  182
+
  183
+  onClick: function(event) {
  184
+    var element = Event.findElement(event, 'LI');
  185
+    this.index = element.autocompleteIndex;
  186
+    this.selectEntry();
  187
+    this.hide();
  188
+  },
  189
+
  190
+  onBlur: function(event) {
  191
+    // needed to make click events working
  192
+    setTimeout(this.hide.bind(this), 250);
  193
+    this.hasFocus = false;
  194
+    this.active = false;
  195
+  },
  196
+
  197
+  render: function() {
  198
+    if(this.entryCount > 0) {
  199
+      for (var i = 0; i < this.entryCount; i++)
  200
+        this.index==i ?
  201
+          Element.addClassName(this.getEntry(i),"selected") :
  202
+          Element.removeClassName(this.getEntry(i),"selected");
  203
+      if(this.hasFocus) {
  204
+        this.show();
  205
+        this.active = true;
  206
+      }
  207
+    } else {
  208
+      this.active = false;
  209
+      this.hide();
  210
+    }
  211
+  },
  212
+
  213
+  markPrevious: function() {
  214
+    if(this.index > 0) this.index--;
  215
+      else this.index = this.entryCount-1;
  216
+    this.getEntry(this.index).scrollIntoView(true);
  217
+  },
  218
+
  219
+  markNext: function() {
  220
+    if(this.index < this.entryCount-1) this.index++;
  221
+      else this.index = 0;
  222
+    this.getEntry(this.index).scrollIntoView(false);
  223
+  },
  224
+
  225
+  getEntry: function(index) {
  226
+    return this.update.firstChild.childNodes[index];
  227
+  },
  228
+
  229
+  getCurrentEntry: function() {
  230
+    return this.getEntry(this.index);
  231
+  },
  232
+
  233
+  selectEntry: function() {
  234
+    this.active = false;
  235
+    this.updateElement(this.getCurrentEntry());
  236
+  },
  237
+
  238
+  updateElement: function(selectedElement) {
  239
+    if (this.options.updateElement) {
  240
+      this.options.updateElement(selectedElement);
  241
+      return;
  242
+    }
  243
+    var value = '';
  244
+    if (this.options.select) {
  245
+      var nodes = $(selectedElement).select('.' + this.options.select) || [];
  246
+      if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
  247
+    } else
  248
+      value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
  249
+
  250
+    var bounds = this.getTokenBounds();
  251
+    if (bounds[0] != -1) {
  252
+      var newValue = this.element.value.substr(0, bounds[0]);
  253
+      var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
  254
+      if (whitespace)
  255
+        newValue += whitespace[0];
  256
+      this.element.value = newValue + value + this.element.value.substr(bounds[1]);
  257
+    } else {
  258
+      this.element.value = value;
  259
+    }
  260
+    this.oldElementValue = this.element.value;
  261
+    this.element.focus();
  262
+
  263
+    if (this.options.afterUpdateElement)
  264
+      this.options.afterUpdateElement(this.element, selectedElement);
  265
+  },
  266
+
  267
+  updateChoices: function(choices) {
  268
+    if(!this.changed && this.hasFocus) {
  269
+      this.update.innerHTML = choices;
  270
+      Element.cleanWhitespace(this.update);
  271
+      Element.cleanWhitespace(this.update.down());
  272
+
  273
+      if(this.update.firstChild && this.update.down().childNodes) {
  274
+        this.entryCount =
  275
+          this.update.down().childNodes.length;
  276
+        for (var i = 0; i < this.entryCount; i++) {
  277
+          var entry = this.getEntry(i);
  278
+          entry.autocompleteIndex = i;
  279
+          this.addObservers(entry);
  280
+        }
  281
+      } else {
  282
+        this.entryCount = 0;
  283
+      }
  284
+
  285
+      this.stopIndicator();
  286
+      this.index = 0;
  287
+
  288
+      if(this.entryCount==1 && this.options.autoSelect) {
  289
+        this.selectEntry();
  290
+        this.hide();
  291
+      } else {
  292
+        this.render();
  293
+      }
  294
+    }
  295
+  },
  296
+
  297
+  addObservers: function(element) {
  298
+    Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
  299
+    Event.observe(element, "click", this.onClick.bindAsEventListener(this));
  300
+  },
  301
+
  302
+  onObserverEvent: function() {
  303
+    this.changed = false;
  304
+    this.tokenBounds = null;
  305
+    if(this.getToken().length>=this.options.minChars) {
  306
+      this.getUpdatedChoices();
  307
+    } else {
  308
+      this.active = false;
  309
+      this.hide();
  310
+    }
  311
+    this.oldElementValue = this.element.value;
  312
+  },
  313
+
  314
+  getToken: function() {
  315
+    var bounds = this.getTokenBounds();
  316
+    return this.element.value.substring(bounds[0], bounds[1]).strip();
  317
+  },
  318
+
  319
+  getTokenBounds: function() {
  320
+    if (null != this.tokenBounds) return this.tokenBounds;
  321
+    var value = this.element.value;
  322
+    if (value.strip().empty()) return [-1, 0];
  323
+    var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
  324
+    var offset = (diff == this.oldElementValue.length ? 1 : 0);
  325
+    var prevTokenPos = -1, nextTokenPos = value.length;
  326
+    var tp;
  327
+    for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
  328
+      tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
  329
+      if (tp > prevTokenPos) prevTokenPos = tp;
  330
+      tp = value.indexOf(this.options.tokens[index], diff + offset);
  331
+      if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
  332
+    }
  333
+    return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
  334
+  }
  335
+});
  336
+
  337
+Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
  338
+  var boundary = Math.min(newS.length, oldS.length);
  339
+  for (var index = 0; index < boundary; ++index)
  340
+    if (newS[index] != oldS[index])
  341
+      return index;
  342
+  return boundary;
  343
+};
  344
+
  345
+Ajax.Autocompleter = Class.create(Autocompleter.Base, {
  346
+  initialize: function(element, update, url, options) {
  347
+    this.baseInitialize(element, update, options);
  348
+    this.options.asynchronous  = true;
  349
+    this.options.onComplete    = this.onComplete.bind(this);
  350
+    this.options.defaultParams = this.options.parameters || null;
  351
+    this.url                   = url;
  352
+  },
  353
+
  354
+  getUpdatedChoices: function() {
  355
+    this.startIndicator();
  356
+
  357
+    var entry = encodeURIComponent(this.options.paramName) + '=' +
  358
+      encodeURIComponent(this.getToken());
  359
+
  360
+    this.options.parameters = this.options.callback ?
  361
+      this.options.callback(this.element, entry) : entry;
  362
+
  363
+    if(this.options.defaultParams)
  364
+      this.options.parameters += '&' + this.options.defaultParams;
  365
+
  366
+    new Ajax.Request(this.url, this.options);
  367
+  },
  368
+
  369
+  onComplete: function(request) {
  370
+    this.updateChoices(request.responseText);
  371
+  }
  372
+});
  373
+
  374
+// The local array autocompleter. Used when you'd prefer to
  375
+// inject an array of autocompletion options into the page, rather
  376
+// than sending out Ajax queries, which can be quite slow sometimes.
  377
+//
  378
+// The constructor takes four parameters. The first two are, as usual,
  379
+// the id of the monitored textbox, and id of the autocompletion menu.
  380
+// The third is the array you want to autocomplete from, and the fourth
  381
+// is the options block.
  382
+//
  383
+// Extra local autocompletion options:
  384
+// - choices - How many autocompletion choices to offer
  385
+//
  386
+// - partialSearch - If false, the autocompleter will match entered
  387
+//                    text only at the beginning of strings in the
  388
+//                    autocomplete array. Defaults to true, which will
  389
+//                    match text at the beginning of any *word* in the
  390
+//                    strings in the autocomplete array. If you want to
  391
+//                    search anywhere in the string, additionally set
  392
+//                    the option fullSearch to true (default: off).
  393
+//
  394
+// - fullSsearch - Search anywhere in autocomplete array strings.
  395
+//
  396
+// - partialChars - How many characters to enter before triggering
  397
+//                   a partial match (unlike minChars, which defines
  398
+//                   how many characters are required to do any match
  399
+//                   at all). Defaults to 2.
  400
+//
  401
+// - ignoreCase - Whether to ignore case when autocompleting.
  402
+//                 Defaults to true.
  403
+//
  404
+// It's possible to pass in a custom function as the 'selector'
  405
+// option, if you prefer to write your own autocompletion logic.
  406
+// In that case, the other options above will not apply unless
  407
+// you support them.
  408
+
  409
+Autocompleter.Local = Class.create(Autocompleter.Base, {
  410
+  initialize: function(element, update, array, options) {
  411
+    this.baseInitialize(element, update, options);
  412
+    this.options.array = array;
  413
+  },
  414
+
  415
+  getUpdatedChoices: function() {
  416
+    this.updateChoices(this.options.selector(this));
  417
+  },
  418
+
  419
+  setOptions: function(options) {
  420
+    this.options = Object.extend({
  421
+      choices: 10,
  422
+      partialSearch: true,
  423
+      partialChars: 2,
  424
+      ignoreCase: true,
  425
+      fullSearch: false,
  426
+      selector: function(instance) {
  427
+        var ret       = []; // Beginning matches
  428
+        var partial   = []; // Inside matches
  429
+        var entry     = instance.getToken();
  430
+        var count     = 0;
  431
+
  432
+        for (var i = 0; i < instance.options.array.length &&
  433
+          ret.length < instance.options.choices ; i++) {
  434
+
  435
+          var elem = instance.options.array[i];
  436
+          var foundPos = instance.options.ignoreCase ?
  437
+            elem.toLowerCase().indexOf(entry.toLowerCase()) :
  438
+            elem.indexOf(entry);
  439
+
  440
+          while (foundPos != -1) {
  441
+            if (foundPos == 0 && elem.length != entry.length) {
  442
+              ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
  443
+                elem.substr(entry.length) + "</li>");
  444
+              break;
  445
+            } else if (entry.length >= instance.options.partialChars &&
  446
+              instance.options.partialSearch && foundPos != -1) {
  447
+              if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
  448
+                partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
  449
+                  elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
  450
+                  foundPos + entry.length) + "</li>");
  451
+                break;
  452
+              }
  453
+            }
  454
+
  455
+            foundPos = instance.options.ignoreCase ?
  456
+              elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
  457
+              elem.indexOf(entry, foundPos + 1);
  458
+
  459
+          }
  460
+        }
  461
+        if (partial.length)
  462
+          ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
  463
+        return "<ul>" + ret.join('') + "</ul>";
  464
+      }
  465
+    }, options || { });