diff --git a/Rakefile b/Rakefile index 3bb0e859..9cb20464 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,10 @@ # 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.join(File.dirname(__FILE__), 'config', 'boot')) +require File.expand_path('../config/application', __FILE__) require 'rake' require 'rake/testtask' require 'rake/rdoctask' -require 'tasks/rails' +Rails::Application.load_tasks diff --git a/config.ru b/config.ru new file mode 100644 index 00000000..99c91ddb --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Cybook::Application diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 00000000..51bd6eb6 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,46 @@ +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 Cybook + 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. + + # 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 = '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 + + # 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 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 diff --git a/config/boot.rb b/config/boot.rb old mode 100755 new mode 100644 index 0a516880..712b0981 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,109 +1,6 @@ -# Don't change this file! -# Configure your app in config/environment.rb and config/environments/*.rb - -RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) - -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) - 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' - min_version = '1.3.1' - unless rubygems_version >= min_version - $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) - exit 1 - end - - rescue LoadError - $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) - exit 1 - end - - def parse_gem_version(text) - $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ - end - - private - def read_environment_rb - File.read("#{RAILS_ROOT}/config/environment.rb") - end - end - end +require 'rubygems' +# Set up gems listed in the Gemfile. +if File.exist?(File.expand_path('../../Gemfile', __FILE__)) + require 'bundler' + Bundler.setup end - -# All that for this: -Rails.boot! diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb new file mode 100644 index 00000000..59385cdf --- /dev/null +++ b/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# 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! diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb new file mode 100644 index 00000000..408f9556 --- /dev/null +++ b/config/initializers/secret_token.rb @@ -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. +Rails.application.config.secret_token = '91d4505d90462738e1e527573148912e9f76eca5dad96739af1ea86cf407220a3a3e4b8d527fea0c70997e2f97f97e8eae7d32e077729a89c392c102e655653a' diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb new file mode 100644 index 00000000..92856855 --- /dev/null +++ b/config/initializers/session_store.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, :key => '_cybook_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 "rake db:sessions:create") +# Rails.application.config.session_store :active_record_store diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 00000000..a747bfa6 --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,5 @@ +# 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" diff --git a/lib/tasks/.gitkeep b/lib/tasks/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/public/404.html b/public/404.html index 0e184561..9a48320a 100644 --- a/public/404.html +++ b/public/404.html @@ -1,8 +1,26 @@ - + + + The page you were looking for doesn't exist (404) + + + -

File not found

-

Change this error message for pages not found in public/404.html

+ +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
- \ No newline at end of file + diff --git a/public/422.html b/public/422.html new file mode 100644 index 00000000..83660ab1 --- /dev/null +++ b/public/422.html @@ -0,0 +1,26 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+ + diff --git a/public/500.html b/public/500.html index ab95f74c..b80307fc 100644 --- a/public/500.html +++ b/public/500.html @@ -1,8 +1,26 @@ - + + + We're sorry, but something went wrong (500) + + + -

Application error

-

Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html

+ +
+

We're sorry, but something went wrong.

+

We've been notified about this issue and we'll take a look at it shortly.

+
- \ No newline at end of file + diff --git a/public/javascripts/rails.js b/public/javascripts/rails.js new file mode 100644 index 00000000..c5fa02ae --- /dev/null +++ b/public/javascripts/rails.js @@ -0,0 +1,118 @@ +document.observe("dom:loaded", function() { + function handleRemote(element) { + var method, url, params; + + if (element.tagName.toLowerCase() === 'form') { + method = element.readAttribute('method') || 'post'; + url = element.readAttribute('action'); + params = element.serialize(true); + } else { + method = element.readAttribute('data-method') || 'get'; + url = element.readAttribute('href'); + params = {}; + } + + var event = element.fire("ajax:before"); + if (event.stopped) return false; + + new Ajax.Request(url, { + method: method, + parameters: params, + asynchronous: true, + evalScripts: true, + + onLoading: function(request) { element.fire("ajax:loading", {request: request}); }, + onLoaded: function(request) { element.fire("ajax:loaded", {request: request}); }, + onInteractive: function(request) { element.fire("ajax:interactive", {request: request}); }, + onComplete: function(request) { element.fire("ajax:complete", {request: request}); }, + onSuccess: function(request) { element.fire("ajax:success", {request: request}); }, + onFailure: function(request) { element.fire("ajax:failure", {request: request}); } + }); + + element.fire("ajax:after"); + } + + function handleMethod(element) { + var method, url, token_name, token; + + method = element.readAttribute('data-method'); + url = element.readAttribute('href'); + csrf_param = $$('meta[name=csrf-param]').first(); + csrf_token = $$('meta[name=csrf-token]').first(); + + var form = new Element('form', { method: "POST", action: url, style: "display: none;" }); + element.parentNode.appendChild(form); + + if (method != 'post') { + var field = new Element('input', { type: 'hidden', name: '_method', value: method }); + form.appendChild(field); + } + + if (csrf_param) { + var param = csrf_param.readAttribute('content'); + var token = csrf_token.readAttribute('content'); + var field = new Element('input', { type: 'hidden', name: param, value: token }); + form.appendChild(field); + } + + form.submit(); + } + + $(document.body).observe("click", function(event) { + var message = event.findElement().readAttribute('data-confirm'); + if (message && !confirm(message)) { + event.stop(); + return false; + } + + var element = event.findElement("a[data-remote]"); + if (element) { + handleRemote(element); + event.stop(); + return true; + } + + var element = event.findElement("a[data-method]"); + if (element) { + handleMethod(element); + event.stop(); + return true; + } + }); + + // TODO: I don't think submit bubbles in IE + $(document.body).observe("submit", function(event) { + var element = event.findElement(), + message = element.readAttribute('data-confirm'); + if (message && !confirm(message)) { + event.stop(); + return false; + } + + var inputs = element.select("input[type=submit][data-disable-with]"); + inputs.each(function(input) { + input.disabled = true; + input.writeAttribute('data-original-value', input.value); + input.value = input.readAttribute('data-disable-with'); + }); + + var element = event.findElement("form[data-remote]"); + if (element) { + handleRemote(element); + event.stop(); + } + }); + + $(document.body).observe("ajax:after", function(event) { + var element = event.findElement(); + + if (element.tagName.toLowerCase() === 'form') { + var inputs = element.select("input[type=submit][disabled=true][data-disable-with]"); + inputs.each(function(input) { + input.value = input.readAttribute('data-original-value'); + input.writeAttribute('data-original-value', null); + input.disabled = false; + }); + } + }); +}); \ No newline at end of file diff --git a/script/rails b/script/rails new file mode 100755 index 00000000..9eb79100 --- /dev/null +++ b/script/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby1.8 +# 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__) + +require BOOT_PATH +require 'rails/commands'