upgrade to rails3, but grip is broken

This commit is contained in:
Wen-Tien Chang 2010-03-08 16:04:05 +08:00
parent 9f1de1b543
commit 29ee4585b2
53 changed files with 485 additions and 1133 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.bundle
db/*.sqlite3
log/*.log log/*.log
tmp/**/* tmp/**/*
.DS_Store .DS_Store

32
Gemfile Normal file
View File

@ -0,0 +1,32 @@
# Edit this Gemfile to bundle your application's dependencies.
source 'http://gemcutter.org'
gem "rails", "3.0.0.beta"
gem "liquid"
# http://github.com/merbjedi/mongomapper
gem "mongo_mapper-rails3", :require => "mongo_mapper"
#gem 'grip'
gem 'warden'
gem 'devise', "1.1.pre"
## Bundle edge rails:
# gem "rails", :git => "git://github.com/rails/rails.git"
# ActiveRecord requires a database adapter. By default,
# Rails has selected sqlite3.
# gem "sqlite3-ruby", :require => "sqlite3"
## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
# gem "sqlite3-ruby", :require => "sqlite3"
# gem "aws-s3", :require => "aws/s3"
## Bundle gems used only in certain environments:
# gem "rspec", :group => :test
# group :test do
# gem "webrat"
# end

View File

@ -1,10 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake, # 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. # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot')) require File.expand_path('../config/application', __FILE__)
require 'rake' require 'rake'
require 'rake/testtask' require 'rake/testtask'
require 'rake/rdoctask' require 'rake/rdoctask'
require 'tasks/rails' Rails::Application.load_tasks

View File

@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery
helper :all helper :all
protect_from_forgery
before_filter :set_locale before_filter :set_locale

View File

@ -10,7 +10,7 @@ class PagesController < ApplicationController
end end
def show def show
@page = Page.find_by_full_name(params[:page_name].join("/")) @page = Page.find_by_full_name(params[:page_name])
render_liquid_page render_liquid_page
end end

View File

@ -2,7 +2,7 @@ module AdminHelper
def show_parent_items_link(parent_item) def show_parent_items_link(parent_item)
@parent_items = @parent_item.ancestors.map{ |i| i.name } @parent_items = @parent_item.ancestors.map{ |i| i.name }
( @parent_items.map{ |i| link_to(i, admin_items_path(:parent_name=>i) ) } << parent_item.name ).join("/") ( @parent_items.map{ |i| link_to(i, admin_items_path(:parent_name=>i) ) } << parent_item.name ).join("/").html_safe
end end
end end

View File

@ -1,3 +1,2 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper module ApplicationHelper
end end

View File

@ -39,7 +39,7 @@
<%= javascript_include_tag "jquery", <%= javascript_include_tag "jquery",
"jquery-ui", "jquery-ui",
"jrails", "rails",
"easy", "easy",
"application", :cache => 'all' %> "application", :cache => 'all' %>
<%= yield :page_specific_javascript %> <%= yield :page_specific_javascript %>

View File

@ -37,7 +37,7 @@
<%= javascript_include_tag "jquery", <%= javascript_include_tag "jquery",
"jquery-ui", "jquery-ui",
"jrails", "rails",
"easy", "easy",
"application", :cache => 'all' %> "application", :cache => 'all' %>
<%= yield :page_specific_javascript %> <%= yield :page_specific_javascript %>

4
config.ru Normal file
View File

@ -0,0 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run R4::Application

53
config/application.rb Normal file
View File

@ -0,0 +1,53 @@
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
# require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
# require "active_resource/railtie"
# require "rails/test_unit/railtie"
require File.expand_path('lib/reroute_middleware')
# Auto-require default libraries and those for the current Rails environment.
Bundler.require :default, Rails.env
module R4
class Application < Rails::Application
config.middleware.use RerouteMiddleware
# 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.
# Add additional load paths for your own custom dirs
# config.load_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 = 'Taipei'
# 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}')]
config.i18n.default_locale = :zh_tw
# Configure generators values. Many other options are available, be sure to check the documentation.
# config.generators do |g|
# g.orm :active_record
# g.template_engine :erb
# g.test_framework :test_unit, :fixture => true
# end
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters << :password
end
end
VALID_LOCALES = ["en", "zh_tw"]

View File

@ -1,110 +1,17 @@
# Don't change this file! # Use Bundler (preferred)
# Configure your app in config/environment.rb and config/environments/*.rb begin
require File.expand_path('../../.bundle/environment', __FILE__)
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) rescue LoadError
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
defined? Rails::Initializer
end
def pick_boot
(vendor_rails? ? VendorBoot : GemBoot).new
end
def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails")
end
def preinitialize
load(preinitializer_path) if File.exist?(preinitializer_path)
end
def preinitializer_path
"#{RAILS_ROOT}/config/preinitializer.rb"
end
end
class Boot
def run
load_initializer
Rails::Initializer.run(:set_load_path)
end
end
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
class GemBoot < Boot
def load_initializer
self.class.load_rubygems
load_rails_gem
require 'initializer'
end
def load_rails_gem
if version = self.class.gem_version
gem 'rails', version
else
gem 'rails'
end
rescue Gem::LoadError => load_error
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
exit 1
end
class << self
def rubygems_version
Gem::RubyGemsVersion rescue nil
end
def gem_version
if defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION
elsif ENV.include?('RAILS_GEM_VERSION')
ENV['RAILS_GEM_VERSION']
else
parse_gem_version(read_environment_rb)
end
end
def load_rubygems
require 'rubygems' require 'rubygems'
min_version = '1.3.1' require 'bundler'
unless rubygems_version >= min_version Bundler.setup
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
end
rescue LoadError # To use 2.x style vendor/rails and RubyGems
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) #
exit 1 # vendor_rails = File.expand_path('../../vendor/rails', __FILE__)
end # if File.exist?(vendor_rails)
# Dir["#{vendor_rails}/*/lib"].each { |path| $:.unshift(path) }
def parse_gem_version(text) # end
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ #
end # require 'rubygems'
private
def read_environment_rb
File.read("#{RAILS_ROOT}/config/environment.rb")
end
end
end
end end
# All that for this:
Rails.boot!

