Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rails --> Padrino.

Since it is a single page mini-site, using Rails seems to be overkill. Also changed:

MySQL --> SQLite3.
ERb --> Slim.

And with some other minor changes.
  • Loading branch information...
commit a1d4a9ab17e912f632d21ec3c79fde1fc125f6d0 1 parent 5b4c07e
@fredwu authored
Showing with 589 additions and 10,219 deletions.
  1. +8 −0 .components
  2. +13 −26 Gemfile
  3. +57 −37 Gemfile.lock
  4. +0 −21 README.rdoc
  5. +0 −7 Rakefile
  6. +37 −0 app/app.rb
  7. +0 −5 app/controllers/accounts_controller.rb
  8. +0 −3  app/controllers/application_controller.rb
  9. +7 −0 app/controllers/heroes.rb
  10. +0 −22 app/helpers/accounts_helper.rb
  11. +0 −23 app/helpers/application_helper.rb
  12. +18 −0 app/helpers/heroes_helper.rb
  13. +0 −54 app/models/account.rb
  14. +1 −1  app/models/book.rb
  15. +46 −0 app/models/hero.rb
  16. +1 −1  app/models/name.rb
  17. +1 −1  app/models/nick.rb
  18. +1 −1  app/models/portrait.rb
  19. +1 −1  app/models/service.rb
  20. +1 −1  app/models/site.rb
  21. +0 −79 app/views/accounts/_account.html.erb
  22. +0 −1  app/views/accounts/_name.html.erb
  23. +0 −3  app/views/accounts/_portrait.html.erb
  24. +0 −3  app/views/accounts/_service.html.erb
  25. +0 −1  app/views/accounts/_site.html.erb
  26. +0 −5 app/views/accounts/index.html.erb
  27. +1 −0  app/views/heroes/_book.html.slim
  28. +10 −0 app/views/heroes/_hero.html.slim
  29. +1 −0  app/views/heroes/_name.html.slim
  30. +1 −0  app/views/heroes/_nick.html.slim
  31. +1 −0  app/views/heroes/_portrait.html.slim
  32. +1 −0  app/views/heroes/_service.html.slim
  33. +1 −0  app/views/heroes/_site.html.slim
  34. +3 −0  app/views/heroes/index.html.slim
  35. +0 −15 app/views/layouts/application.html.erb
  36. +20 −0 app/views/layouts/application.html.slim
  37. +2 −4 config.ru
  38. +0 −42 config/application.rb
  39. +25 −0 config/apps.rb
  40. +26 −9 config/boot.rb
  41. +49 −0 config/database.rb
  42. +0 −22 config/database.yml
  43. +0 −5 config/environment.rb
  44. +0 −26 config/environments/development.rb
  45. +0 −49 config/environments/production.rb
  46. +0 −35 config/environments/test.rb
  47. +0 −7 config/initializers/backtrace_silencers.rb
  48. +0 −10 config/initializers/inflections.rb
  49. +0 −5 config/initializers/mime_types.rb
  50. +0 −7 config/initializers/secret_token.rb
  51. +0 −8 config/initializers/session_store.rb
  52. +0 −5 config/locales/en.yml
  53. +0 −4 config/routes.rb
  54. +12 −0 db/migrate/001_create_heros.rb
  55. +2 −3 db/migrate/{20110101001709_create_books.rb → 002_create_books.rb}
  56. +1 −2  db/migrate/{20110101001535_create_names.rb → 003_create_names.rb}
  57. +1 −2  db/migrate/{20110101002342_create_nicks.rb → 004_create_nicks.rb}
  58. +1 −2  db/migrate/{20110101001654_create_portraits.rb → 005_create_portraits.rb}
  59. +1 −2  db/migrate/{20110101001639_create_services.rb → 006_create_services.rb}
  60. +1 −2  db/migrate/{20110101001612_create_sites.rb → 007_create_sites.rb}
  61. +0 −13 db/migrate/20110101001326_create_accounts.rb
  62. BIN  db/rubycommitters_development.db
  63. BIN  db/rubycommitters_test.db
  64. +11 −11 db/schema.rb
  65. +0 −7 db/seeds.rb
  66. +0 −2  doc/README_FOR_APP
  67. 0  lib/tasks/.gitkeep
  68. +3 −4 lib/tasks/import.rake
  69. +0 −26 public/404.html
  70. +0 −26 public/422.html
  71. +0 −26 public/500.html
  72. BIN  public/images/rails.png
  73. +48 −0 public/index.html
  74. +0 −2  public/javascripts/application.js
  75. +0 −965 public/javascripts/controls.js
  76. +0 −974 public/javascripts/dragdrop.js
  77. +0 −1,123 public/javascripts/effects.js
  78. +167 −0 public/javascripts/jquery.js
  79. +0 −6,001 public/javascripts/prototype.js
  80. +0 −175 public/javascripts/rails.js
  81. +0 −5 public/robots.txt
  82. 0  public/stylesheets/.gitkeep
  83. +8 −0 public/stylesheets/base.css
  84. +0 −7 public/stylesheets/site.css
  85. +0 −6 script/rails
  86. +0 −3  test/fixtures/accounts.yml
  87. +0 −19 test/fixtures/books.yml
  88. +0 −11 test/fixtures/names.yml
  89. +0 −4 test/fixtures/nicks.yml
  90. +0 −3  test/fixtures/portraits.yml
  91. +0 −24 test/fixtures/services.yml
  92. +0 −6 test/fixtures/sites.yml
  93. +0 −11 test/functional/accounts_controller_test.rb
  94. +0 −9 test/performance/browsing_test.rb
  95. +0 −13 test/test_helper.rb
  96. +0 −124 test/unit/account_test.rb
  97. +0 −4 test/unit/helpers/accounts_helper_test.rb
  98. +0 −53 test/unit/ruby-committers.yml
  99. 0  vendor/plugins/.gitkeep
