Skip to content
Browse files

Update to newest suspenders

  • Loading branch information...
2 parents 12489da + 07f834d commit b79c73ebe7ae60356ee98a02ab851658ac33bda6 @mike-burns committed
Showing with 1,705 additions and 5,636 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Rakefile
  3. 0 app/controllers/{application.rb → application_controller.rb}
  4. +4 −4 app/views/layouts/application.html.erb
  5. 0 app/views/{layouts → shared}/_flashes.html.erb
  6. +2 −0 app/views/shared/_javascript.html.erb
  7. +3 −2 config/boot.rb
  8. +6 −6 config/database.yml
  9. +6 −0 config/deploy.rb
  10. +46 −22 config/environment.rb
  11. +50 −0 config/environments/cucumber.rb
  12. +1 −1 config/environments/development.rb
  13. +36 −4 config/environments/test.rb
  14. +11 −0 config/initializers/backtrace_silencers.rb
  15. +30 −0 config/initializers/bigdecimal-segfault-fix.rb
  16. +26 −0 config/initializers/errors.rb
  17. +10 −0 config/initializers/mocks.rb
  18. +19 −0 config/initializers/new_rails_defaults.rb
  19. +5 −0 config/initializers/noisy_attr_accessible.rb
  20. +0 −6 config/initializers/requires.rb
  21. +15 −0 config/initializers/session_store.rb
  22. +3 −2 config/initializers/time_formats.rb
  23. +7 −0 config/locales/en.yml
  24. +61 −31 doc/README_FOR_TEMPLATE
  25. +4 −0 features/step_definitions/debug_steps.rb
  26. +119 −0 features/step_definitions/webrat_steps.rb
  27. +24 −0 features/support/env.rb
  28. 0 vendor/gems/thoughtbot-shoulda-2.0.5/test/rails_root/db/schema.rb → features/support/paperclip/.keep
  29. +27 −0 features/support/paths.rb
  30. +16 −0 lib/tasks/cucumber.rake
  31. 0 vendor/gems/thoughtbot-shoulda-2.0.5/test/rails_root/config/environments/sqlite3.rb → log/.keep
  32. +72 −72 public/javascripts/controls.js
  33. +165 −164 public/javascripts/dragdrop.js
  34. +173 −165 public/javascripts/effects.js
  35. +362 −267 public/javascripts/prototype.js
  36. +23 −1 script/create_project
  37. +8 −0 script/cucumber
  38. +1 −1 test/functional/accounts_controller_test.rb
  39. +3 −3 test/functional/moods_controller_test.rb
  40. +5 −5 test/functional/openids_controller_test.rb
  41. +4 −4 test/functional/sessions_controller_test.rb
  42. +2 −2 test/functional/users_controller_test.rb
  43. +59 −0 test/shoulda_macros/forms.rb
  44. +38 −5 test/shoulda_macros/pagination.rb
  45. +1 −1 test/shoulda_macros/session.rb
  46. +25 −3 test/test_helper.rb
  47. +1 −1 test/unit/mood_test.rb
  48. +2 −2 test/unit/user_test.rb
  49. +55 −0 vendor/gems/RedCloth-3.0.4/.specification
  50. +0 −3 vendor/gems/RedCloth-3.0.4/bin/redcloth
  51. +0 −160 vendor/gems/RedCloth-3.0.4/doc/CHANGELOG
  52. +0 −25 vendor/gems/RedCloth-3.0.4/doc/COPYING
  53. +0 −106 vendor/gems/RedCloth-3.0.4/doc/README
  54. +0 −216 vendor/gems/RedCloth-3.0.4/doc/REFERENCE
  55. +0 −359 vendor/gems/RedCloth-3.0.4/doc/make.rb
  56. +0 −1,130 vendor/gems/RedCloth-3.0.4/lib/redcloth.rb
  57. +0 −28 vendor/gems/RedCloth-3.0.4/run-tests.rb
  58. +0 −1,376 vendor/gems/RedCloth-3.0.4/setup.rb
  59. +0 −105 vendor/gems/RedCloth-3.0.4/tests/code.yml
  60. +0 −26 vendor/gems/RedCloth-3.0.4/tests/hard_breaks.yml
  61. +0 −171 vendor/gems/RedCloth-3.0.4/tests/images.yml
  62. +0 −39 vendor/gems/RedCloth-3.0.4/tests/instiki.yml
  63. +0 −155 vendor/gems/RedCloth-3.0.4/tests/links.yml
  64. +0 −77 vendor/gems/RedCloth-3.0.4/tests/lists.yml
  65. +0 −218 vendor/gems/RedCloth-3.0.4/tests/markdown.yml
  66. +0 −64 vendor/gems/RedCloth-3.0.4/tests/poignant.yml
  67. +0 −198 vendor/gems/RedCloth-3.0.4/tests/table.yml
  68. +0 −406 vendor/gems/RedCloth-3.0.4/tests/textism.yml
  69. +85 −0 vendor/gems/builder-2.1.2/.specification
  70. +85 −0 vendor/gems/builder-2.1.2/CHANGES