View File

@ -1,76 +1,5 @@
# Be sure to restart your server when you modify this file # Load the rails application
require File.expand_path('../application', __FILE__)
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' 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|
# 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.
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{RAILS_ROOT}/extras )
# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "sqlite3-ruby", :lib => "sqlite3"
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "liquid"
config.gem "mongo_mapper"
config.gem 'grip'
config.gem "devise", :version => '1.0.1'
# 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 ]
# 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 ]
# 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.
config.time_zone = "Taipei"
# 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}')]
config.i18n.default_locale = "zh_tw"
config.middleware.use :RerouteMiddleware
end
#VALID_LOCALES = ["en", "zh_tw"]
VALID_LOCALES = ["en", "zh_tw"]
MongoMapper.database = "r4-#{Rails.env}"
module MongoMapper::Document::ClassMethods
def key_i18n(key, *options)
VALID_LOCALES.each do |locale|
key "#{key.to_s}_#{locale}".to_sym, *options
end
define_method(key) do
self.send("#{key.to_s}_#{I18n.locale}")
end
define_method("#{key}=") do |value|
VALID_LOCALES.each do |locale|
self.send("#{key.to_s}_#{locale}=", value)
end
end
end
end
# Initialize the rails application
R4::Application.initialize!

View File

@ -1,19 +1,20 @@
# Settings specified here will take precedence over those in config/environment.rb R4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on # In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development # 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. # since you don't have to restart the webserver when you make code changes.
config.cache_classes = false config.cache_classes = false
# Log error messages when you accidentally call methods on nil. # Log error messages when you accidentally call methods on nil.
config.whiny_nils = true config.whiny_nils = true
# Show full error reports and disable caching # Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_view.debug_rjs = true config.action_view.debug_rjs = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = { :host => 'localhost:3000' } end

View File

@ -1,28 +1,33 @@
# Settings specified here will take precedence over those in config/environment.rb R4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps. # The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests # Code is not reloaded between requests
config.cache_classes = true config.cache_classes = true
# Full error reports are disabled and caching is turned on # Full error reports are disabled and caching is turned on
config.action_controller.consider_all_requests_local = false config.consider_all_requests_local = false
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
config.action_view.cache_template_loading = true
# See everything in the log (default is :info) # See everything in the log (default is :info)
# config.log_level = :debug # config.log_level = :debug
# Use a different logger for distributed setups # Use a different logger for distributed setups
# config.logger = SyslogLogger.new # config.logger = SyslogLogger.new
# Use a different cache store in production # Use a different cache store in production
# config.cache_store = :mem_cache_store # config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and javascripts from an asset server # Disable Rails's static asset server
# config.action_controller.asset_host = "http://assets.example.com" # In production, Apache or nginx will already do this
config.serve_static_assets = false
# Disable delivery errors, bad email addresses will be ignored # Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_mailer.raise_delivery_errors = false # config.action_controller.asset_host = "http://assets.example.com"
# Enable threaded mode # Disable delivery errors, bad email addresses will be ignored
# config.threadsafe! # config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
end

View File

@ -1,28 +1,29 @@
# Settings specified here will take precedence over those in config/environment.rb R4::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that # 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 # 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! # and recreated between test runs. Don't rely on the data there!
config.cache_classes = true config.cache_classes = true
# Log error messages when you accidentally call methods on nil. # Log error messages when you accidentally call methods on nil.
config.whiny_nils = true config.whiny_nils = true
# Show full error reports and disable caching # Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = false
config.action_view.cache_template_loading = true
# Disable request forgery protection in test environment # Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = false
# Tell Action Mailer not to deliver emails to the real world. # Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
# Use SQL instead of Active Record's schema dumper when creating the test database. # 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, # 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 # like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql # config.active_record.schema_format = :sql
end

View File

@ -3,5 +3,5 @@
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # 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/ } # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying do debug a problem that might steem from framework code. # 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! # Rails.backtrace_cleaner.remove_silencers!

View File

@ -0,0 +1,7 @@
# 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.
ActionController::Base.cookie_verifier_secret = 'cbf6409102b30cb9f4da455ee08c3a7e9d8b2a3d32a0e5b59a354dad03f469d363a8127ef4b7bc3b1afa632d7cf947a1e59e09022d2d4cd8df1f4fa521d7ec07'

View File

@ -2,7 +2,7 @@
# four configuration values can also be set straight in your models. # four configuration values can also be set straight in your models.
Devise.setup do |config| Devise.setup do |config|
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in DeviseMailer.
# config.mailer_sender = "please-change-me@config-initializers-devise.com" config.mailer_sender = "please-change-me@config-initializers-devise.com"
# ==> Configuration for :authenticatable # ==> Configuration for :authenticatable
# Invoke `rake secret` and use the printed value to setup a pepper to generate # Invoke `rake secret` and use the printed value to setup a pepper to generate

View File

@ -0,0 +1,28 @@
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "r4-#{Rails.env}"
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
MongoMapper.connection.connect_to_master if forked
end
end
module MongoMapper::Document::ClassMethods
def key_i18n(key, *options)
VALID_LOCALES.each do |locale|
key "#{key.to_s}_#{locale}".to_sym, *options
end
define_method(key) do
self.send("#{key.to_s}_#{I18n.locale}")
end
define_method("#{key}=") do |value|
VALID_LOCALES.each do |locale|
self.send("#{key.to_s}_#{locale}=", value)
end
end
end
end

View File