View
8 .components
@@ -0,0 +1,8 @@
+---
+:stylesheet: none
+:test: none
+:renderer: slim
+:script: jquery
+:mock: none
+:orm: activerecord
+
View
39 Gemfile
@@ -1,31 +1,18 @@
-source 'http://rubygems.org'
+source :rubygems
-gem 'rails', '3.0.3'
-
-# Bundle edge Rails instead:
-# gem 'rails', :git => 'git://github.com/rails/rails.git'
+# Project requirements
+gem 'rake'
+gem 'rack-flash'
+gem 'thin' # or mongrel
+# Component requirements
+gem 'slim', '>= 0.8.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
+gem 'activerecord', '~> 3.0.3', :require => 'active_record'
-# Use unicorn as the web server
-# gem 'unicorn'
-
-# Deploy with Capistrano
-# gem 'capistrano'
-
-# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
-# gem 'ruby-debug'
-# gem 'ruby-debug19'
-
-# Bundle the extra gems:
-# gem 'bj'
-# gem 'nokogiri'
-# gem 'sqlite3-ruby', :require => 'sqlite3'
-# gem 'aws-s3', :require => 'aws/s3'
+# Test requirements
+gem 'rack-test', :group => :test, :require => 'rack/test'
-# Bundle gems for the local environment. Make sure to
-# put test-only gems in this group so their generators
-# and rake tasks are available in development mode:
-# group :development, :test do
-# gem 'webrat'
-# end
+# Padrino
+gem 'sinatra', '1.1.0', :require => 'sinatra/base'
+gem 'padrino', '0.9.19'
View
94 Gemfile.lock
@@ -1,20 +1,6 @@
GEM
remote: http://rubygems.org/
specs:
- abstract (1.0.0)
- actionmailer (3.0.3)
- actionpack (= 3.0.3)
- mail (~> 2.2.9)
- actionpack (3.0.3)
- activemodel (= 3.0.3)
- activesupport (= 3.0.3)
- builder (~> 2.1.2)
- erubis (~> 2.6.6)
- i18n (~> 0.4)
- rack (~> 1.2.1)
- rack-mount (~> 0.6.13)
- rack-test (~> 0.5.6)
- tzinfo (~> 0.3.23)
activemodel (3.0.3)
activesupport (= 3.0.3)
builder (~> 2.1.2)
@@ -24,50 +10,84 @@ GEM
activesupport (= 3.0.3)
arel (~> 2.0.2)
tzinfo (~> 0.3.23)
- activeresource (3.0.3)
- activemodel (= 3.0.3)
- activesupport (= 3.0.3)
activesupport (3.0.3)
arel (2.0.6)
builder (2.1.2)
- erubis (2.6.6)
- abstract (>= 1.0.0)
+ daemons (1.1.0)
+ eventmachine (0.12.10)
+ git (1.2.5)
+ http_router (0.4.1)
+ rack (>= 1.0.0)
+ url_mount (~> 0.2.1)
i18n (0.5.0)
- mail (2.2.13)
+ mail (2.2.14)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
+ padrino (0.9.19)
+ padrino-admin (= 0.9.19)
+ padrino-core (= 0.9.19)
+ padrino-gen (= 0.9.19)
+ padrino-helpers (= 0.9.19)
+ padrino-mailer (= 0.9.19)
+ padrino-admin (0.9.19)
+ padrino-core (= 0.9.19)
+ padrino-helpers (= 0.9.19)
+ padrino-core (0.9.19)
+ activesupport (>= 3.0.0)
+ http_router (~> 0.4.0)
+ sinatra (>= 1.1.0)
+ thor (>= 0.14.3)
+ tzinfo
+ padrino-gen (0.9.19)
+ bundler (>= 1.0.2)
+ git
+ padrino-core (= 0.9.19)
+ padrino-helpers (0.9.19)
+ i18n (>= 0.4.1)
+ padrino-core (= 0.9.19)
+ padrino-mailer (0.9.19)
+ mail (>= 2.2.0)
+ padrino-core (= 0.9.19)
polyglot (0.3.1)
rack (1.2.1)
- rack-mount (0.6.13)
- rack (>= 1.0.0)
- rack-test (0.5.6)
+ rack-flash (0.1.1)
+ rack
+ rack-test (0.5.7)
rack (>= 1.0)
- rails (3.0.3)
- actionmailer (= 3.0.3)
- actionpack (= 3.0.3)
- activerecord (= 3.0.3)
- activeresource (= 3.0.3)
- activesupport (= 3.0.3)
- bundler (~> 1.0)
- railties (= 3.0.3)
- railties (3.0.3)
- actionpack (= 3.0.3)
- activesupport (= 3.0.3)
- rake (>= 0.8.7)
- thor (~> 0.14.4)
rake (0.8.7)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
+ slim (0.8.3)
+ temple (~> 0.1.6)
+ tilt (~> 1.1)
sqlite3-ruby (1.3.2)
+ temple (0.1.6)
+ thin (1.2.7)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
thor (0.14.6)
+ tilt (1.2.1)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
+ url_mount (0.2.1)
+ rack
PLATFORMS
ruby
DEPENDENCIES
- rails (= 3.0.3)
+ activerecord (~> 3.0.3)
+ padrino (= 0.9.19)
+ rack-flash
+ rack-test
+ rake
+ sinatra (= 1.1.0)
+ slim (>= 0.8.3)
sqlite3-ruby
+ thin
View
21 README.rdoc
@@ -1,21 +0,0 @@
-= rubycommitters.org
-
-This is the source code for the rubycommitters.org website.
-
-== Hacking
-
-First clone the repo:
-
- $ git clone git://github.com/tenderlove/rubycommitters.org.git
- $ cd rubycommitters.org
-
-Then import committer data
-
- $ bundle install
- $ rake import
-
-Start your server
-
- $ ruby script/rails server
-
-Have fun hacking!
View
7 Rakefile
@@ -1,7 +0,0 @@
-# Add your own tasks in files placed in lib/tasks ending in .rake,
-# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
-
-require File.expand_path('../config/application', __FILE__)
-require 'rake'
-
-Rubycommitters::Application.load_tasks
View
37 app/app.rb
@@ -0,0 +1,37 @@
+class RubyCommitters < Padrino::Application
+ register Padrino::Mailer
+ register Padrino::Helpers
+
+ Slim::Engine.set_default_options :pretty => true
+
+ ##
+ # Application configuration options
+ #
+ set :site_name, 'Ruby Committers'
+ # set :raise_errors, true # Show exceptions (default for development)
+ # set :public, "foo/bar" # Location for static assets (default root/public)
+ # set :reload, false # Reload application files (default in development)
+ # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
+ # set :locale_path, "bar" # Set path for I18n translations (defaults to app/locale/)
+ # enable :sessions # Disabled by default
+ # disable :flash # Disables rack-flash (enabled by default if sessions)
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
+ #
+
+ ##
+ # You can configure for a specified environment like:
+ #
+ # configure :development do
+ # set :foo, :bar
+ # disable :asset_stamp # no asset timestamping for dev
+ # end
+ #
+
+ ##
+ # You can manage errors like:
+ #
+ # error 404 do
+ # render 'errors/404'
+ # end
+ #
+end
View
5 app/controllers/accounts_controller.rb
@@ -1,5 +0,0 @@
-class AccountsController < ApplicationController
- def index
- @accounts = Account.find :all
- end
-end
View
3  app/controllers/application_controller.rb
@@ -1,3 +0,0 @@
-class ApplicationController < ActionController::Base
- protect_from_forgery
-end
View
7 app/controllers/heroes.rb
@@ -0,0 +1,7 @@
+RubyCommitters.controllers :heroes do
+ get :index, :map => '/' do
+ @heroes = Hero.all
+ @attrs = %w{names nicks sites services books portraits}
+ render 'heroes/index'
+ end
+end
View
22 app/helpers/accounts_helper.rb
@@ -1,22 +0,0 @@
-module AccountsHelper
- def link_to_service name, service
- case service.name
- when 'twitter'
- link_to name, 'http://twitter.com/' + service.key
- when 'friendfeed'
- link_to name, 'http://friendfeed.com/' + service.key
- when 'mixi'
- link_to name, 'http://mixi.jp/show_friend.pl?id=' + service.key
- when 'github'
- link_to name, 'http://github.com/' + service.key
- when 'facebook'
- if service.key =~ /^\s*\d+$/
- link_to name, 'http://www.facebook.com/profile.php?id=' + service.key
- else
- link_to name, 'http://www.facebook.com/' + service.key
- end
- when 'iddy'
- link_to name, 'http://iddy.jp/profile/' + service.key
- end
- end
-end
View
23 app/helpers/application_helper.rb
@@ -1,23 +0,0 @@
-module ApplicationHelper
- def analytics_tag
- if Rails.env.production?
- (<<-eojs).html_safe
-<script type="text/javascript">
-
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-1260604-9']);
- _gaq.push(['_trackPageview']);
-
- (function() {
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
- })();
-
-</script>
- eojs
- else
- ''
- end
- end
-end
View
18 app/helpers/heroes_helper.rb
@@ -0,0 +1,18 @@
+RubyCommitters.helpers do
+ def link_to_service(name, service)
+ _link_to = Proc.new { |url| link_to service.name, url + service.key }
+
+ case service.name
+ when 'twitter' then _link_to.call('http://twitter.com/')
+ when 'friendfeed' then _link_to.call('http://friendfeed.com/')
+ when 'mixi' then _link_to.call('http://show_friend.pl?id=')
+ when 'github' then _link_to.call('http://github.com/')
+ when 'iddy' then _link_to.call('http://iddy.jp/profile/')
+ when 'facebook' then _link_to.call("http://www.facebook.com/#{'profile.php?id=' if service.key =~ /^\d+$/}")
+ end
+ end
+
+ def link_to_book(isbn)
+ link_to isbn, 'http://books.google.com/books?as_isbn=' + isbn
+ end
+end
View
54 app/models/account.rb
@@ -1,54 +0,0 @@
-class Account < ActiveRecord::Base
- has_many :names
- has_many :nicks
- has_many :sites
- has_many :services
- has_many :portraits
- has_many :books
-
- ###
- # Import +io+ object that contains a YAML representation of the
- # ruby-committers
- def self.import io
- begin
- require 'psych'
- yamler = Psych
- rescue LoadError
- require 'yaml'
- yamler = YAML
- end
-
- doc = yamler.load io
- doc.each do |record|
- account = Account.create!(:username => record['account'])
- (record['name'] || []).each do |name|
- account.names.create!(:value => name)
- end
-
- (record['nick'] || []).each do |name|
- account.nicks.create!(:value => name)
- end
-
- (record['sites'] || []).each do |site|
- account.sites.create!(
- :title => site['title'],
- :url => site['url'],
- :lang => site['lang'],
- :feed => site['feed']
- )
- end
-
- (record['portraits'] || []).each do |portrait|
- account.portraits.create!(:url => portrait)
- end
-
- (record['services'] || []).each do |name, key|
- account.services.create!(:name => name, :key => key)
- end
-
- (record['ruby-books'] || []).each do |key|
- account.books.create!(:key => key)
- end
- end
- end
-end
View
2  app/models/book.rb
@@ -1,3 +1,3 @@
class Book < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
46 app/models/hero.rb
@@ -0,0 +1,46 @@
+class Hero < ActiveRecord::Base
+ has_many :names
+ has_many :nicks
+ has_many :sites
+ has_many :services
+ has_many :portraits
+ has_many :books
+
+ def self.import(io)
+ require 'yaml'
+
+ entries = YAML.load(io)
+ entries.each do |entry|
+ hero = Hero.create!(:username => entry['account'])
+
+ (entry['name'] || []).each do |name|
+ hero.names.create!(:value => name)
+ end
+
+ (entry['nick'] || []).each do |name|
+ hero.nicks.create!(:value => name)
+ end
+
+ (entry['sites'] || []).each do |site|
+ hero.sites.create!(
+ :title => site['title'],
+ :url => site['url'],
+ :lang => site['lang'],
+ :feed => site['feed']
+ )
+ end
+
+ (entry['portraits'] || []).each do |portrait|
+ hero.portraits.create!(:url => portrait)
+ end
+
+ (entry['services'] || []).each do |name, key|
+ hero.services.create!(:name => name, :key => key)
+ end
+
+ (entry['ruby-books'] || []).each do |isbn|
+ hero.books.create!(:isbn => isbn)
+ end
+ end
+ end
+end
View
2  app/models/name.rb
@@ -1,3 +1,3 @@
class Name < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
2  app/models/nick.rb
@@ -1,3 +1,3 @@
class Nick < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
2  app/models/portrait.rb
@@ -1,3 +1,3 @@
class Portrait < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
2  app/models/service.rb
@@ -1,3 +1,3 @@
class Service < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
2  app/models/site.rb
@@ -1,3 +1,3 @@
class Site < ActiveRecord::Base
- belongs_to :account
+ belongs_to :hero
end
View
79 app/views/accounts/_account.html.erb
@@ -1,79 +0,0 @@
-<li>
- <table>
- <tr>
- <td>Account:</td>
- <td><%= account.username %></td>
- </tr>
-
- <% unless account.names.empty? %>
- <tr>
- <td>Names:</td>
- <td>
- <ul>
- <%= render :partial => 'name', :collection => account.names %>
- </ul>
- </td>
- </tr>
- <% end %>
-
- <% unless account.nicks.empty? %>
- <tr>
- <td>Nicknames:</td>
- <td>
- <ul>
- <%= render :partial => 'name', :collection => account.nicks %>
- </ul>
- </td>
- </tr>
- <% end %>
-
- <% unless account.sites.empty? %>
- <tr>
- <td>Sites:</td>
- <td>
- <ul>
- <%= render :partial => 'site', :collection => account.sites %>
- </ul>
- </td>
- </tr>
- <% end %>
-
- <% unless account.services.empty? %>
- <tr>
- <td>Services:</td>
- <td>
- <ul>
- <%= render :partial => 'service', :collection => account.services %>
- </ul>
- </td>
- </tr>
- <% end %>
-
- <% unless account.portraits.empty? %>
- <tr>
- <td>Portraits:</td>
- <td>
- <ul>
- <%= render :partial => 'portrait', :collection => account.portraits %>
- </ul>
- </td>
- </tr>
- <% end %>
-
- <!-- FIXME: unsure how to link to ISBN. :-( -->
- <!--
- <% unless account.books.empty? %>
- <tr>
- <td>Books:</td>
- <td>
- <ul>
- <% account.books.each do |book| %>
- <li><%= book.key %></li>
- <% end %>
- </ul>
- </td>
- </tr>
- <% end %>
- -->
- </table>
-</li>
View
1  app/views/accounts/_name.html.erb
@@ -1 +0,0 @@
-<li><%= name.value %></li>
View
3  app/views/accounts/_portrait.html.erb
@@ -1,3 +0,0 @@
-<div class='image-wrapper'>
- <%= image_tag portrait.url %>
-</div>
View
3  app/views/accounts/_service.html.erb
@@ -1,3 +0,0 @@
-<li>
- <%= link_to_service service.name, service %>
-</li>
View
1  app/views/accounts/_site.html.erb
@@ -1 +0,0 @@
-<li><%= link_to site.title, site.url %></li>
View
5 app/views/accounts/index.html.erb
@@ -1,5 +0,0 @@
-<h1>Ruby Committers</h1>
-<%= link_to 'fork me on github', 'http://github.com/tenderlove/rubycommitters.org' %>
-<ul>
-<%= render :partial => 'account', :collection => @accounts %>
-</ul>
View
1  app/views/heroes/_book.html.slim
@@ -0,0 +1 @@
+li== link_to_book(book.isbn)
View
10 app/views/heroes/_hero.html.slim
@@ -0,0 +1,10 @@
+li
+ hr
+ h2= hero.username
+ table
+ - @attrs.each do |attr|
+ - unless hero.send(attr).empty?
+ tr
+ th= attr.capitalize
+ td
+ ul== partial "heroes/#{attr.chop}", :collection => hero.send(attr)
View
1  app/views/heroes/_name.html.slim
@@ -0,0 +1 @@
+li= name.value
View
1  app/views/heroes/_nick.html.slim
@@ -0,0 +1 @@
+li= nick.value
View
1  app/views/heroes/_portrait.html.slim
@@ -0,0 +1 @@
+li== image_tag portrait.url
View
1  app/views/heroes/_service.html.slim
@@ -0,0 +1 @@
+li== link_to_service service.name, service
View
1  app/views/heroes/_site.html.slim
@@ -0,0 +1 @@
+li== link_to site.title, site.url
View
3  app/views/heroes/index.html.slim
@@ -0,0 +1,3 @@
+h1= RubyCommitters.site_name
+
+ul== partial 'heroes/hero', :collection => @heroes
View
15 app/views/layouts/application.html.erb
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>Ruby Committers</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
- <%= analytics_tag %>
-</head>
-<body>
-
-<%= yield %>
-
-</body>
-</html>
View
20 app/views/layouts/application.html.slim
@@ -0,0 +1,20 @@
+! doctype html
+html
+ head
+ title= RubyCommitters.site_name
+ == stylesheet_link_tag :base
+ == javascript_include_tag :jquery, :application
+
+ body
+ == yield
+
+ - if Padrino.env == :production
+ javascript:
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-1260604-9']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
View
6 config.ru
@@ -1,4 +1,2 @@
-# This file is used by Rack-based servers to start the application.
-
-require ::File.expand_path('../config/environment', __FILE__)
-run Rubycommitters::Application
+require ::File.dirname(__FILE__) + '/config/boot.rb'
+run Padrino.application
View
42 config/application.rb
@@ -1,42 +0,0 @@
-require File.expand_path('../boot', __FILE__)
-
-require 'rails/all'
-
-# If you have a Gemfile, require the gems listed there, including any gems
-# you've limited to :test, :development, or :production.
-Bundler.require(:default, Rails.env) if defined?(Bundler)
-
-module Rubycommitters
- class Application < Rails::Application
- # Settings in config/environments/* take precedence over those specified here.
- # Application configuration should go into files in config/initializers
- # -- all .rb files in that directory are automatically loaded.
-
- # Custom directories with classes and modules you want to be autoloadable.
- # config.autoload_paths += %W(#{config.root}/extras)
-
- # Only load the plugins named here, in the order given (default is alphabetical).
- # :all can be used as a placeholder for all plugins not explicitly named.
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
-
- # Activate observers that should always be running.
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
-
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
- # config.time_zone = 'Central Time (US & Canada)'
-
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
- # config.i18n.default_locale = :de
-
- # JavaScript files you want as :defaults (application.js is always included).
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
-
- # Configure the default encoding used in templates for Ruby 1.9.
- config.encoding = "utf-8"
-
- # Configure sensitive parameters which will be filtered from the log file.
- config.filter_parameters += [:password]
- end
-end
View
25 config/apps.rb
@@ -0,0 +1,25 @@
+##
+# This file mounts each app in the Padrino project to a specified sub-uri.
+# You can mount additional applications using any of these commands below:
+#
+# Padrino.mount("blog").to('/blog')
+# Padrino.mount("blog", :app_class => "BlogApp").to('/blog')
+# Padrino.mount("blog", :app_file => "path/to/blog/app.rb").to('/blog')
+#
+# You can also map apps to a specified host:
+#
+# Padrino.mount("Admin").host("admin.example.org")
+# Padrino.mount("WebSite").host(/.*\.?example.org/)
+# Padrino.mount("Foo").to("/foo").host("bar.example.org")
+#
+# Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'.
+# Note 2: If you use the host matching remember to respect the order of the rules.
+#
+# By default, this file mounts the parimary app which was generated with this project.
+# However, the mounted app can be modified as needed:
+#
+# Padrino.mount(:app_file => "path/to/file", :app_class => "Blog").to('/')
+#
+
+# Mounts the core application for this project
+Padrino.mount("RubyCommitters").to('/')
View
35 config/boot.rb
@@ -1,13 +1,30 @@
-require 'rubygems'
+# Defines our constants
+PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV)
+PADRINO_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) unless defined?(PADRINO_ROOT)
-# Set up gems listed in the Gemfile.
-gemfile = File.expand_path('../../Gemfile', __FILE__)
begin
- ENV['BUNDLE_GEMFILE'] = gemfile
+ # Require the preresolved locked set of gems.
+ require File.expand_path('../../.bundle/environment', __FILE__)
+rescue LoadError
+ # Fallback on doing the resolve at runtime.
+ require 'rubygems'
require 'bundler'
Bundler.setup
-rescue Bundler::GemNotFound => e
- STDERR.puts e.message
- STDERR.puts "Try running `bundle install`."
- exit!
-end if File.exist?(gemfile)
+end
+
+Bundler.require(:default, PADRINO_ENV.to_sym)
+puts "=> Located #{Padrino.bundle} Gemfile for #{Padrino.env}"
+
+##
+# Add here your before load hooks
+#
+Padrino.before_load do
+end
+
+##
+# Add here your after load hooks
+#
+Padrino.after_load do
+end
+
+Padrino.load!
View
49 config/database.rb
@@ -0,0 +1,49 @@
+##
+# You can use other adapters like:
+#
+# ActiveRecord::Base.configurations[:development] = {
+# :adapter => 'mysql',
+# :encoding => 'utf8',
+# :reconnect => false,
+# :database => 'your_database',
+# :pool => 5,
+# :username => 'root',
+# :password => '',
+# :host => 'localhost',
+# :socket => '/tmp/mysql.sock'
+# }
+#
+
+ActiveRecord::Base.configurations[:development] = {
+ :adapter => 'sqlite3',
+ :database => Padrino.root('db', "rubycommitters_development.db")
+}
+
+ActiveRecord::Base.configurations[:production] = {
+ :adapter => 'sqlite3',
+ :database => Padrino.root('db', "rubycommitters_production.db")
+}
+
+ActiveRecord::Base.configurations[:test] = {
+ :adapter => 'sqlite3',
+ :database => Padrino.root('db', "rubycommitters_test.db")
+}
+
+# Setup our logger
+ActiveRecord::Base.logger = logger
+
+# 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
+
+# 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
+
+# Now we can estabilish connection with our db
+ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
View
22 config/database.yml
@@ -1,22 +0,0 @@
-# SQLite version 3.x
-# gem install sqlite3-ruby (not necessary on OS X Leopard)
-development:
- adapter: sqlite3
- database: db/development.sqlite3
- pool: 5
- timeout: 5000
-
-# Warning: The database defined as "test" will be erased and
-# re-generated from your development database when you run "rake".
-# Do not set this db to the same as development or production.
-test:
- adapter: sqlite3
- database: db/test.sqlite3
- pool: 5
- timeout: 5000
-
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
View
5 config/environment.rb
@@ -1,5 +0,0 @@
-# Load the rails application
-require File.expand_path('../application', __FILE__)
-
-# Initialize the rails application
-Rubycommitters::Application.initialize!
View
26 config/environments/development.rb
@@ -1,26 +0,0 @@
-Rubycommitters::Application.configure do
- # Settings specified here will take precedence over those in config/application.rb
-
- # In the development environment your application's code is reloaded on
- # every request. This slows down response time but is perfect for development
- # since you don't have to restart the webserver when you make code changes.
- config.cache_classes = false
-
- # Log error messages when you accidentally call methods on nil.
- config.whiny_nils = true
-
- # Show full error reports and disable caching
- config.consider_all_requests_local = true
- config.action_view.debug_rjs = true
- config.action_controller.perform_caching = false
-
- # Don't care if the mailer can't send
- config.action_mailer.raise_delivery_errors = false
-
- # Print deprecation notices to the Rails logger
- config.active_support.deprecation = :log
-
- # Only use best-standards-support built into browsers
- config.action_dispatch.best_standards_support = :builtin
-end
-
View
49 config/environments/production.rb
@@ -1,49 +0,0 @@
-Rubycommitters::Application.configure do
- # Settings specified here will take precedence over those in config/application.rb
-
- # The production environment is meant for finished, "live" apps.
- # Code is not reloaded between requests
- config.cache_classes = true
-
- # Full error reports are disabled and caching is turned on
- config.consider_all_requests_local = false
- config.action_controller.perform_caching = true
-
- # Specifies the header that your server uses for sending files
- config.action_dispatch.x_sendfile_header = "X-Sendfile"
-
- # For nginx:
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
-
- # If you have no front-end server that supports something like X-Sendfile,
- # just comment this out and Rails will serve the files
-
- # See everything in the log (default is :info)
- # config.log_level = :debug
-
- # Use a different logger for distributed setups
- # config.logger = SyslogLogger.new
-
- # Use a different cache store in production
- # config.cache_store = :mem_cache_store
-
- # Disable Rails's static asset server
- # In production, Apache or nginx will already do this
- config.serve_static_assets = false
-
- # Enable serving of images, stylesheets, and javascripts from an asset server
- # config.action_controller.asset_host = "http://assets.example.com"
-
- # Disable delivery errors, bad email addresses will be ignored
- # config.action_mailer.raise_delivery_errors = false
-
- # Enable threaded mode
- # config.threadsafe!
-
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
- # the I18n.default_locale when a translation can not be found)
- config.i18n.fallbacks = true
-
- # Send deprecation notices to registered listeners
- config.active_support.deprecation = :notify
-end
View
35 config/environments/test.rb
@@ -1,35 +0,0 @@
-Rubycommitters::Application.configure do
- # Settings specified here will take precedence over those in config/application.rb
-
- # The test environment is used exclusively to run your application's
- # test suite. You never need to work with it otherwise. Remember that
- # your test database is "scratch space" for the test suite and is wiped
- # and recreated between test runs. Don't rely on the data there!
- config.cache_classes = true
-
- # Log error messages when you accidentally call methods on nil.
- config.whiny_nils = true
-
- # Show full error reports and disable caching
- config.consider_all_requests_local = true
- config.action_controller.perform_caching = false
-
- # Raise exceptions instead of rendering exception templates
- config.action_dispatch.show_exceptions = 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
-
- # 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
-
- # Print deprecation notices to the stderr
- config.active_support.deprecation = :stderr
-end
View
7 config/initializers/backtrace_silencers.rb
@@ -1,7 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
-# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
-
-# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
-# Rails.backtrace_cleaner.remove_silencers!
View
10 config/initializers/inflections.rb
@@ -1,10 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-# Add new inflection rules using the following format
-# (all these examples are active by default):
-# ActiveSupport::Inflector.inflections do |inflect|
-# inflect.plural /^(ox)$/i, '\1en'
-# inflect.singular /^(ox)en/i, '\1'
-# inflect.irregular 'person', 'people'
-# inflect.uncountable %w( fish sheep )
-# end
View
5 config/initializers/mime_types.rb
@@ -1,5 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-# Add new mime types for use in respond_to blocks:
-# Mime::Type.register "text/richtext", :rtf
-# Mime::Type.register_alias "text/html", :iphone
View
7 config/initializers/secret_token.rb
@@ -1,7 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-# Your secret key for verifying the integrity of signed cookies.
-# If you change this key, all old signed cookies 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.
-Rubycommitters::Application.config.secret_token = 'a927173e0a11e6e2869c568fdbc19eae1425c9691a3addbe00bf0ea7e005795a6a4722ab07c36f88abe48568e934a8ac0d0d91ab957d7896ea309887c0afe861'
View
8 config/initializers/session_store.rb
@@ -1,8 +0,0 @@
-# Be sure to restart your server when you modify this file.
-
-Rubycommitters::Application.config.session_store :cookie_store, :key => '_rubycommitters_session'
-
-# 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 "rails generate session_migration")
-# Rubycommitters::Application.config.session_store :active_record_store
View
5 config/locales/en.yml
@@ -1,5 +0,0 @@
-# Sample localization file for English. Add more files in this directory for other locales.
-# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
-
-en:
- hello: "Hello world"
View
4 config/routes.rb
@@ -1,4 +0,0 @@
-Rubycommitters::Application.routes.draw do
- resources :accounts
- root :to => 'accounts#index'
-end
View
12 db/migrate/001_create_heros.rb
@@ -0,0 +1,12 @@
+class CreateHeros < ActiveRecord::Migration
+ def self.up
+ create_table :heros do |t|
+ t.string :username
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :heros
+ end
+end
View
5 db/migrate/20110101001709_create_books.rb → db/migrate/002_create_books.rb
@@ -1,9 +1,8 @@
class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
- t.string :key
- t.references :account
-
+ t.string :isbn
+ t.references :hero
t.timestamps
end
end
View
3  db/migrate/20110101001535_create_names.rb → db/migrate/003_create_names.rb
@@ -2,8 +2,7 @@ class CreateNames < ActiveRecord::Migration
def self.up
create_table :names do |t|
t.string :value
- t.references :account
-
+ t.references :hero
t.timestamps
end
end
View
3  db/migrate/20110101002342_create_nicks.rb → db/migrate/004_create_nicks.rb
@@ -2,8 +2,7 @@ class CreateNicks < ActiveRecord::Migration
def self.up
create_table :nicks do |t|
t.string :value
- t.references :account
-
+ t.references :hero
t.timestamps
end
end
View
3  ...igrate/20110101001654_create_portraits.rb → db/migrate/005_create_portraits.rb
@@ -2,8 +2,7 @@ class CreatePortraits < ActiveRecord::Migration
def self.up
create_table :portraits do |t|
t.string :url
- t.references :account
-
+ t.references :hero
t.timestamps
end
end
View
3  db/migrate/20110101001639_create_services.rb → db/migrate/006_create_services.rb
@@ -3,8 +3,7 @@ def self.up
create_table :services do |t|
t.string :name
t.string :key
- t.references :account
-
+ t.references :hero
t.timestamps
end
end
View
3  db/migrate/20110101001612_create_sites.rb → db/migrate/007_create_sites.rb
@@ -5,8 +5,7 @@ def self.up
t.string :url
t.string :feed
t.string :lang
- t.references :account
-
+ t.references :hero
t.timestamps
end
end
View
13 db/migrate/20110101001326_create_accounts.rb
@@ -1,13 +0,0 @@
-class CreateAccounts < ActiveRecord::Migration
- def self.up
- create_table :accounts do |t|
- t.string :username
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :accounts
- end
-end
View
BIN  db/rubycommitters_development.db
Binary file not shown
View
BIN  db/rubycommitters_test.db
Binary file not shown
View
22 db/schema.rb
@@ -10,38 +10,38 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20110101002342) do
+ActiveRecord::Schema.define(:version => 7) do
- create_table "accounts", :force => true do |t|
- t.string "username"
+ create_table "books", :force => true do |t|
+ t.string "isbn"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
- create_table "books", :force => true do |t|
- t.string "key"
- t.integer "account_id"
+ create_table "heros", :force => true do |t|
+ t.string "username"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "names", :force => true do |t|
t.string "value"
- t.integer "account_id"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "nicks", :force => true do |t|
t.string "value"
- t.integer "account_id"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "portraits", :force => true do |t|
t.string "url"
- t.integer "account_id"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -49,7 +49,7 @@
create_table "services", :force => true do |t|
t.string "name"
t.string "key"
- t.integer "account_id"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
@@ -59,7 +59,7 @@
t.string "url"
t.string "feed"
t.string "lang"
- t.integer "account_id"
+ t.integer "hero_id"
t.datetime "created_at"
t.datetime "updated_at"
end
View
7 db/seeds.rb
@@ -1,7 +0,0 @@
-# This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
-#
-# Examples:
-#
-# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
-# Mayor.create(:name => 'Daley', :city => cities.first)
View
2  doc/README_FOR_APP
@@ -1,2 +0,0 @@
-Use this README file to introduce your application and point to useful places in the API for learning more.
-Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
View
0  lib/tasks/.gitkeep
No changes.
View
7 lib/tasks/import.rake
@@ -1,6 +1,5 @@
-require 'open-uri'
-
desc "import the list of ruby committers"
-task :import => 'db:migrate' do
- Account.import open('http://svn.coderepos.org/share/lang/ruby/ruby-committers/ruby-committers.yml')
+task :import => ['ar:drop', 'ar:migrate'] do
+ require 'open-uri'
+ Hero.import open('http://svn.coderepos.org/share/lang/ruby/ruby-committers/ruby-committers.yml')
end
View
26 public/404.html
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>The page you were looking for doesn't exist (404)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/404.html -->
- <div class="dialog">
- <h1>The page you were looking for doesn't exist.</h1>
- <p>You may have mistyped the address or the page may have moved.</p>
- </div>
-</body>
-</html>
View
26 public/422.html
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>The change you wanted was rejected (422)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/422.html -->
- <div class="dialog">
- <h1>The change you wanted was rejected.</h1>
- <p>Maybe you tried to change something you didn't have access to.</p>
- </div>
-</body>
-</html>
View
26 public/500.html
@@ -1,26 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>We're sorry, but something went wrong (500)</title>
- <style type="text/css">
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
- div.dialog {
- width: 25em;
- padding: 0 4em;
- margin: 4em auto 0 auto;
- border: 1px solid #ccc;
- border-right-color: #999;
- border-bottom-color: #999;
- }
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
- </style>
-</head>
-
-<body>
- <!-- This file lives in public/500.html -->
- <div class="dialog">
- <h1>We're sorry, but something went wrong.</h1>
- <p>We've been notified about this issue and we'll take a look at it shortly.</p>
- </div>
-</body>
-</html>
View
BIN  public/images/rails.png
Deleted file not rendered
View
48 public/index.html
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>
+ Welcome to Padrino
+ </title>
+ <style type="text/css">
+ body{
+ font-family:Helvetica,Arial,sans-serif;
+ line-height:150%;
+ }
+ ul,li{
+ list-style-type:none;
+ margin:0px;
+ padding:5px 0px 5px 0px;
+ margin-left:5px;
+ }
+ a{
+ color:#333;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>
+ Welcome to Padrino.rb
+ </h1>
+ <p>
+ Thanks for choosing Padrino for your Development.<br />
+ To get you started you we collected some Tutorials and Links:<br />
+ </p>
+ <ul>
+ <li>
+ <a href="http://www.padrinorb.com/guides/blog-tutorial">Blog Tutorial</a>
+ </li>
+ <li>
+ <a href="http://www.padrinorb.com/guides/generators">Generators</a>
+ </li>
+ <li>
+ <a href="http://www.padrinorb.com/guides/development-commands">Development Commands</a>
+ </li>
+ </ul>
+ <p>
+ To define a new default site for your project please delete this <em>index.html</em> file from the <em>public</em> directory.
+ </p>
+ </body>
+</html>
View
2  public/javascripts/application.js
@@ -1,2 +0,0 @@
-// Place your application-specific JavaScript functions and classes here
-// This file is automatically included by javascript_include_tag :defaults
View
965 public/javascripts/controls.js
@@ -1,965 +0,0 @@
-// script.aculo.us controls.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
-
-// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
-// (c) 2005-2009 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
-// (c) 2005-2009 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
-// 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,
-// a getUpdatedChoices function that will be invoked every time
-// 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
-// autocompletion. Specific auto-completion logic (AJAX, etc)
-// belongs in getUpdatedChoices.
-//
-// Tokenized incremental autocompletion is enabled automatically
-// when an autocompleter is instantiated with the 'tokens' option
-// in the options parameter, e.g.:
-// new Ajax.Autocompleter('id','upd', '/url/', { tokens: ',' });
-// 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
-// allows smart autocompletion after linebreaks.
-
-if(typeof Effect == 'undefined')
- throw("controls.js requires including script.aculo.us' effects.js library");
-
-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;
- this.entryCount = 0;
- this.oldElementValue = this.element.value;
-
- if(this.setOptions)
- this.setOptions(options);
- else
- this.options = options || { };
-
- this.options.paramName = this.options.paramName || this.element.name;
- 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){
- if(!update.style.position || update.style.position=='absolute') {
- update.style.position = 'absolute';
- Position.clone(element, update, {
- setHeight: false,
- offsetTop: element.offsetHeight
- });
- }
- Effect.Appear(update,{duration:0.15});
- };
- this.options.onHide = this.options.onHide ||
- function(element, update){ new Effect.Fade(update,{duration:0.15}) };
-
- 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);
-
- Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
- Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
- },
-
- show: function() {
- if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
- if(!this.iefix &&
- (Prototype.Browser.IE) &&
- (Element.getStyle(this.update, 'position')=='absolute')) {
- 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>');
- this.iefix = $(this.update.id+'_iefix');
- }
- 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;
- this.update.style.zIndex = 2;
- Element.show(this.iefix);
- },
-
- hide: function() {
- this.stopIndicator();
- if(Element.getStyle(this.update, 'display')!='none') this.options.onHide(this.element, this.update);
- if(this.iefix) Element.hide(this.iefix);
- },
-
- startIndicator: function() {
- if(this.options.indicator) Element.show(this.options.indicator);
- },
-
- stopIndicator: function() {
- if(this.options.indicator) Element.hide(this.options.indicator);
- },
-
- onKeyPress: function(event) {
- if(this.active)
- switch(event.keyCode) {
- case Event.KEY_TAB:
- case Event.KEY_RETURN:
- this.selectEntry();
- Event.stop(event);
- case Event.KEY_ESC:
- this.hide();
- this.active = false;
- Event.stop(event);
- return;
- case Event.KEY_LEFT:
- case Event.KEY_RIGHT:
- return;
- case Event.KEY_UP:
- this.markPrevious();
- this.render();
- Event.stop(event);
- return;
- case Event.KEY_DOWN:
- this.markNext();
- this.render();
- Event.stop(event);
- 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 =
- setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000);
- },
-
- activate: function() {
- this.changed = false;
- this.hasFocus = true;
- this.getUpdatedChoices();
- },
-
- onHover: function(event) {
- var element = Event.findElement(event, 'LI');
- 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;
- },
-
- render: function() {
- if(this.entryCount > 0) {
- for (var i = 0; i < this.entryCount; i++)
- this.index==i ?
- Element.addClassName(this.getEntry(i),"selected") :
- Element.removeClassName(this.getEntry(i),"selected");
- if(this.hasFocus) {
- this.show();
- this.active = true;
- }
- } else {
- this.active = false;
- this.hide();
- }
- },
-
- markPrevious: function() {
- 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++;
- 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());
- },
-
- updateElement: function(selectedElement) {
- if (this.options.updateElement) {
- this.options.updateElement(selectedElement);
- return;
- }
- var value = '';
- if (this.options.select) {
- var nodes = $(selectedElement).select('.' + this.options.select) || [];
- 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]);
- var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
- if (whitespace)
- newValue += whitespace[0];
- this.element.value = newValue + value + this.element.value.substr(bounds[1]);
- } else {
- this.element.value = value;
- }
- this.oldElementValue = this.element.value;
- this.element.focus();
-
- if (this.options.afterUpdateElement)
- this.options.afterUpdateElement(this.element, selectedElement);
- },
-
- updateChoices: function(choices) {
- if(!this.changed && this.hasFocus) {
- this.update.innerHTML = choices;
- Element.cleanWhitespace(this.update);
- Element.cleanWhitespace(this.update.down());
-
- if(this.update.firstChild && this.update.down().childNodes) {
- 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 {
- this.entryCount = 0;
- }
-
- this.stopIndicator();
- this.index = 0;
-
- if(this.entryCount==1 && this.options.autoSelect) {
- this.selectEntry();
- this.hide();
- } else {
- this.render();
- }
- }
- },
-
- addObservers: function(element) {
- Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
- Event.observe(element, "click", this.onClick.bindAsEventListener(this));
- },
-
- onObserverEvent: function() {
- this.changed = false;
- this.tokenBounds = null;
- if(this.getToken().length>=this.options.minChars) {
- this.getUpdatedChoices();
- } else {
- this.active = false;
- this.hide();
- }
- this.oldElementValue = this.element.value;
- },
-
- getToken: function() {
- var bounds = this.getTokenBounds();
- return this.element.value.substring(bounds[0], bounds[1]).strip();
- },
-
- getTokenBounds: function() {
- if (null != this.tokenBounds) return this.tokenBounds;
- var value = this.element.value;
- if (value.strip().empty()) return [-1, 0];
- var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
- var offset = (diff == this.oldElementValue.length ? 1 : 0);
- var prevTokenPos = -1, nextTokenPos = value.length;
- var tp;
- for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
- tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
- if (tp > prevTokenPos) prevTokenPos = tp;
- tp = value.indexOf(this.options.tokens[index], diff + offset);
- if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
- }
- return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
- }
-});
-
-Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
- var boundary = Math.min(newS.length, oldS.length);
- for (var index = 0; index < boundary; ++index)
- if (newS[index] != oldS[index])
- return index;
- return boundary;
-};
-
-Ajax.Autocompleter = Class.create(Autocompleter.Base, {
- initialize: function(element, update, url, options) {
- this.baseInitialize(element, update, options);
- this.options.asynchronous = true;
- this.options.onComplete = this.onComplete.bind(this);
- this.options.defaultParams = this.options.parameters || null;
- this.url = url;
- },
-
- getUpdatedChoices: function() {
- this.startIndicator();
-
- 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)
- this.options.parameters += '&' + this.options.defaultParams;
-
- new Ajax.Request(this.url, this.options);
- },
-
- onComplete: function(request) {
- this.updateChoices(request.responseText);
- }
-});
-
-// The local array autocompleter. Used when you'd prefer to
-// inject an array of autocompletion options into the page, rather
-// than sending out Ajax queries, which can be quite slow sometimes.
-//
-// The constructor takes four parameters. The first two are, as usual,
-// the id of the monitored textbox, and id of the autocompletion menu.
-// The third is the array you want to autocomplete from, and the fourth
-// is the options block.
-//
-// Extra local autocompletion options:
-// - choices - How many autocompletion choices to offer
-//
-// - partialSearch - If false, the autocompleter will match entered
-// 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
-// search anywhere in the string, additionally set
-// the option fullSearch to true (default: off).
-//
-// - fullSsearch - Search anywhere in autocomplete array strings.
-//
-// - partialChars - How many characters to enter before triggering
-// a partial match (unlike minChars, which defines
-// how many characters are required to do any match
-// at all). Defaults to 2.
-//
-// - ignoreCase - Whether to ignore case when autocompleting.
-// Defaults to true.
-//
-// 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.
-
-Autocompleter.Local = Class.create(Autocompleter.Base, {
- initialize: function(element, update, array, options) {
- this.baseInitialize(element, update, options);
- this.options.array = array;
- },
-
- getUpdatedChoices: function() {
- this.updateChoices(this.options.selector(this));
- },
-
- setOptions: function(options) {
- this.options = Object.extend({
- choices: 10,
- partialSearch: true,
- partialChars: 2,
- ignoreCase: true,
- fullSearch: false,
- selector: function(instance) {
- var ret = []; // Beginning matches
- var partial = []; // Inside matches
- var entry = instance.getToken();
- var count = 0;
-
- 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()) :
- elem.indexOf(entry);
-
- while (foundPos != -1) {
- 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 &&
- instance.options.partialSearch && foundPos != -1) {
- if (instance.options.fullSearch || /\s/.test(elem.substr(foundPos-1,1))) {
- partial.push("<li>" + elem.substr(0, foundPos) + "<strong>" +
- elem.substr(foundPos, entry.length) + "</strong>" + elem.substr(
- foundPos + entry.length) + "</li>");
- break;
- }
- }
-
- 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));
- return "<ul>" + ret.join('') + "</ul>";
- }
- }, options || { });
- }
-});
-
-// AJAX in-place editor and collection editor
-// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
-
-// Use this if you notice weird scrolling problems on some browsers,
-// the DOM might be a bit confused when this gets called so do this
-// waits 1 ms (with setTimeout) until it does the activation
-Field.scrollFreeActivate = function(field) {
- setTimeout(function() {
- Field.activate(field);
- }, 1);
-};
-
-Ajax.InPlaceEditor = Class.create({
- initialize: function(element, url, options) {
- this.url = url;
- this.element = element = $(element);
- this.prepareOptions();
- this._controls = { };
- arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
- Object.extend(this.options, options || { });
- if (!this.options.formId && this.element.id) {
- this.options.formId = this.element.id + '-inplaceeditor';
- if ($(this.options.formId))
- this.options.formId = '';
- }
- if (this.options.externalControl)
- this.options.externalControl = $(this.options.externalControl);
- if (!this.options.externalControl)
- this.options.externalControlOnly = false;
- this._originalBackground = this.element.getStyle('background-color') || 'transparent';
- this.element.title = this.options.clickToEditText;
- this._boundCancelHandler = this.handleFormCancellation.bind(this);
- this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
- this._boundFailureHandler = this.handleAJAXFailure.bind(this);
- this._boundSubmitHandler = this.handleFormSubmission.bind(this);
- this._boundWrapperHandler = this.wrapUp.bind(this);
- this.registerListeners();
- },
- checkForEscapeOrReturn: function(e) {
- if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
- if (Event.KEY_ESC == e.keyCode)
- this.handleFormCancellation(e);
- else if (Event.KEY_RETURN == e.keyCode)
- this.handleFormSubmission(e);
- },
- createControl: function(mode, handler, extraClasses) {
- var control = this.options[mode + 'Control'];
- var text = this.options[mode + 'Text'];
- if ('button' == control) {
- var btn = document.createElement('input');
- btn.type = 'submit';
- btn.value = text;
- btn.className = 'editor_' + mode + '_button';
- if ('cancel' == mode)
- btn.onclick = this._boundCancelHandler;
- this._form.appendChild(btn);
- this._controls[mode] = btn;
- } else if ('link' == control) {
- var link = document.createElement('a');
- link.href = '#';
- link.appendChild(document.createTextNode(text));
- link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
- link.className = 'editor_' + mode + '_link';
- if (extraClasses)
- link.className += ' ' + extraClasses;
- this._form.appendChild(link);
- this._controls[mode] = link;
- }
- },
- createEditField: function() {
- var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
- var fld;
- if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
- fld = document.createElement('input');
- fld.type = 'text';
- var size = this.options.size || this.options.cols || 0;
- if (0 < size) fld.size = size;
- } else {
- fld = document.createElement('textarea');
- fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
- fld.cols = this.options.cols || 40;
- }
- fld.name = this.options.paramName;
- fld.value = text; // No HTML breaks conversion anymore
- fld.className = 'editor_field';
- if (this.options.submitOnBlur)
- fld.onblur = this._boundSubmitHandler;
- this._controls.editor = fld;
- if (this.options.loadTextURL)
- this.loadExternalText();
- this._form.appendChild(this._controls.editor);
- },
- createForm: function() {
- var ipe = this;
- function addText(mode, condition) {
- var text = ipe.options['text' + mode + 'Controls'];
- if (!text || condition === false) return;
- ipe._form.appendChild(document.createTextNode(text));
- };
- this._form = $(document.createElement('form'));
- this._form.id = this.options.formId;
- this._form.addClassName(this.options.formClassName);
- this._form.onsubmit = this._boundSubmitHandler;
- this.createEditField();
- if ('textarea' == this._controls.editor.tagName.toLowerCase())
- this._form.appendChild(document.createElement('br'));
- if (this.options.onFormCustomization)
- this.options.onFormCustomization(this, this._form);
- addText('Before', this.options.okControl || this.options.cancelControl);
- this.createControl('ok', this._boundSubmitHandler);
- addText('Between', this.options.okControl && this.options.cancelControl);
- this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
- addText('After', this.options.okControl || this.options.cancelControl);
- },
- destroy: function() {
- if (this._oldInnerHTML)
- this.element.innerHTML = this._oldInnerHTML;
- this.leaveEditMode();
- this.unregisterListeners();
- },
- enterEditMode: function(e) {
- if (this._saving || this._editing) return;
- this._editing = true;
- this.triggerCallback('onEnterEditMode');
- if (this.options.externalControl)
- this.options.externalControl.hide();
- this.element.hide();
- this.createForm();
- this.element.parentNode.insertBefore(this._form, this.element);
- if (!this.options.loadTextURL)
- this.postProcessEditField();
- if (e) Event.stop(e);
- },
- enterHover: function(e) {
- if (this.options.hoverClassName)
- this.element.addClassName(this.options.hoverClassName);
- if (this._saving) return;
- this.triggerCallback('onEnterHover');
- },
- getText: function() {
- return this.element.innerHTML.unescapeHTML();
- },
- handleAJAXFailure: function(transport) {
- this.triggerCallback('onFailure', transport);
- if (this._oldInnerHTML) {
- this.element.innerHTML = this._oldInnerHTML;
- this._oldInnerHTML = null;
- }
- },
- handleFormCancellation: function(e) {
- this.wrapUp();
- if (e) Event.stop(e);
- },
- handleFormSubmission: function(e) {
- var form = this._form;
- var value = $F(this._controls.editor);
- this.prepareSubmission();
- var params = this.options.callback(form, value) || '';
- if (Object.isString(params))
- params = params.toQueryParams();
- params.editorId = this.element.id;
- if (this.options.htmlResponse) {
- var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
- Object.extend(options, {
- parameters: params,
- onComplete: this._boundWrapperHandler,
- onFailure: this._boundFailureHandler
- });
- new Ajax.Updater({ success: this.element }, this.url, options);
- } else {
- var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
- Object.extend(options, {
- parameters: params,