Sorry, we could not display the entire diff because too many files (3,192) changed.
View
2 .gitignore
@@ -7,3 +7,5 @@ public/system
coverage/*
*.sw*
.rake_tasks
+*.swp
+!.keep
View
3 Rakefile
@@ -8,3 +8,6 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
+
+desc "Run all tests and features"
+task :default => [:test, :features]
View
0 app/controllers/application.rb → app/controllers/application_controller.rb
File renamed without changes.
View
8 app/views/layouts/application.html.erb
@@ -3,12 +3,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
- <title><%= PROJECT_NAME.humanize %></title>
- <%= stylesheet_link_tag 'screen', :media => 'all' %>
- <%= javascript_include_tag :defaults %>
+ <title>CHANGEME</title>
+ <%= stylesheet_link_tag 'screen', :media => 'all', :cache => true %>
</head>
<body class="<%= body_class %>">
- <%= render :partial => 'layouts/flashes' -%>
+ <%= render :partial => 'shared/flashes' -%>
<%= yield %>
+ <%= render :partial => 'shared/javascript' %>
</body>
</html>
View
0 app/views/layouts/_flashes.html.erb → app/views/shared/_flashes.html.erb
File renamed without changes.
View
2 app/views/shared/_javascript.html.erb
@@ -0,0 +1,2 @@
+<%= javascript_include_tag :defaults, :cache => true %>
+<%= yield :javascript %>
View
5 config/boot.rb
@@ -44,6 +44,7 @@ class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
+ Rails::GemDependency.add_frozen_gem_path
end
end
@@ -67,7 +68,7 @@ def load_rails_gem
class << self
def rubygems_version
- Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
+ Gem::RubyGemsVersion rescue nil
end
def gem_version
@@ -82,7 +83,7 @@ def gem_version
def load_rubygems
require 'rubygems'
- min_version = '1.1.1'
+ min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
View
12 config/database.yml
@@ -2,7 +2,7 @@
development:
adapter: postgresql
- database: <%= PROJECT_NAME %>_development
+ database: moodswings_development
#username: mike
#password:
#host: localhost
@@ -10,7 +10,7 @@ development:
test:
adapter: postgresql
- database: <%= PROJECT_NAME %>_test
+ database: moodswings_test
#username: mike
#password:
#host: localhost
@@ -18,16 +18,16 @@ test:
staging:
adapter: postgresql
- database: <%= PROJECT_NAME %>_staging
- username: <%= PROJECT_NAME %>
+ database: moodswings_staging
+ username: moodswings_
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
production:
adapter: postgresql
- database: <%= PROJECT_NAME %>_production
- username: <%= PROJECT_NAME %>
+ database: moodswings_production
+ username: moodswings_
password: <%= File.read(PASSWORD_FILE).chomp if File.readable? PASSWORD_FILE %>
host: localhost
encoding: utf8
View
6 config/deploy.rb
@@ -29,6 +29,12 @@
task :after_default do
cleanup
end
+
+ before :deploy do
+ if real_revision.empty?
+ raise "The tag, revision, or branch #{revision} does not exist."
+ end
+ end
end
namespace :db do
View
68 config/environment.rb
@@ -1,29 +1,51 @@
-PROJECT_NAME = "moodswings"
+# Be sure to restart your server when you modify this file
-throw "The project's name in environment.rb is blank" if PROJECT_NAME.empty?
-throw "Project name (#{PROJECT_NAME}) must_be_like_this" unless PROJECT_NAME =~ /^[a-z_]*$/
+# Specifies gem version of Rails to use when vendor/rails is not present
+RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
- config.gem 'mislav-will_paginate',
- :lib => 'will_paginate',
- :source => 'http://gems.github.com',
- :version => '~> 2.3.5'
+ # Settings in config/environments/* take precedence over those specified here.
- config.gem "ruby-openid", :lib => 'openid'
+ # Application configuration should go into files in config/initializers
+ # -- all .rb files in that directory are automatically loaded.
+ # See Rails::Configuration for more options.
- config.gem 'thoughtbot-shoulda',
- :lib => 'shoulda',
- :source => 'http://gems.github.com',
- :version => '>= 2.0.5'
- config.gem 'thoughtbot-factory_girl',
- :lib => 'factory_girl',
- :source => 'http://gems.github.com',
- :version => '>= 1.1.3'
- config.gem 'redgreen'
+ # Skip frameworks you're not going to use. To use Rails without a database
+ # you must remove the Active Record framework.
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
+ # Specify gems that this application depends on.
+ config.gem "ruby-openid", :lib => 'openid'
+ config.gem 'RedCloth',
+ :lib => 'redcloth',
+ :version => '>= 4.2.2'
+ config.gem 'mislav-will_paginate',
+ :lib => 'will_paginate',
+ :source => 'http://gems.github.com',
+ :version => '~> 2.3.11'
+ config.gem 'thoughtbot-clearance',
+ :lib => 'clearance',
+ :source => 'http://gems.github.com',
+ :version => '>= 0.8.2'
+ config.gem 'justinfrench-formtastic',
+ :lib => 'formtastic',
+ :source => 'http://gems.github.com',
+ :version => '~> 0.2.1'
+ config.gem 'thoughtbot-paperclip',
+ :lib => 'paperclip',
+ :source => 'http://gems.github.com',
+ :version => '>= 2.3.0'
+ config.gem 'rack',
+ :version => '>= 1.0.0'
+
+ # Only load the plugins named here, in the order given. By default, all plugins
+ # in vendor/plugins are loaded in alphabetical order.
+ # :all can be used as a placeholder for all plugins not explicitly named
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+
# Add the vendor/gems/*/lib directories to the LOAD_PATH
config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
@@ -32,9 +54,11 @@
# Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
config.time_zone = 'UTC'
- SESSION_KEY = "bb64b687bf0cb57289f9161a45f1ebf7"
- config.action_controller.session = {
- :session_key => "_#{PROJECT_NAME}_session",
- :secret => SESSION_KEY
- }
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
+ # like if you have constraints or database-specific column types
+ # config.active_record.schema_format = :sql
+
+ # Activate observers that should always be running
+ # config.active_record.observers = :cacher, :garbage_collector
end
View
50 config/environments/cucumber.rb
@@ -0,0 +1,50 @@
+config.cache_classes = true # This must be true for Cucumber to operate correctly!
+
+# Log error messages when you accidentally call methods on nil.
+config.whiny_nils = true
+
+# Show full error reports and disable caching
+config.action_controller.consider_all_requests_local = true
+config.action_controller.perform_caching = false
+
+# Disable request forgery protection in test environment
+config.action_controller.allow_forgery_protection = false
+
+# Tell Action Mailer not to deliver emails to the real world.
+# The :test delivery method accumulates sent emails in the
+# ActionMailer::Base.deliveries array.
+config.action_mailer.delivery_method = :test
+
+config.gem 'thoughtbot-factory_girl',
+ :lib => 'factory_girl',
+ :source => 'http://gems.github.com',
+ :version => '>= 1.2.0'
+
+# Cucumber and dependencies
+config.gem 'polyglot',
+ :version => '0.2.6',
+ :lib => false
+config.gem 'treetop',
+ :version => '1.2.6',
+ :lib => false
+config.gem 'term-ansicolor',
+ :version => '1.0.3',
+ :lib => false
+config.gem 'diff-lcs',
+ :version => '1.1.2',
+ :lib => false
+config.gem 'builder',
+ :version => '2.1.2',
+ :lib => false
+config.gem 'cucumber',
+ :version => '0.3.11'
+
+# Webrat and dependencies
+# NOTE: don't vendor nokogiri - it's a binary Gem
+config.gem 'nokogiri',
+ :version => '1.3.3',
+ :lib => false
+config.gem 'webrat',
+ :version => '0.4.4'
+
+HOST = 'localhost'
View
2 config/environments/development.rb
@@ -16,4 +16,4 @@
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
-HOST = "localhost"
+HOST = 'localhost'
View
40 config/environments/test.rb
@@ -21,9 +21,41 @@
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
-HOST = "localhost"
+config.gem 'thoughtbot-factory_girl',
+ :lib => 'factory_girl',
+ :source => 'http://gems.github.com',
+ :version => '>= 1.2.2'
+config.gem 'thoughtbot-shoulda',
+ :lib => 'shoulda',
+ :source => 'http://gems.github.com',
+ :version => '>= 2.10.2'
+config.gem 'jtrupiano-timecop',
+ :version => '0.2.1',
+ :source => 'http://gems.github.com',
+ :lib => 'timecop'
+config.gem 'fakeweb',
+ :lib => 'fakeweb',
+ :version => '>= 1.2.5'
+
+# Webrat and dependencies
+# NOTE: don't vendor nokogiri - it's a binary Gem
+config.gem 'nokogiri',
+ :version => '1.3.3',
+ :lib => false
+config.gem 'webrat',
+ :version => '0.4.4'
+
+# At the bottom due to a loading bug in Rails
+config.gem 'jferris-mocha',
+ :version => '0.9.5.0.1241126838',
+ :source => 'http://gems.github.com',
+ :lib => 'mocha'
+
+HOST = 'localhost'
-require 'quietbacktrace'
require 'factory_girl'
-require 'redgreen'
-require 'mocha'
+begin require 'redgreen'; rescue LoadError; end
+
+config.after_initialize do
+ Timecop.travel(Time.now)
+end
View
11 config/initializers/backtrace_silencers.rb
@@ -0,0 +1,11 @@
+SHOULDA_NOISE = %w( shoulda )
+FACTORY_GIRL_NOISE = %w( factory_girl )
+THOUGHTBOT_NOISE = SHOULDA_NOISE + FACTORY_GIRL_NOISE
+
+Rails.backtrace_cleaner.add_silencer do |line|
+ THOUGHTBOT_NOISE.any? { |dir| line.include?(dir) }
+end
+
+# When debugging, uncomment the next line.
+# Rails.backtrace_cleaner.remove_silencers!
+
View
30 config/initializers/bigdecimal-segfault-fix.rb
@@ -0,0 +1,30 @@
+# Copyright (c) 2009 Michael Koziarski <michael@koziarski.com>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+require 'bigdecimal'
+
+alias BigDecimalUnsafe BigDecimal
+
+
+# This fixes CVE-2009-1904 however it removes legitimate functionality that your
+# application may depend on. You are *strongly* advised to upgrade your ruby
+# rather than relying on this fix for an extended period of time.
+
+def BigDecimal(initial, digits=0)
+ if initial.size > 255 || initial =~ /e/i
+ raise "Invalid big Decimal Value"
+ end
+ BigDecimalUnsafe(initial, digits)
+end
+
View
26 config/initializers/errors.rb
@@ -0,0 +1,26 @@
+require 'net/smtp'
+# Example:
+# begin
+# some http call
+# rescue *HTTP_ERRORS => error
+# notify_hoptoad error
+# end
+
+HTTP_ERRORS = [Timeout::Error,
+ Errno::EINVAL,
+ Errno::ECONNRESET,
+ EOFError,
+ Net::HTTPBadResponse,
+ Net::HTTPHeaderSyntaxError,
+ Net::ProtocolError]
+
+SMTP_SERVER_ERRORS = [TimeoutError,
+ IOError,
+ Net::SMTPUnknownError,
+ Net::SMTPServerBusy,
+ Net::SMTPAuthenticationError]
+
+SMTP_CLIENT_ERRORS = [Net::SMTPFatalError,
+ Net::SMTPSyntaxError]
+
+SMTP_ERRORS = SMTP_SERVER_ERRORS + SMTP_CLIENT_ERRORS
View
10 config/initializers/mocks.rb
@@ -0,0 +1,10 @@
+# Rails 2 doesn't like mocks
+
+# This callback will run before every request to a mock in development mode,
+# or before the first server request in production.
+
+Rails.configuration.to_prepare do
+ Dir[File.join(RAILS_ROOT, 'test', 'mocks', RAILS_ENV, '*.rb')].each do |f|
+ load f
+ end
+end
View
19 config/initializers/new_rails_defaults.rb
@@ -0,0 +1,19 @@
+# Be sure to restart your server when you modify this file.
+
+# These settings change the behavior of Rails 2 apps and will be defaults
+# for Rails 3. You can remove this initializer when Rails 3 is released.
+
+if defined?(ActiveRecord)
+ # Include Active Record class name as root for JSON serialized output.
+ ActiveRecord::Base.include_root_in_json = true
+
+ # Store the full class name (including module namespace) in STI type column.
+ ActiveRecord::Base.store_full_sti_class = true
+end
+
+# Use ISO 8601 format for JSON serialized times and dates.
+ActiveSupport.use_standard_json_time_format = true
+
+# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
+# if you're including raw json in an HTML page.
+ActiveSupport.escape_html_entities_in_json = false
View
5 config/initializers/noisy_attr_accessible.rb
@@ -0,0 +1,5 @@
+ActiveRecord::Base.class_eval do
+ def log_protected_attribute_removal(*attributes)
+ raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}"
+ end
+end
View
6 config/initializers/requires.rb
@@ -7,9 +7,3 @@
Dir[File.join(RAILS_ROOT, 'lib', '*.rb')].each do |f|
require f
end
-
-# Rails 2 doesn't like mocks
-
-Dir[File.join(RAILS_ROOT, 'test', 'mocks', RAILS_ENV, '*.rb')].each do |f|
- require f
-end
View
15 config/initializers/session_store.rb
@@ -0,0 +1,15 @@
+# Be sure to restart your server when you modify this file.
+
+# Your secret key for verifying cookie session data integrity.
+# If you change this key, all old sessions will become invalid!
+# Make sure the secret is at least 30 characters and all random,
+# no regular words or you'll be exposed to dictionary attacks.
+ActionController::Base.session = {
+ :key => "_moodswings_session",
+ :secret => "bb64b687bf0cb57289f9161a45f1ebf7"
+}
+
+# Use the database for sessions instead of the cookie-based default,
+# which shouldn't be used to store highly confidential information
+# (create the session table with "rake db:sessions:create")
+# ActionController::Base.session_store = :active_record_store
View
5 config/initializers/time_formats.rb
@@ -1,4 +1,5 @@
-# Example time formats
-{ :short_date => "%x", :long_date => "%a, %b %d, %Y" }.each do |k, v|
+{ :short_date => "%x", # 04/13/10
+ :long_date => "%a, %b %d, %Y" # Tue, Apr 13, 2010
+}.each do |k, v|
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.update(k => v)
end
View
7 config/locales/en.yml
@@ -0,0 +1,7 @@
+# Sample localization file for English.
+# Add more files in this directory for other locales.
+# http://guides.rubyonrails.org/i18n.html
+
+en:
+ hello: "Hello world"
+
View
92 doc/README_FOR_TEMPLATE
@@ -1,5 +1,10 @@
-This is Suspenders, the thoughtbot rails template. To create a new project, checkout this
-repository and run:
+This is Suspenders, the thoughtbot rails template.
+
+To create a new project, first checkout the repository:
+
+ git clone git://github.com/thoughtbot/suspenders.git
+
+Change into the new 'suspenders' directory and run:
./script/create_project projectname
@@ -10,45 +15,64 @@ repo.
When making a change to a project that was created via this template, consider
whether it's a change that should be made across all projects. If so, then
-make the change in this template, and pull it into your project via:
+make the change in suspenders instead of your project. Note: If you don't
+have commit access to suspenders, create a github ticket and we'll review your
+suggestion.
+
+Once that's committed, you can pull into your project to get all the changes
+that have been made in suspenders since your last pull:
git pull suspenders master
-
+
About Suspenders
----------------
Suspenders was created for use at thoughtbot, inc. (http://thoughtbot.com) as a
-baseline application setup, with reasonable default plugins that the majority (if not all)
-of our applications used, as well as best-practice configuration options.
+baseline application setup, with reasonable default plugins that the majority
+(if not all) of our applications used, as well as best-practice configuration
+options.
+
+Suspenders currently includes a version of Rails from the 2.3 stable branch.
+You can determine the changeset with the vendor/rails/REVISION_xxxxx file.
+
+Gems (unpacked in vendor/gems, unless they are compiled gems):
+--------------------------------------------------------------
+
+For record pagination:
-Suspenders currently includes Rails 2.1.1
+ will_paginate (2.3.11)
-Gems (unpacked in vendor/gems):
--------------------------------
+For text formatting:
- will_paginate 2.3.4
- RedCloth 3.0.4
+ RedCloth (4.2.2, not unpacked, this is a compiled gem)
+
+Form builder:
+
+ Formtastic (0.2.1)
+
+File attachments:
+
+ Paperclip (2.3.0)
+
+Basic user auth:
+
+ Clearance (0.7.0 engine)
For testing:
- mocha 0.9.1
- redgreen-1.2.2
- factory_girl 1.1.3
- shoulda 2.0.2
- quietbacktrace 1.1.4
+ jferris-mocha (standard mocha plus test spies)
+ factory_girl (fixture replacement for test data)
+ shoulda (rails test helpers and context framework)
+ timecop (for time sensitive tests)
+ fakeweb (for blocking HTTP calls to third-party services)
Plugins (in vendor/plugins):
----------------------------
hoptoad_notifier
limerick_rake
- mile_marker
- squirrel
-
-For testing:
+ validation_reflection (used by formtastic to find required fields)
- helper_test
-
Initializers (in config/initializers)
-------------------------------------
@@ -75,7 +99,8 @@ Rake Tasks
Rake tasks are contained in the limerick_rake gem.
bootstrap
- Provides rake tasks for loading data into the database. These are used for an initial application dataset needed for production.
+ Provides rake tasks for loading data into the database. These are used for
+ an initial application dataset needed for production.
capistrano
Standard capistrano deployment tasks
@@ -85,23 +110,28 @@ Testing
Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha.
-factory_girl is a fixture replacement library, following the factory pattern. Place your
-factories in test/factories.rb. The fixture directory has been removed, as fixtures are not
-used.
+factory_girl is a fixture replacement library, following the factory pattern.
+Place your factories in test/factories.rb. The fixture directory has been
+removed, as fixtures are not used.
-Shoulda is a pragmatic testing framework for TDD and BDD built on top of Test::Unit. A number of additional
-testing macros are provided in test/shoulda_macros:
+Shoulda is a pragmatic testing framework for TDD and BDD built on top of
+Test::Unit. A number of additional testing macros are provided in
+test/shoulda_macros:
shoulda_have_form
shoulda_paginate_collection
+Timecop is used to freeze the time for the entire test suite. It is frozen to
+the value of Time.now; that is, the time that the tests suite starts running.
+
Deployment
----------
-Deployment is done using capistrano, and deploys to a mongrel cluster, running under Apache.
+Deployment is done using capistrano, and deploys to a mongrel cluster, running
+under Apache.
-Rake tasks are provided for managing git branches which the different environments pull from
-for deploy.
+Rake tasks are provided for managing git branches which the different
+environments pull from for deploy.
To push the git master to git staging branch run:
View
4 features/step_definitions/debug_steps.rb
@@ -0,0 +1,4 @@
+When /^I save and open the page$/ do
+ save_and_open_page
+end
+
View
119 features/step_definitions/webrat_steps.rb
@@ -0,0 +1,119 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
+
+# Commonly used webrat steps
+# http://github.com/brynary/webrat
+
+Given /^I am on (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^I go to (.+)$/ do |page_name|
+ visit path_to(page_name)
+end
+
+When /^I press "([^\"]*)"$/ do |button|
+ click_button(button)
+end
+
+When /^I follow "([^\"]*)"$/ do |link|
+ click_link(link)
+end
+
+When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
+ fill_in(field, :with => value)
+end
+
+When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
+ select(value, :from => field)
+end
+
+# Use this step in conjunction with Rail's datetime_select helper. For example:
+# When I select "December 25, 2008 10:00" as the date and time
+When /^I select "([^\"]*)" as the date and time$/ do |time|
+ select_datetime(time)
+end
+
+# Use this step when using multiple datetime_select helpers on a page or
+# you want to specify which datetime to select. Given the following view:
+# <%= f.label :preferred %><br />
+# <%= f.datetime_select :preferred %>
+# <%= f.label :alternative %><br />
+# <%= f.datetime_select :alternative %>
+# The following steps would fill out the form:
+# When I select "November 23, 2004 11:20" as the "Preferred" date and time
+# And I select "November 25, 2004 10:30" as the "Alternative" date and time
+When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
+ select_datetime(datetime, :from => datetime_label)
+end
+
+# Use this step in conjunction with Rail's time_select helper. For example:
+# When I select "2:20PM" as the time
+# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
+# will convert the 2:20PM to 14:20 and then select it.
+When /^I select "([^\"]*)" as the time$/ do |time|
+ select_time(time)
+end
+
+# Use this step when using multiple time_select helpers on a page or you want to
+# specify the name of the time on the form. For example:
+# When I select "7:30AM" as the "Gym" time
+When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
+ select_time(time, :from => time_label)
+end
+
+# Use this step in conjunction with Rail's date_select helper. For example:
+# When I select "February 20, 1981" as the date
+When /^I select "([^\"]*)" as the date$/ do |date|
+ select_date(date)
+end
+
+# Use this step when using multiple date_select helpers on one page or
+# you want to specify the name of the date on the form. For example:
+# When I select "April 26, 1982" as the "Date of Birth" date
+When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
+ select_date(date, :from => date_label)
+end
+
+When /^I check "([^\"]*)"$/ do |field|
+ check(field)
+end
+
+When /^I uncheck "([^\"]*)"$/ do |field|
+ uncheck(field)
+end
+
+When /^I choose "([^\"]*)"$/ do |field|
+ choose(field)
+end
+
+When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
+ attach_file(field, path)
+end
+
+Then /^I should see "([^\"]*)"$/ do |text|
+ assert_contain text
+end
+
+Then /^I should not see "([^\"]*)"$/ do |text|
+ assert_not_contain text
+end
+
+Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
+ assert_match /#{value}/, field_labeled(field).value
+end
+
+Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
+ assert_no_match /#{value}/, field_labeled(field).value
+end
+
+Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
+ assert field_labeled(label).checked?
+end
+
+Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
+ assert ! field_labeled(label).checked?
+end
+
+Then /^I should be on (.+)$/ do |page_name|
+ assert_equal path_to(page_name), URI.parse(current_url).path
+end
View
24 features/support/env.rb
@@ -0,0 +1,24 @@
+# Sets up the Rails environment for Cucumber
+ENV["RAILS_ENV"] ||= "cucumber"
+require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
+require 'cucumber/rails/world'
+
+# Comment out the next line if you don't want Cucumber Unicode support
+require 'cucumber/formatter/unicode'
+
+# Comment out the next line if you don't want transactions to
+# open/roll back around each scenario
+Cucumber::Rails.use_transactional_fixtures
+
+# Comment out the next line if you want Rails' own error handling
+# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
+Cucumber::Rails.bypass_rescue
+
+require 'webrat'
+
+Webrat.configure do |config|
+ config.mode = :rails
+end
+
+# require 'cucumber/rails/rspec'
+require 'webrat/core/matchers'
View
0 ...houlda-2.0.5/test/rails_root/db/schema.rb → features/support/paperclip/.keep
File renamed without changes.
View
27 features/support/paths.rb
@@ -0,0 +1,27 @@
+module NavigationHelpers
+ # Maps a name to a path. Used by the
+ #
+ # When /^I go to (.+)$/ do |page_name|
+ #
+ # step definition in webrat_steps.rb
+ #
+ def path_to(page_name)
+ case page_name
+
+ when /the homepage/
+ '/'
+
+ # Add more mappings here.
+ # Here is a more fancy example:
+ #
+ # when /^(.*)'s profile page$/i
+ # user_profile_path(User.find_by_login($1))
+
+ else
+ raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
+ "Now, go and add a mapping in #{__FILE__}"
+ end
+ end
+end
+
+World(NavigationHelpers)
View
16 lib/tasks/cucumber.rake
@@ -0,0 +1,16 @@
+$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
+
+begin
+ require 'cucumber/rake/task'
+
+ Cucumber::Rake::Task.new(:features) do |t|
+ t.fork = true
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
+ end
+ task :features => 'db:test:prepare'
+rescue LoadError
+ desc 'Cucumber rake task not available'
+ task :features do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
+ end
+end
View
0 ...rails_root/config/environments/sqlite3.rb → log/.keep
File renamed without changes.
View
144 public/javascripts/controls.js
@@ -1,22 +1,22 @@
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
-// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
-// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
+// (c) 2005-2008 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
+// (c) 2005-2008 Jon Tirsen (http://www.tirsen.com)
// Contributors:
// Richard Livsey
// Rahul Bhargava
// Rob Wills
-//
+//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
-// Autocompleter.Base handles all the autocompletion functionality
+// Autocompleter.Base handles all the autocompletion functionality
// that's independent of the data source for autocompletion. This
// includes drawing the autocompletion menu, observing keyboard
// and mouse events, and similar.
//
-// Specific autocompleters need to provide, at the very least,
+// Specific autocompleters need to provide, at the very least,
// a getUpdatedChoices function that will be invoked every time
-// the text inside the monitored textbox changes. This method
+// the text inside the monitored textbox changes. This method
// should get the text for which to provide autocompletion by
// invoking this.getToken(), NOT by directly accessing
// this.element.value. This is to allow incremental tokenized
@@ -30,23 +30,23 @@
// will incrementally autocomplete with a comma as the token.
// Additionally, ',' in the above example can be replaced with
// a token array, e.g. { tokens: [',', '\n'] } which
-// enables autocompletion on multiple tokens. This is most
-// useful when one of the tokens is \n (a newline), as it
+// enables autocompletion on multiple tokens. This is most
+// useful when one of the tokens is \n (a newline), as it
// allows smart autocompletion after linebreaks.
if(typeof Effect == 'undefined')
throw("controls.js requires including script.aculo.us' effects.js library");
-var Autocompleter = { }
+var Autocompleter = { };
Autocompleter.Base = Class.create({
baseInitialize: function(element, update, options) {
- element = $(element)
- this.element = element;
- this.update = $(update);
- this.hasFocus = false;
- this.changed = false;
- this.active = false;
- this.index = 0;
+ element = $(element);
+ this.element = element;
+ this.update = $(update);
+ this.hasFocus = false;
+ this.changed = false;
+ this.active = false;
+ this.index = 0;
this.entryCount = 0;
this.oldElementValue = this.element.value;
@@ -59,28 +59,28 @@ Autocompleter.Base = Class.create({
this.options.tokens = this.options.tokens || [];
this.options.frequency = this.options.frequency || 0.4;
this.options.minChars = this.options.minChars || 1;
- this.options.onShow = this.options.onShow ||
- function(element, update){
+ this.options.onShow = this.options.onShow ||
+ function(element, update){
if(!update.style.position || update.style.position=='absolute') {
update.style.position = 'absolute';
Position.clone(element, update, {
- setHeight: false,
+ setHeight: false,
offsetTop: element.offsetHeight
});
}
Effect.Appear(update,{duration:0.15});
};
- this.options.onHide = this.options.onHide ||
+ this.options.onHide = this.options.onHide ||
function(element, update){ new Effect.Fade(update,{duration:0.15}) };
- if(typeof(this.options.tokens) == 'string')
+ if(typeof(this.options.tokens) == 'string')
this.options.tokens = new Array(this.options.tokens);
// Force carriage returns as token delimiters anyway
if (!this.options.tokens.include('\n'))
this.options.tokens.push('\n');
this.observer = null;
-
+
this.element.setAttribute('autocomplete','off');
Element.hide(this.update);
@@ -91,10 +91,10 @@ Autocompleter.Base = Class.create({
show: function() {
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
- if(!this.iefix &&
+ if(!this.iefix &&
(Prototype.Browser.IE) &&
(Element.getStyle(this.update, 'position')=='absolute')) {
- new Insertion.After(this.update,
+ new Insertion.After(this.update,
'<iframe id="' + this.update.id + '_iefix" '+
'style="display:none;position:absolute;filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);" ' +
'src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
@@ -102,7 +102,7 @@ Autocompleter.Base = Class.create({
}
if(this.iefix) setTimeout(this.fixIEOverlapping.bind(this), 50);
},
-
+
fixIEOverlapping: function() {
Position.clone(this.update, this.iefix, {setTop:(!this.update.style.height)});
this.iefix.style.zIndex = 1;
@@ -150,15 +150,15 @@ Autocompleter.Base = Class.create({
Event.stop(event);
return;
}
- else
- if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
+ else
+ if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
(Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
this.changed = true;
this.hasFocus = true;
if(this.observer) clearTimeout(this.observer);
- this.observer =
+ this.observer =
setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
},
@@ -170,35 +170,35 @@ Autocompleter.Base = Class.create({
onHover: function(event) {
var element = Event.findElement(event, 'LI');
- if(this.index != element.autocompleteIndex)
+ if(this.index != element.autocompleteIndex)
{
this.index = element.autocompleteIndex;
this.render();
}
Event.stop(event);
},
-
+
onClick: function(event) {
var element = Event.findElement(event, 'LI');
this.index = element.autocompleteIndex;
this.selectEntry();
this.hide();
},
-
+
onBlur: function(event) {
// needed to make click events working
setTimeout(this.hide.bind(this), 250);
this.hasFocus = false;
- this.active = false;
- },
-
+ this.active = false;
+ },
+
render: function() {
if(this.entryCount > 0) {
for (var i = 0; i < this.entryCount; i++)
- this.index==i ?
- Element.addClassName(this.getEntry(i),"selected") :
+ this.index==i ?
+ Element.addClassName(this.getEntry(i),"selected") :
Element.removeClassName(this.getEntry(i),"selected");
- if(this.hasFocus) {
+ if(this.hasFocus) {
this.show();
this.active = true;
}
@@ -207,27 +207,27 @@ Autocompleter.Base = Class.create({
this.hide();
}
},
-
+
markPrevious: function() {
- if(this.index > 0) this.index--
+ if(this.index > 0) this.index--;
else this.index = this.entryCount-1;
this.getEntry(this.index).scrollIntoView(true);
},
-
+
markNext: function() {
- if(this.index < this.entryCount-1) this.index++
+ if(this.index < this.entryCount-1) this.index++;
else this.index = 0;
this.getEntry(this.index).scrollIntoView(false);
},
-
+
getEntry: function(index) {
return this.update.firstChild.childNodes[index];
},
-
+
getCurrentEntry: function() {
return this.getEntry(this.index);
},
-
+
selectEntry: function() {
this.active = false;
this.updateElement(this.getCurrentEntry());
@@ -244,7 +244,7 @@ Autocompleter.Base = Class.create({
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
} else
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
-
+
var bounds = this.getTokenBounds();
if (bounds[0] != -1) {
var newValue = this.element.value.substr(0, bounds[0]);
@@ -257,7 +257,7 @@ Autocompleter.Base = Class.create({
}
this.oldElementValue = this.element.value;
this.element.focus();
-
+
if (this.options.afterUpdateElement)
this.options.afterUpdateElement(this.element, selectedElement);
},
@@ -269,20 +269,20 @@ Autocompleter.Base = Class.create({
Element.cleanWhitespace(this.update.down());
if(this.update.firstChild && this.update.down().childNodes) {
- this.entryCount =
+ this.entryCount =
this.update.down().childNodes.length;
for (var i = 0; i < this.entryCount; i++) {
var entry = this.getEntry(i);
entry.autocompleteIndex = i;
this.addObservers(entry);
}
- } else {
+ } else {
this.entryCount = 0;
}
this.stopIndicator();
this.index = 0;
-
+
if(this.entryCount==1 && this.options.autoSelect) {
this.selectEntry();
this.hide();
@@ -298,7 +298,7 @@ Autocompleter.Base = Class.create({
},
onObserverEvent: function() {
- this.changed = false;
+ this.changed = false;
this.tokenBounds = null;
if(this.getToken().length>=this.options.minChars) {
this.getUpdatedChoices();
@@ -351,16 +351,16 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
getUpdatedChoices: function() {
this.startIndicator();
-
- var entry = encodeURIComponent(this.options.paramName) + '=' +
+
+ var entry = encodeURIComponent(this.options.paramName) + '=' +
encodeURIComponent(this.getToken());
this.options.parameters = this.options.callback ?
this.options.callback(this.element, entry) : entry;
- if(this.options.defaultParams)
+ if(this.options.defaultParams)
this.options.parameters += '&' + this.options.defaultParams;
-
+
new Ajax.Request(this.url, this.options);
},
@@ -382,7 +382,7 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
// - choices - How many autocompletion choices to offer
//
// - partialSearch - If false, the autocompleter will match entered
-// text only at the beginning of strings in the
+// text only at the beginning of strings in the
// autocomplete array. Defaults to true, which will
// match text at the beginning of any *word* in the
// strings in the autocomplete array. If you want to
@@ -399,7 +399,7 @@ Ajax.Autocompleter = Class.create(Autocompleter.Base, {
// - ignoreCase - Whether to ignore case when autocompleting.
// Defaults to true.
//
-// It's possible to pass in a custom function as the 'selector'
+// It's possible to pass in a custom function as the 'selector'
// option, if you prefer to write your own autocompletion logic.
// In that case, the other options above will not apply unless
// you support them.
@@ -427,20 +427,20 @@ Autocompleter.Local = Class.create(Autocompleter.Base, {
var entry = instance.getToken();
var count = 0;
- for (var i = 0; i < instance.options.array.length &&
- ret.length < instance.options.choices ; i++) {
+ for (var i = 0; i < instance.options.array.length &&
+ ret.length < instance.options.choices ; i++) {
var elem = instance.options.array[i];
- var foundPos = instance.options.ignoreCase ?
- elem.toLowerCase().indexOf(entry.toLowerCase()) :
+ var foundPos = instance.options.ignoreCase ?
+ elem.toLowerCase().indexOf(entry.toLowerCase()) :
elem.indexOf(entry);
while (foundPos != -1) {
- if (foundPos == 0 && elem.length != entry.length) {
- ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
+ if (foundPos == 0 && elem.length != entry.length) {
+ ret.push("<li><strong>" + elem.substr(0, entry.length) + "</strong>" +
elem.substr(entry.length) + "</li>");
break;
- } else if (entry.length >= instance.options.partialChars &&
+ } else if (entry.length >= instance.options.partialChars &&
instance.options.partialSearch && foundPos != -1) {
if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
@@ -450,14 +450,14 @@ Autocompleter.Local = Class.create(Autocompleter.Base, {
}
}
- foundPos = instance.options.ignoreCase ?
- elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
+ foundPos = instance.options.ignoreCase ?
+ elem.toLowerCase().indexOf(entry.toLowerCase(), foundPos + 1) :
elem.indexOf(entry, foundPos + 1);
}
}
if (partial.length)
- ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
+ ret = ret.concat(partial.slice(0, instance.options.choices - ret.length));
return "<ul>" + ret.join('') + "</ul>";
}
}, options || { });
@@ -474,7 +474,7 @@ Field.scrollFreeActivate = function(field) {
setTimeout(function() {
Field.activate(field);
}, 1);
-}
+};
Ajax.InPlaceEditor = Class.create({
initialize: function(element, url, options) {
@@ -604,7 +604,7 @@ Ajax.InPlaceEditor = Class.create({
this.triggerCallback('onEnterHover');
},
getText: function() {
- return this.element.innerHTML;
+ return this.element.innerHTML.unescapeHTML();
},
handleAJAXFailure: function(transport) {
this.triggerCallback('onFailure', transport);
@@ -780,7 +780,7 @@ Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
onSuccess: function(transport) {
var js = transport.responseText.strip();
if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
- throw 'Server returned an invalid collection representation.';
+ throw('Server returned an invalid collection representation.');
this._collection = eval(js);
this.checkForExternalText();
}.bind(this),
@@ -937,7 +937,7 @@ Ajax.InPlaceCollectionEditor.DefaultOptions = {
loadingCollectionText: 'Loading options...'
};
-// Delayed observer, like Form.Element.Observer,
+// Delayed observer, like Form.Element.Observer,
// but waits for delay after last key input
// Ideal for live-search fields
@@ -947,7 +947,7 @@ Form.Element.DelayedObserver = Class.create({
this.element = $(element);
this.callback = callback;
this.timer = null;
- this.lastValue = $F(this.element);
+ this.lastValue = $F(this.element);
Event.observe(this.element,'keyup',this.delayedListener.bindAsEventListener(this));
},
delayedListener: function(event) {
@@ -960,4 +960,4 @@ Form.Element.DelayedObserver = Class.create({
this.timer = null;
this.callback(this.element, $F(this.element));
}
-});
+});
View
329 public/javascripts/dragdrop.js
@@ -1,6 +1,6 @@
// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
-// (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
-//
+// (c) 2005-2008 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
+//
// script.aculo.us is freely distributable under the terms of an MIT-style license.
// For details, see the script.aculo.us web site: http://script.aculo.us/
@@ -32,7 +32,7 @@ var Droppables = {
options._containers.push($(containment));
}
}
-
+
if(options.accept) options.accept = [options.accept].flatten();
Element.makePositioned(element); // fix IE
@@ -40,34 +40,34 @@ var Droppables = {
this.drops.push(options);
},
-
+
findDeepestChild: function(drops) {
deepest = drops[0];
-
+
for (i = 1; i < drops.length; ++i)
if (Element.isParent(drops[i].element, deepest.element))
deepest = drops[i];
-
+
return deepest;
},
isContained: function(element, drop) {
var containmentNode;
if(drop.tree) {
- containmentNode = element.treeNode;
+ containmentNode = element.treeNode;
} else {
containmentNode = element.parentNode;
}
return drop._containers.detect(function(c) { return containmentNode == c });
},
-
+
isAffected: function(point, element, drop) {
return (
(drop.element!=element) &&
((!drop._containers) ||
this.isContained(element, drop)) &&
((!drop.accept) ||
- (Element.classNames(element).detect(
+ (Element.classNames(element).detect(
function(v) { return drop.accept.include(v) } ) )) &&
Position.within(drop.element, point[0], point[1]) );
},
@@ -87,12 +87,12 @@ var Droppables = {
show: function(point, element) {
if(!this.drops.length) return;
var drop, affected = [];
-
+
this.drops.each( function(drop) {
if(Droppables.isAffected(point, element, drop))
affected.push(drop);
});
-
+
if(affected.length>0)
drop = Droppables.findDeepestChild(affected);
@@ -101,7 +101,7 @@ var Droppables = {
Position.within(drop.element, point[0], point[1]);
if(drop.onHover)
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
-
+
if (drop != this.last_active) Droppables.activate(drop);
}
},
@@ -112,8 +112,8 @@ var Droppables = {
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
if (this.last_active.onDrop) {
- this.last_active.onDrop(element, this.last_active.element, event);
- return true;
+ this.last_active.onDrop(element, this.last_active.element, event);
+ return true;
}
},
@@ -121,25 +121,25 @@ var Droppables = {
if(this.last_active)
this.deactivate(this.last_active);
}
-}
+};
var Draggables = {
drags: [],
observers: [],
-
+
register: function(draggable) {
if(this.drags.length == 0) {
this.eventMouseUp = this.endDrag.bindAsEventListener(this);
this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
this.eventKeypress = this.keyPress.bindAsEventListener(this);
-
+
Event.observe(document, "mouseup", this.eventMouseUp);
Event.observe(document, "mousemove", this.eventMouseMove);
Event.observe(document, "keypress", this.eventKeypress);
}
this.drags.push(draggable);
},
-
+
unregister: function(draggable) {
this.drags = this.drags.reject(function(d) { return d==draggable });
if(this.drags.length == 0) {
@@ -148,24 +148,24 @@ var Draggables = {
Event.stopObserving(document, "keypress", this.eventKeypress);
}
},
-
+
activate: function(draggable) {
- if(draggable.options.delay) {
- this._timeout = setTimeout(function() {
- Draggables._timeout = null;
- window.focus();
- Draggables.activeDraggable = draggable;
- }.bind(this), draggable.options.delay);
+ if(draggable.options.delay) {
+ this._timeout = setTimeout(function() {
+ Draggables._timeout = null;
+ window.focus();
+ Draggables.activeDraggable = draggable;
+ }.bind(this), draggable.options.delay);
} else {
window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
this.activeDraggable = draggable;
}
},
-
+
deactivate: function() {
this.activeDraggable = null;
},
-
+
updateDrag: function(event) {
if(!this.activeDraggable) return;
var pointer = [Event.pointerX(event), Event.pointerY(event)];
@@ -173,36 +173,36 @@ var Draggables = {
// the same coordinates, prevent needless redrawing (moz bug?)
if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
this._lastPointer = pointer;
-
+
this.activeDraggable.updateDrag(event, pointer);
},
-
+
endDrag: function(event) {
- if(this._timeout) {
- clearTimeout(this._timeout);
- this._timeout = null;
+ if(this._timeout) {
+ clearTimeout(this._timeout);
+ this._timeout = null;
}
if(!this.activeDraggable) return;
this._lastPointer = null;
this.activeDraggable.endDrag(event);
this.activeDraggable = null;
},
-
+
keyPress: function(event) {
if(this.activeDraggable)
this.activeDraggable.keyPress(event);
},
-
+
addObserver: function(observer) {
this.observers.push(observer);
this._cacheObserverCallbacks();
},
-
+
removeObserver: function(element) { // element instead of observer fixes mem leaks
this.observers = this.observers.reject( function(o) { return o.element==element });
this._cacheObserverCallbacks();
},
-
+
notify: function(eventName, draggable, event) { // 'onStart', 'onEnd', 'onDrag'
if(this[eventName+'Count'] > 0)
this.observers.each( function(o) {
@@ -210,7 +210,7 @@ var Draggables = {
});
if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
},
-
+
_cacheObserverCallbacks: function() {
['onStart','onEnd','onDrag'].each( function(eventName) {
Draggables[eventName+'Count'] = Draggables.observers.select(
@@ -218,7 +218,7 @@ var Draggables = {
).length;
});
}
-}
+};
/*--------------------------------------------------------------------------*/
@@ -234,12 +234,12 @@ var Draggable = Class.create({
},
endeffect: function(element) {
var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
- new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
+ new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
queue: {scope:'_draggable', position:'end'},
- afterFinish: function(){
- Draggable._dragging[element] = false
+ afterFinish: function(){
+ Draggable._dragging[element] = false
}
- });
+ });
},
zindex: 1000,
revert: false,
@@ -250,57 +250,57 @@ var Draggable = Class.create({
snap: false, // false, or xy or [x,y] or function(x,y){ return [x,y] }
delay: 0
};
-
+
if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
Object.extend(defaults, {
starteffect: function(element) {
element._opacity = Element.getOpacity(element);
Draggable._dragging[element] = true;
- new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
+ new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
}
});
-
+
var options = Object.extend(defaults, arguments[1] || { });
this.element = $(element);
-
+
if(options.handle && Object.isString(options.handle))
this.handle = this.element.down('.'+options.handle, 0);
-
+
if(!this.handle) this.handle = $(options.handle);
if(!this.handle) this.handle = this.element;
-
+
if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
options.scroll = $(options.scroll);
this._isScrollChild = Element.childOf(this.element, options.scroll);
}
- Element.makePositioned(this.element); // fix IE
+ Element.makePositioned(this.element); // fix IE
this.options = options;
- this.dragging = false;
+ this.dragging = false;
this.eventMouseDown = this.initDrag.bindAsEventListener(this);
Event.observe(this.handle, "mousedown", this.eventMouseDown);
-
+
Draggables.register(this);
},
-
+
destroy: function() {
Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
Draggables.unregister(this);
},
-
+
currentDelta: function() {
return([
parseInt(Element.getStyle(this.element,'left') || '0'),
parseInt(Element.getStyle(this.element,'top') || '0')]);
},
-
+
initDrag: function(event) {
if(!Object.isUndefined(Draggable._dragging[this.element]) &&
Draggable._dragging[this.element]) return;
- if(Event.isLeftClick(event)) {
+ if(Event.isLeftClick(event)) {
// abort on form elements, fixes a Firefox issue
var src = Event.element(event);
if((tag_name = src.tagName.toUpperCase()) && (
@@ -309,34 +309,34 @@ var Draggable = Class.create({
tag_name=='OPTION' ||
tag_name=='BUTTON' ||
tag_name=='TEXTAREA')) return;
-
+
var pointer = [Event.pointerX(event), Event.pointerY(event)];
var pos = Position.cumulativeOffset(this.element);
this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
-
+
Draggables.activate(this);
Event.stop(event);
}
},
-
+
startDrag: function(event) {
this.dragging = true;
if(!this.delta)
this.delta = this.currentDelta();
-
+
if(this.options.zindex) {
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
this.element.style.zIndex = this.options.zindex;
}
-
+
if(this.options.ghosting) {
this._clone = this.element.cloneNode(true);
- this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
- if (!this.element._originallyAbsolute)
+ this._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
+ if (!this._originallyAbsolute)
Position.absolutize(this.element);
this.element.parentNode.insertBefore(this._clone, this.element);
}
-
+
if(this.options.scroll) {
if (this.options.scroll == window) {
var where = this._getWindowScroll(this.options.scroll);
@@ -347,28 +347,28 @@ var Draggable = Class.create({
this.originalScrollTop = this.options.scroll.scrollTop;
}
}
-
+
Draggables.notify('onStart', this, event);
-
+
if(this.options.starteffect) this.options.starteffect(this.element);
},
-
+
updateDrag: function(event, pointer) {
if(!this.dragging) this.startDrag(event);
-
+
if(!this.options.quiet){
Position.prepare();
Droppables.show(pointer, this.element);
}
-
+
Draggables.notify('onDrag', this, event);
-
+
this.draw(pointer);
if(this.options.change) this.options.change(this);
-
+
if(this.options.scroll) {
this.stopScrolling();
-
+
var p;
if (this.options.scroll == window) {
with(this._getWindowScroll(this.options.scroll)) { p = [ left, top, left+width, top+height ]; }
@@ -386,16 +386,16 @@ var Draggable = Class.create({
if(pointer[1] > (p[3]-this.options.scrollSensitivity)) speed[1] = pointer[1]-(p[3]-this.options.scrollSensitivity);
this.startScrolling(speed);
}
-
+
// fix AppleWebKit rendering
if(Prototype.Browser.WebKit) window.scrollBy(0,0);
-
+
Event.stop(event);
},
-
+
finishDrag: function(event, success) {
this.dragging = false;
-
+
if(this.options.quiet){
Position.prepare();
var pointer = [Event.pointerX(event), Event.pointerY(event)];
@@ -403,24 +403,24 @@ var Draggable = Class.create({
}
if(this.options.ghosting) {
- if (!this.element._originallyAbsolute)
+ if (!this._originallyAbsolute)
Position.relativize(this.element);
- delete this.element._originallyAbsolute;
+ delete this._originallyAbsolute;
Element.remove(this._clone);
this._clone = null;
}
- var dropped = false;
- if(success) {
- dropped = Droppables.fire(event, this.element);
- if (!dropped) dropped = false;
+ var dropped = false;
+ if(success) {
+ dropped = Droppables.fire(event, this.element);
+ if (!dropped) dropped = false;
}
if(dropped && this.options.onDropped) this.options.onDropped(this.element);
Draggables.notify('onEnd', this, event);
var revert = this.options.revert;
if(revert && Object.isFunction(revert)) revert = revert(this.element);
-
+
var d = this.currentDelta();
if(revert && this.options.reverteffect) {
if (dropped == 0 || revert != 'failure')
@@ -433,67 +433,67 @@ var Draggable = Class.create({
if(this.options.zindex)
this.element.style.zIndex = this.originalZ;
- if(this.options.endeffect)
+ if(this.options.endeffect)
this.options.endeffect(this.element);
-
+
Draggables.deactivate(this);
Droppables.reset();
},
-
+
keyPress: function(event) {
if(event.keyCode!=Event.KEY_ESC) return;
this.finishDrag(event, false);
Event.stop(event);
},
-
+
endDrag: function(event) {
if(!this.dragging) return;
this.stopScrolling();
this.finishDrag(event, true);
Event.stop(event);
},
-
+
draw: function(point) {
var pos = Position.cumulativeOffset(this.element);
if(this.options.ghosting) {
var r = Position.realOffset(this.element);
pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
}
-
+
var d = this.currentDelta();
pos[0] -= d[0]; pos[1] -= d[1];
-
+
if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
}
-
- var p = [0,1].map(function(i){
- return (point[i]-pos[i]-this.offset[i])
+
+ var p = [0,1].map(function(i){
+ return (point[i]-pos[i]-this.offset[i])
}.bind(this));
-
+
if(this.options.snap) {
if(Object.isFunction(this.options.snap)) {
p = this.options.snap(p[0],p[1],this);
} else {
if(Object.isArray(this.options.snap)) {
p = p.map( function(v, i) {
- return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
+ return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this));
} else {
p = p.map( function(v) {
- return (v/this.options.snap).round()*this.options.snap }.bind(this))
+ return (v/this.options.snap).round()*this.options.snap }.bind(this));
}
}}
-
+
var style = this.element.style;
if((!this.options.constraint) || (this.options.constraint=='horizontal'))
style.left = p[0] + "px";
if((!this.options.constraint) || (this.options.constraint=='vertical'))
style.top = p[1] + "px";
-
+
if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
},
-
+
stopScrolling: function() {
if(this.scrollInterval) {
clearInterval(this.scrollInterval);
@@ -501,14 +501,14 @@ var Draggable = Class.create({
Draggables._lastScrollPointer = null;
}
},
-
+
startScrolling: function(speed) {
if(!(speed[0] || speed[1])) return;
this.scrollSpeed = [speed[0]*this.options.scrollSpeed,speed[1]*this.options.scrollSpeed];
this.lastScrolled = new Date();
this.scrollInterval = setInterval(this.scroll.bind(this), 10);
},
-
+
scroll: function() {
var current = new Date();
var delta = current - this.lastScrolled;
@@ -524,7 +524,7 @@ var Draggable = Class.create({
this.options.scroll.scrollLeft += this.scrollSpeed[0] * delta / 1000;
this.options.scroll.scrollTop += this.scrollSpeed[1] * delta / 1000;
}
-
+
Position.prepare();
Droppables.show(Draggables._lastPointer, this.element);
Draggables.notify('onDrag', this);
@@ -538,10 +538,10 @@ var Draggable = Class.create({
Draggables._lastScrollPointer[1] = 0;
this.draw(Draggables._lastScrollPointer);
}
-
+
if(this.options.change) this.options.change(this);
},
-
+
_getWindowScroll: function(w) {
var T, L, W, H;
with (w.document) {
@@ -560,7 +560,7 @@ var Draggable = Class.create({
H = documentElement.clientHeight;
} else {
W = body.offsetWidth;
- H = body.offsetHeight
+ H = body.offsetHeight;
}
}
return { top: T, left: L, width: W, height: H };
@@ -577,11 +577,11 @@ var SortableObserver = Class.create({
this.observer = observer;
this.lastValue = Sortable.serialize(this.element);
},
-
+
onStart: function() {
this.lastValue = Sortable.serialize(this.element);
},
-
+
onEnd: function() {
Sortable.unmark();
if(this.lastValue != Sortable.serialize(this.element))
@@ -591,11 +591,11 @@ var SortableObserver = Class.create({
var Sortable = {
SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
-
+
sortables: { },
-
+
_findRootElement: function(element) {
- while (element.tagName.toUpperCase() != "BODY") {
+ while (element.tagName.toUpperCase() != "BODY") {
if(element.id && Sortable.sortables[element.id]) return element;
element = element.parentNode;
}
@@ -606,22 +606,23 @@ var Sortable = {
if(!element) return;
return Sortable.sortables[element.id];
},
-
+
destroy: function(element){
- var s = Sortable.options(element);
-
+ element = $(element);
+ var s =