@ -6,7 +6,7 @@
# no regular words or you'll be exposed to dictionary attacks. # no regular words or you'll be exposed to dictionary attacks.
ActionController::Base.session = { ActionController::Base.session = {
:key => '_r4_session', :key => '_r4_session',
:secret => '1f062d6db3c797bea2da1ae0c82c0dd952833633fcfdda1e20baca0686bc2bee75aaa0db9ffe67e44655fad008fd1ddc5d670b051c7cf54ac6fa51c16dbe49fd' :secret => '3de7e1b7f4a979950642fd6ebf1a1f67488c568c7e510d7fe9011d6f8ad37e4195bc32aed07167ac7541b7b152d4ffbca73e05bd19d8faddff52b422f3851890'
} }
# Use the database for sessions instead of the cookie-based default, # Use the database for sessions instead of the cookie-based default,

View File

@ -1,4 +1,10 @@
en: en:
errors:
messages:
not_found: "not found"
already_confirmed: "was already confirmed"
not_locked: "was not locked"
devise: devise:
sessions: sessions:
link: 'Sign in' link: 'Sign in'

View File

@ -1,66 +1,90 @@
ActionController::Routing::Routes.draw do |map| R4::Application.routes.draw do |map|
map.resources :announcements resources :announcements
map.namespace :admin do |admin| namespace :admin do
admin.resources :items, :member => { :up => :put, :down => :put } resources :items do
admin.resources :pages member do
admin.resources :links put :up
admin.resources :components put :down
admin.resources :layouts
admin.resources :snippets
admin.resources :assets
end end
map.namespace :panel do |panel|
panel.resources :users
panel.resources :announcements
end end
map.devise_for :users resources :pages
resources :links
resources :components
resources :layouts
resources :snippets
resources :assets
end
# The priority is based upon order of creation: first created -> highest priority. namespace :panel do
resources :users
resources :announcements
end
devise_for :users
# match 'users' => '#index', :as => :devise_for
match '/' => 'pages#index'
match '*page_name' => 'pages#show', :as => :page
# The priority is based upon order of creation:
# first created -> highest priority.
# Sample of regular route: # Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view' # match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action # Keep in mind you can assign values other than :controller and :action
# Sample of named route: # Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
# This route can be invoked with purchase_url(:id => product.id) # This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically): # Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products # resources :products
# Sample resource route with options: # Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } # resources :products do
# member do
# get :short
# post :toggle
# end
#
# collection do
# get :sold
# end
# end
# Sample resource route with sub-resources: # Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller # resources :products do
# resources :comments, :sales
# resource :seller
# end
# Sample resource route with more complex sub-resources # Sample resource route with more complex sub-resources
# map.resources :products do |products| # resources :products do
# products.resources :comments # resources :comments
# products.resources :sales, :collection => { :recent => :get } # resources :sales do
# get :recent, :on => :collection
# end
# end # end
# Sample resource route within a namespace: # Sample resource route within a namespace:
# map.namespace :admin do |admin| # namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) # # Directs /admin/products/* to Admin::ProductsController
# admin.resources :products # # (app/controllers/admin/products_controller.rb)
# resources :products
# end # end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html. # You can have the root of your site routed with "root"
map.root :controller => "pages" # just remember to delete public/index.html.
root :to => "pages#index"
# See how all your routes lay out with "rake routes" # See how all your routes lay out with "rake routes"
# Install the default routes as the lowest priority. # This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: These default routes make all actions in every controller accessible via GET requests. You should # Note: This route will make all actions in every controller accessible via GET requests.
# consider removing the them or commenting them out if you're using named routes and resources. # match ':controller(/:action(/:id(.:format)))'
map.page '*page_name', :controller => 'pages', :action => 'show'
#map.connect ':controller/:action/:id'
#map.connect ':controller/:action/:id.:format'
end end

7
db/seeds.rb Normal file
View File

@ -0,0 +1,7 @@
# 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 File

@ -1,10 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The page you were looking for doesn't exist (404)</title> <title>The page you were looking for doesn't exist (404)</title>
<style type="text/css"> <style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; } body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }

View File

@ -1,10 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>The change you wanted was rejected (422)</title> <title>The change you wanted was rejected (422)</title>
<style type="text/css"> <style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; } body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }

View File

@ -1,10 +1,6 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <!DOCTYPE html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>We're sorry, but something went wrong (500)</title> <title>We're sorry, but something went wrong (500)</title>
<style type="text/css"> <style type="text/css">
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; } body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }

View File

@ -1,10 +1,2 @@
$(document).ready(function(){ // Place your application-specific JavaScript functions and classes here
$.easy.navigation(); // This file is automatically included by javascript_include_tag :defaults
$.easy.tooltip();
$.easy.popup();
$.easy.external();
$.easy.rotate();
$.easy.forms();
$.easy.showhide();
$.easy.jump();
});

126
public/javascripts/rails.js Normal file
View File

@ -0,0 +1,126 @@
jQuery(function ($) {
var csrf_token = $('meta[name=csrf-token]').attr('content'),
csrf_param = $('meta[name=csrf-param]').attr('content');
$.fn.extend({
/**
* Triggers a custom event on an element and returns the event result
* this is used to get around not being able to ensure callbacks are placed
* at the end of the chain.
*
* TODO: deprecate with jQuery 1.4.2 release, in favor of subscribing to our
* own events and placing ourselves at the end of the chain.
*/
triggerAndReturn: function (name, data) {
var event = new $.Event(name);
this.trigger(event, data);
return event.result !== false;
},
/**
* Handles execution of remote calls firing overridable events along the way
*/
callRemote: function () {
var el = this,
data = el.is('form') ? el.serializeArray() : [],
method = el.attr('method') || el.attr('data-method') || 'GET',
url = el.attr('action') || el.attr('href');
if (url === undefined) {
throw "No URL specified for remote call (action or href must be present).";
} else {
if (el.triggerAndReturn('ajax:before')) {
$.ajax({
url: url,
data: data,
dataType: 'script',
type: method.toUpperCase(),
beforeSend: function (xhr) {
el.trigger('ajax:loading', xhr);
},
success: function (data, status, xhr) {
el.trigger('ajax:success', [data, status, xhr]);
},
complete: function (xhr) {
el.trigger('ajax:complete', xhr);
},
error: function (xhr, status, error) {
el.trigger('ajax:failure', [xhr, status, error]);
}
});
}
el.trigger('ajax:after');
}
}
});
/**
* confirmation handler
*/
$('a[data-confirm],input[data-confirm]').live('click', function () {
var el = $(this);
if (el.triggerAndReturn('confirm')) {
if (!confirm(el.attr('data-confirm'))) {
return false;
}
}
});
/**
* remote handlers
*/
$('form[data-remote]').live('submit', function (e) {
$(this).callRemote();
e.preventDefault();
});
$('a[data-remote],input[data-remote]').live('click', function (e) {
$(this).callRemote();
e.preventDefault();
});
$('a[data-method]:not([data-remote])').live('click', function (e){
var link = $(this),
href = link.attr('href'),
method = link.attr('data-method'),
form = $('<form method="post" action="'+href+'">'),
metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
if (csrf_param != null && csrf_token != null) {
metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
}
form.hide()
.append(metadata_input)
.appendTo('body');
e.preventDefault();
form.submit();
});
/**
* disable-with handlers
*/
var disable_with_input_selector = 'input[data-disable-with]';
var disable_with_form_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
$(disable_with_form_selector).live('ajax:before', function () {
$(this).find(disable_with_input_selector).each(function () {
var input = $(this);
input.data('enable-with', input.val())
.attr('value', input.attr('data-disable-with'))
.attr('disabled', 'disabled');
});
});
$(disable_with_form_selector).live('ajax:after', function () {
$(this).find(disable_with_input_selector).each(function () {
var input = $(this);
input.removeAttr('disabled')
.val(input.data('enable-with'));
});
});
});

View File

@ -1,4 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'

10
script/rails Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
ENV_PATH = File.expand_path('../../config/environment', __FILE__)
BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
APP_PATH = File.expand_path('../../config/application', __FILE__)
ROOT_PATH = File.expand_path('../..', __FILE__)
require BOOT_PATH
require 'rails/commands'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'

View File

@ -1,3 +0,0 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'

View File

@ -1,5 +1,5 @@
require 'test_helper' require 'test_helper'
require 'performance_test_help' require 'rails/performance_test_help'
# Profiling results for each test method are written to tmp/performance. # Profiling results for each test method are written to tmp/performance.
class BrowsingTest < ActionController::PerformanceTest class BrowsingTest < ActionController::PerformanceTest

View File

@ -1,33 +1,8 @@
ENV["RAILS_ENV"] = "test" ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help' require 'rails/test_help'
class ActiveSupport::TestCase class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test database remains unchanged so your fixtures don't have to be reloaded
# between every test method. Fewer database queries means faster tests.
#
# Read Mike Clark's excellent walkthrough at
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
#
# Every Active Record database supports transactions except MyISAM tables
# in MySQL. Turn off transactional fixtures in this case; however, if you
# don't care one way or the other, switching from MyISAM to InnoDB tables
# is recommended.
#
# The only drawback to using transactional fixtures is when you actually
# need to test transactions. Since your test is bracketed by a transaction,
# any transactions started in your code will be automatically rolled back.
self.use_transactional_fixtures = true
# Instantiated fixtures are slow, but give you @david where otherwise you
# would need people(:david). If you don't want to migrate your existing
# test cases which use the @david style and don't mind the speed hit (each
# instantiated fixtures translates to a database query per test method),
# then set this back to true.
self.use_instantiated_fixtures = false
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
# #
# Note: You'll currently still have to declare fixtures explicitly in integration tests # Note: You'll currently still have to declare fixtures explicitly in integration tests

View File

@ -1,35 +0,0 @@
SVN
* better approximate scriptaculous effect names
* add support for page[:element_id].visual_effect(:effect) as well as page.visual_effect(:effect, :element_id)
* added a reset form function to jrails.js (stolen from jquery form)
* can now use jquery selectors in all functions
* added javascript_function helper to render inline rjs helpers
* better support for sortable_element
* updated to jquery-ui 1.5.1
0.4.0 (16 June 2008)
* updated to jquery-ui 1.5 & merged js into single file
* Added jQuery.noConflict support
* support for value/val
* additional support for update/delete methods
* support for success/failure hash
* setRequestHeader now gets called globally
* Better support for droppables, sortables
* Add support for prototype AJAX callbacks
* better support for AJAX form calls
0.3.0 (22 Feb 2008)
* updated to jquery-fx 1.0b and jquery-ui 1.5b
* Add text/javascript request header to fix format.js
* Added Tasks (thanks ggarside)
* Improve visual_effects methods
* Fixed some RJS calls
* Fixed observer code for ie
0.2.0 (26 Nov 2007)
* Vastly Improved FX
* Improved Form Observers
* Fixed Rails <= 1.2.6 Compatibility
0.1.0 (15 Nov 2007)
* Initial release

View File

@ -1,21 +0,0 @@
= jRails
jRails is a drop-in jQuery replacement for the Rails Prototype/script.aculo.us helpers.
== Resources
Install
* .script/plugin install http://ennerchi.googlecode.com/svn/trunk/plugins/jrails
Project Site
* http://code.google.com/p/ennerchi/
Web Site
* http://www.ennerchi.com/projects/jrails
Group Site
* http://groups.google.com/group/jrails

View File

@ -1,6 +0,0 @@
# uncomment to use jQuery.noConflict()
#ActionView::Helpers::PrototypeHelper::JQUERY_VAR = 'jQuery'
ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = ['jquery','jquery-ui','jrails']
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
require 'jrails'

View File

@ -1,9 +0,0 @@
# Install hook code here
puts "Copying files..."
dir = "javascripts"
["jquery-ui.js", "jquery.js", "jrails.js"].each do |js_file|
dest_file = File.join(RAILS_ROOT, "public", dir, js_file)
src_file = File.join(File.dirname(__FILE__) , dir, js_file)
FileUtils.cp_r(src_file, dest_file)
end
puts "Files copied - Installation complete!"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
(function($){$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*"})(jQuery);(function($){$.fn.reset=function(){return this.each(function(){if(typeof this.reset=="function"||(typeof this.reset=="object"&&!this.reset.nodeType)){this.reset()}})};$.fn.enable=function(){return this.each(function(){this.disabled=false})};$.fn.disable=function(){return this.each(function(){this.disabled=true})}})(jQuery);(function($){$.extend({fieldEvent:function(el,obs){var field=el[0]||el,e="change";if(field.type=="radio"||field.type=="checkbox"){e="click"}else{if(obs&&field.type=="text"||field.type=="textarea"){e="keyup"}}return e}});$.fn.extend({delayedObserver:function(delay,callback){var el=$(this);if(typeof window.delayedObserverStack=="undefined"){window.delayedObserverStack=[]}if(typeof window.delayedObserverCallback=="undefined"){window.delayedObserverCallback=function(stackPos){observed=window.delayedObserverStack[stackPos];if(observed.timer){clearTimeout(observed.timer)}observed.timer=setTimeout(function(){observed.timer=null;observed.callback(observed.obj,observed.obj.formVal())},observed.delay*1000);observed.oldVal=observed.obj.formVal()}}window.delayedObserverStack.push({obj:el,timer:null,delay:delay,oldVal:el.formVal(),callback:callback});var stackPos=window.delayedObserverStack.length-1;if(el[0].tagName=="FORM"){$(":input",el).each(function(){var field=$(this);field.bind($.fieldEvent(field,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})})}else{el.bind($.fieldEvent(el,delay),function(){observed=window.delayedObserverStack[stackPos];if(observed.obj.formVal()==observed.obj.oldVal){return}else{window.delayedObserverCallback(stackPos)}})}},formVal:function(){var el=this[0];if(el.tagName=="FORM"){return this.serialize()}if(el.type=="checkbox"||self.type=="radio"){return this.filter("input:checked").val()||""}else{return this.val()}}})})(jQuery);(function($){$.fn.extend({visualEffect:function(o){e=o.replace(/\_(.)/g,function(m,l){return l.toUpperCase()});return eval("$(this)."+e+"()")},appear:function(speed,callback){return this.fadeIn(speed,callback)},blindDown:function(speed,callback){return this.show("blind",{direction:"vertical"},speed,callback)},blindUp:function(speed,callback){return this.hide("blind",{direction:"vertical"},speed,callback)},blindRight:function(speed,callback){return this.show("blind",{direction:"horizontal"},speed,callback)},blindLeft:function(speed,callback){this.hide("blind",{direction:"horizontal"},speed,callback);return this},dropOut:function(speed,callback){return this.hide("drop",{direction:"down"},speed,callback)},dropIn:function(speed,callback){return this.show("drop",{direction:"up"},speed,callback)},fade:function(speed,callback){return this.fadeOut(speed,callback)},fadeToggle:function(speed,callback){return this.animate({opacity:"toggle"},speed,callback)},fold:function(speed,callback){return this.hide("fold",{},speed,callback)},foldOut:function(speed,callback){return this.show("fold",{},speed,callback)},grow:function(speed,callback){return this.show("scale",{},speed,callback)},highlight:function(speed,callback){return this.show("highlight",{},speed,callback)},puff:function(speed,callback){return this.hide("puff",{},speed,callback)},pulsate:function(speed,callback){return this.show("pulsate",{},speed,callback)},shake:function(speed,callback){return this.show("shake",{},speed,callback)},shrink:function(speed,callback){return this.hide("scale",{},speed,callback)},squish:function(speed,callback){return this.hide("scale",{origin:["top","left"]},speed,callback)},slideUp:function(speed,callback){return this.hide("slide",{direction:"up"},speed,callback)},slideDown:function(speed,callback){return this.show("slide",{direction:"up"},speed,callback)},switchOff:function(speed,callback){return this.hide("clip",{},speed,callback)},switchOn:function(speed,callback){return this.show("clip",{},speed,callback)}})})(jQuery);

View File

@ -1,192 +0,0 @@
/*
*
* jRails ajax extras
* version 0.1
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.ajaxSettings.accepts._default = "text/javascript, text/html, application/xml, text/xml, */*";
})(jQuery);
/*
*
* jRails form extras
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
// reset a form
$.fn.reset = function() {
return this.each(function() {
// guard against an input with the name of 'reset'
// note that IE reports the reset function as an 'object'
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType))
this.reset();
});
};
// enable a form element
$.fn.enable = function() {
return this.each(function() {
this.disabled = false;
});
};
// disable a form element
$.fn.disable = function() {
return this.each(function() {
this.disabled = true;
});
};
})(jQuery);
/*
*
* jRails form observer plugin
* version 0.2
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.extend({ // Translate field to event
fieldEvent: function(el, obs) {
var field = el[0] || el, e = 'change';
if (field.type == 'radio' || field.type == 'checkbox') e = 'click';
else if (obs && field.type == 'text' || field.type == 'textarea') e = 'keyup';
return e;
}
});
$.fn.extend({ // Delayed observer for fields and forms
delayedObserver: function(delay, callback){
var el = $(this);
if (typeof window.delayedObserverStack == 'undefined') window.delayedObserverStack = [];
if (typeof window.delayedObserverCallback == 'undefined') {
window.delayedObserverCallback = function(stackPos) {
var observed = window.delayedObserverStack[stackPos];
if (observed.timer) clearTimeout(observed.timer);
observed.timer = setTimeout(function(){
observed.timer = null;
observed.callback(observed.obj, observed.obj.formVal());
}, observed.delay * 1000);
observed.oldVal = observed.obj.formVal();
};
}
window.delayedObserverStack.push({
obj: el, timer: null, delay: delay,
oldVal: el.formVal(), callback: callback
});
var stackPos = window.delayedObserverStack.length-1;
if (el[0].tagName == 'FORM') {
$(':input', el).each(function(){
var field = $(this);
field.bind($.fieldEvent(field, delay), function(){
var observed = window.delayedObserverStack[stackPos];
if (observed.obj.formVal() == observed.oldVal) return;
else window.delayedObserverCallback(stackPos);
});
});
} else {
el.bind($.fieldEvent(el, delay), function(){
var observed = window.delayedObserverStack[stackPos];
if (observed.obj.formVal() == observed.oldVal) return;
else window.delayedObserverCallback(stackPos);
});
};
},
formVal: function() { // Gets form values
var el = this[0];
if(el.tagName == 'FORM') return this.serialize();
if(el.type == 'checkbox' || el.type == 'radio') return this.filter('input:checked').val() || '';
else return this.val();
}
});
})(jQuery);
/*
*
* jRails visual effects stubs
* version 0.2
* <aaron@ennerchi.com> | http://www.ennerchi.com
*
*/
(function($) {
$.fn.extend({
visualEffect : function(o) {
e = o.replace(/\_(.)/g, function(m, l){return l.toUpperCase()});
return eval('$(this).'+e+'()');
},
appear : function(speed, callback) {
return this.fadeIn(speed, callback);
},
blindDown : function(speed, callback) {
return this.show('blind', { direction: 'vertical' }, speed, callback);
},
blindUp : function(speed, callback) {
return this.hide('blind', { direction: 'vertical' }, speed, callback);
},
blindRight : function(speed, callback) {
return this.show('blind', { direction: 'horizontal' }, speed, callback);
},
blindLeft : function(speed, callback) {
this.hide('blind', { direction: 'horizontal' }, speed, callback);
return this;
},
dropOut : function(speed, callback) {
return this.hide('drop', {direction: 'down' }, speed, callback);
},
dropIn : function(speed, callback) {
return this.show('drop', { direction: 'up' }, speed, callback);
},
fade : function(speed, callback) {
return this.fadeOut(speed, callback);
},
fadeToggle : function(speed, callback) {
return this.animate({opacity: 'toggle'}, speed, callback);
},
fold : function(speed, callback) {
return this.hide('fold', {}, speed, callback);
},
foldOut : function(speed, callback) {
return this.show('fold', {}, speed, callback);
},
grow : function(speed, callback) {
return this.show('scale', {}, speed, callback);
},
highlight : function(speed, callback) {
return this.show('highlight', {}, speed, callback);
},
puff : function(speed, callback) {
return this.hide('puff', {}, speed, callback);
},
pulsate : function(speed, callback) {
return this.show('pulsate', {}, speed, callback);
},
shake : function(speed, callback) {
return this.show('shake', {}, speed, callback);
},
shrink : function(speed, callback) {
return this.hide('scale', {}, speed, callback);
},
squish : function(speed, callback) {
return this.hide('scale', { origin: ['top', 'left'] }, speed, callback);
},
slideUp : function(speed, callback) {
return this.hide('slide', { direction: 'up'}, speed, callback);
},
slideDown : function(speed, callback) {
return this.show('slide', { direction: 'up'}, speed, callback);
},
switchOff : function(speed, callback) {
return this.hide('clip', {}, speed, callback);
},
switchOn : function(speed, callback) {
return this.show('clip', {}, speed, callback);
}
});
})(jQuery);

View File

@ -1,410 +0,0 @@
module ActionView
module Helpers
module JavaScriptHelper
# This function can be used to render rjs inline
#
# <%= javascript_function do |page|
# page.replace_html :list, :partial => 'list', :object => @list
# end %>
#
def javascript_function(*args, &block)
html_options = args.extract_options!
function = args[0] || ''
html_options.symbolize_keys!
function = update_page(&block) if block_given?
javascript_tag(function)
end
def jquery_id(id)
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
end
def jquery_ids(ids)
Array(ids).map{|id| jquery_id(id)}.join(',')
end
end
module PrototypeHelper
unless const_defined? :JQUERY_VAR
JQUERY_VAR = '$'
end
unless const_defined? :JQCALLBACKS
JQCALLBACKS = Set.new([ :beforeSend, :complete, :error, :success ] + (100..599).to_a)
AJAX_OPTIONS = Set.new([ :before, :after, :condition, :url,
:asynchronous, :method, :insertion, :position,
:form, :with, :update, :script ]).merge(JQCALLBACKS)
end
def periodically_call_remote(options = {})
frequency = options[:frequency] || 10 # every ten seconds by default
code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
javascript_tag(code)
end
def remote_function(options)
javascript_options = options_for_ajax(options)
update = ''
if options[:update] && options[:update].is_a?(Hash)
update = []
update << "success:'#{options[:update][:success]}'" if options[:update][:success]
update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
update = '{' + update.join(',') + '}'
elsif options[:update]
update << "'#{options[:update]}'"
end
function = "#{JQUERY_VAR}.ajax(#{javascript_options})"
function = "#{options[:before]}; #{function}" if options[:before]
function = "#{function}; #{options[:after]}" if options[:after]
function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
return function
end
class JavaScriptGenerator
module GeneratorMethods
def insert_html(position, id, *options_for_render)
insertion = position.to_s.downcase
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").#{insertion}", render(*options_for_render)
end
def replace_html(id, *options_for_render)
insert_html(:html, id, *options_for_render)
end
def replace(id, *options_for_render)
call "#{JQUERY_VAR}(\"#{jquery_id(id)}\").replaceWith", render(*options_for_render)
end
def remove(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").remove"
end
def show(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").show"
end
def hide(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").hide"
end
def toggle(*ids)
call "#{JQUERY_VAR}(\"#{jquery_ids(ids)}\").toggle"
end
def jquery_id(id)
id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
end
def jquery_ids(ids)
Array(ids).map{|id| jquery_id(id)}.join(',')
end
end
end
protected
def options_for_ajax(options)
js_options = build_callbacks(options)
url_options = options[:url]
url_options = url_options.merge(:escape => false) if url_options.is_a?(Hash)
js_options['url'] = "'#{url_for(url_options)}'"
js_options['async'] = false if options[:type] == :synchronous
js_options['type'] = options[:method] ? method_option_to_s(options[:method]) : ( options[:form] ? "'post'" : nil )
js_options['dataType'] = options[:datatype] ? "'#{options[:datatype]}'" : (options[:update] ? nil : "'script'")
if options[:form]
js_options['data'] = "#{JQUERY_VAR}.param(#{JQUERY_VAR}(this).serializeArray())"
elsif options[:submit]
js_options['data'] = "#{JQUERY_VAR}(\"##{options[:submit]} :input\").serialize()"
elsif options[:with]
js_options['data'] = options[:with].gsub("Form.serialize(this.form)","#{JQUERY_VAR}.param(#{JQUERY_VAR}(this.form).serializeArray())")
end
js_options['type'] ||= "'post'"
if options[:method]
if method_option_to_s(options[:method]) == "'put'" || method_option_to_s(options[:method]) == "'delete'"
js_options['type'] = "'post'"
if js_options['data']
js_options['data'] << " + '&"
else
js_options['data'] = "'"
end
js_options['data'] << "_method=#{options[:method]}'"
end
end
if respond_to?('protect_against_forgery?') && protect_against_forgery?
if js_options['data']
js_options['data'] << " + '&"
else
js_options['data'] = "'"
end
js_options['data'] << "#{request_forgery_protection_token}=' + encodeURIComponent('#{escape_javascript form_authenticity_token}')"
end
js_options['data'] = "''" if js_options['type'] == "'post'" && js_options['data'].nil?
options_for_javascript(js_options.reject {|key, value| value.nil?})
end
def build_update_for_success(html_id, insertion=nil)
insertion = build_insertion(insertion)
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request);"
end
def build_update_for_error(html_id, insertion=nil)
insertion = build_insertion(insertion)
"#{JQUERY_VAR}('#{jquery_id(html_id)}').#{insertion}(request.responseText);"
end
def build_insertion(insertion)
insertion = insertion ? insertion.to_s.downcase : 'html'
insertion = 'append' if insertion == 'bottom'
insertion = 'prepend' if insertion == 'top'
insertion
end
def build_observer(klass, name, options = {})
if options[:with] && (options[:with] !~ /[\{=(.]/)
options[:with] = "'#{options[:with]}=' + value"
else
options[:with] ||= 'value' unless options[:function]
end
callback = options[:function] || remote_function(options)
javascript = "#{JQUERY_VAR}('#{jquery_id(name)}').delayedObserver("
javascript << "#{options[:frequency] || 0}, "
javascript << "function(element, value) {"
javascript << "#{callback}}"
#javascript << ", '#{options[:on]}'" if options[:on]
javascript << ")"
javascript_tag(javascript)
end
def build_callbacks(options)
callbacks = {}
options[:beforeSend] = '';
[:uninitialized,:loading,:loaded].each do |key|
options[:beforeSend] << (options[key].last == ';' ? options.delete(key) : options.delete(key) << ';') if options[key]
end
options.delete(:beforeSend) if options[:beforeSend].blank?
options[:error] = options.delete(:failure) if options[:failure]
if options[:update]
if options[:update].is_a?(Hash)
options[:update][:error] = options[:update].delete(:failure) if options[:update][:failure]
if options[:update][:success]
options[:success] = build_update_for_success(options[:update][:success], options[:position]) << (options[:success] ? options[:success] : '')
end
if options[:update][:error]
options[:error] = build_update_for_error(options[:update][:error], options[:position]) << (options[:error] ? options[:error] : '')
end
else
options[:success] = build_update_for_success(options[:update], options[:position]) << (options[:success] ? options[:success] : '')
end
end
options.each do |callback, code|
if JQCALLBACKS.include?(callback)
callbacks[callback] = "function(request){#{code}}"
end
end
callbacks
end
end
class JavaScriptElementProxy < JavaScriptProxy #:nodoc:
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
def initialize(generator, id)
id = id.to_s.count('#.*,>+~:[/ ') == 0 ? "##{id}" : id
@id = id
super(generator, "#{JQUERY_VAR}(\"#{id}\")")
end
def replace_html(*options_for_render)
call 'html', @generator.send(:render, *options_for_render)
end
def replace(*options_for_render)
call 'replaceWith', @generator.send(:render, *options_for_render)
end
def reload(options_for_replace={})
replace(options_for_replace.merge({ :partial => @id.to_s.sub(/^#/,'') }))
end
def value()
call 'val()'
end
def value=(value)
call 'val', value
end
end
class JavaScriptElementCollectionProxy < JavaScriptCollectionProxy #:nodoc:\
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
def initialize(generator, pattern)
super(generator, "#{JQUERY_VAR}(#{pattern.to_json})")
end
end
module ScriptaculousHelper
unless const_defined? :JQUERY_VAR
JQUERY_VAR = ActionView::Helpers::PrototypeHelper::JQUERY_VAR
end
unless const_defined? :SCRIPTACULOUS_EFFECTS
SCRIPTACULOUS_EFFECTS = {
:appear => {:method => 'fadeIn'},
:blind_down => {:method => 'blind', :mode => 'show', :options => {:direction => 'vertical'}},
:blind_up => {:method => 'blind', :mode => 'hide', :options => {:direction => 'vertical'}},
:blind_right => {:method => 'blind', :mode => 'show', :options => {:direction => 'horizontal'}},
:blind_left => {:method => 'blind', :mode => 'hide', :options => {:direction => 'horizontal'}},
:bounce_in => {:method => 'bounce', :mode => 'show', :options => {:direction => 'up'}},
:bounce_out => {:method => 'bounce', :mode => 'hide', :options => {:direction => 'up'}},
:drop_in => {:method => 'drop', :mode => 'show', :options => {:direction => 'up'}},
:drop_out => {:method => 'drop', :mode => 'hide', :options => {:direction => 'down'}},
:fade => {:method => 'fadeOut'},
:fold_in => {:method => 'fold', :mode => 'hide'},
:fold_out => {:method => 'fold', :mode => 'show'},
:grow => {:method => 'scale', :mode => 'show'},
:shrink => {:method => 'scale', :mode => 'hide'},
:slide_down => {:method => 'slide', :mode => 'show', :options => {:direction => 'up'}},
:slide_up => {:method => 'slide', :mode => 'hide', :options => {:direction => 'up'}},
:slide_right => {:method => 'slide', :mode => 'show', :options => {:direction => 'left'}},
:slide_left => {:method => 'slide', :mode => 'hide', :options => {:direction => 'left'}},
:squish => {:method => 'scale', :mode => 'hide', :options => {:origin => "['top','left']"}},
:switch_on => {:method => 'clip', :mode => 'show', :options => {:direction => 'vertical'}},
:switch_off => {:method => 'clip', :mode => 'hide', :options => {:direction => 'vertical'}},
:toggle_appear => {:method => 'fadeToggle'},
:toggle_slide => {:method => 'slide', :mode => 'toggle', :options => {:direction => 'up'}},
:toggle_blind => {:method => 'blind', :mode => 'toggle', :options => {:direction => 'vertical'}},
}
end
def visual_effect(name, element_id = false, js_options = {})
element = element_id ? element_id : "this"
if SCRIPTACULOUS_EFFECTS.has_key? name.to_sym
effect = SCRIPTACULOUS_EFFECTS[name.to_sym]
name = effect[:method]
mode = effect[:mode]
js_options = js_options.merge(effect[:options]) if effect[:options]
end
[:color, :direction].each do |option|
js_options[option] = "'#{js_options[option]}'" if js_options[option]
end
if js_options.has_key? :duration
speed = js_options.delete :duration
speed = (speed * 1000).to_i unless speed.nil?
else
speed = js_options.delete :speed
end
if ['fadeIn','fadeOut','fadeToggle'].include?(name)
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{name}("
javascript << "#{speed}" unless speed.nil?
javascript << ");"
else
javascript = "#{JQUERY_VAR}('#{jquery_id(element_id)}').#{mode || 'effect'}('#{name}'"
javascript << ",#{options_for_javascript(js_options)}" unless speed.nil? && js_options.empty?
javascript << ",#{speed}" unless speed.nil?
javascript << ");"
end
end
def sortable_element_js(element_id, options = {}) #:nodoc:
#convert similar attributes
options[:handle] = ".#{options[:handle]}" if options[:handle]
if options[:tag] || options[:only]
options[:items] = "> "
options[:items] << options.delete(:tag) if options[:tag]
options[:items] << ".#{options.delete(:only)}" if options[:only]
end
options[:connectWith] = options.delete(:containment).map {|x| "##{x}"} if options[:containment]
options[:containment] = options.delete(:container) if options[:container]
options[:dropOnEmpty] = false unless options[:dropOnEmpty]
options[:helper] = "'clone'" if options[:ghosting] == true
options[:axis] = case options.delete(:constraint)
when "vertical"
"y"
when "horizontal"
"x"
when false
nil
when nil
"y"
end
options.delete(:axis) if options[:axis].nil?
options.delete(:overlap)
options.delete(:ghosting)
if options[:onUpdate] || options[:url]
options[:with] ||= "#{JQUERY_VAR}(this).sortable('serialize',{key:'#{element_id}[]'})"
options[:onUpdate] ||= "function(){" + remote_function(options) + "}"
end
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
options[:update] = options.delete(:onUpdate) if options[:onUpdate]
[:axis, :cancel, :containment, :cursor, :handle, :tolerance, :items, :placeholder].each do |option|
options[option] = "'#{options[option]}'" if options[option]
end
options[:connectWith] = array_or_string_for_javascript(options[:connectWith]) if options[:connectWith]
%(#{JQUERY_VAR}('#{jquery_id(element_id)}').sortable(#{options_for_javascript(options)});)
end
def draggable_element_js(element_id, options = {})
%(#{JQUERY_VAR}("#{jquery_id(element_id)}").draggable(#{options_for_javascript(options)});)
end
def drop_receiving_element_js(element_id, options = {})
#convert similar options
options[:hoverClass] = options.delete(:hoverclass) if options[:hoverclass]
options[:drop] = options.delete(:onDrop) if options[:onDrop]
if options[:drop] || options[:url]
options[:with] ||= "'id=' + encodeURIComponent(#{JQUERY_VAR}(ui.draggable).attr('id'))"
options[:drop] ||= "function(ev, ui){" + remote_function(options) + "}"
end
options.delete_if { |key, value| PrototypeHelper::AJAX_OPTIONS.include?(key) }
options[:accept] = array_or_string_for_javascript(options[:accept]) if options[:accept]
[:activeClass, :hoverClass, :tolerance].each do |option|
options[option] = "'#{options[option]}'" if options[option]
end
%(#{JQUERY_VAR}('#{jquery_id(element_id)}').droppable(#{options_for_javascript(options)});)
end
end
end
end

View File

@ -1,19 +0,0 @@
namespace :jrails do
namespace :update do
desc "Copies the jQuery and jRails javascripts to public/javascripts"
task :javascripts do
puts "Copying files..."
project_dir = RAILS_ROOT + '/public/javascripts/'
scripts = Dir[File.join(File.dirname(__FILE__), '..') + '/javascripts/*.js']
FileUtils.cp(scripts, project_dir)
puts "files copied successfully."
end
end
namespace :install do
desc "Installs the jQuery and jRails javascripts to public/javascripts"
task :javascripts do
Rake::Task['jrails:update:javascripts'].invoke
end
end
end