Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8 from fotioslindiakos/rails_32

Created new quickstart for Rails 3.2

Merging this at fotios request
  • Loading branch information...
commit 9438670429c8d598c11c681c7f0948520901bb45 2 parents 5594086 + 4b174ee
kwoodson authored
Showing with 672 additions and 10,009 deletions.
  1. +15 −5 .gitignore
  2. +1 −1  .openshift/action_hooks/build
  3. +1 −1  .openshift/action_hooks/deploy
  4. +2 −2 .openshift/action_hooks/post_deploy
  5. +14 −0 .openshift/action_hooks/post_start_ruby-1.9
  6. +14 −0 .openshift/action_hooks/post_stop_ruby-1.9
  7. +19 −2 .openshift/action_hooks/pre_build
  8. +14 −0 .openshift/action_hooks/pre_start_ruby-1.9
  9. +14 −0 .openshift/action_hooks/pre_stop_ruby-1.9
  10. +22 −0 .openshift/cron/README.cron
  11. 0  public/stylesheets/.gitkeep → .openshift/cron/daily/.gitignore
  12. 0  public/.gitkeep → .openshift/cron/hourly/.gitignore
  13. 0  .openshift/cron/minutely/.gitignore
  14. 0  .openshift/cron/monthly/.gitignore
  15. +16 −0 .openshift/cron/weekly/README
  16. +1 −0  .openshift/cron/weekly/chrono.dat
  17. +3 −0  .openshift/cron/weekly/chronograph
  18. +12 −0 .openshift/cron/weekly/jobs.allow
  19. +7 −0 .openshift/cron/weekly/jobs.deny
  20. +3 −3 .openshift/markers/README
  21. +33 −20 Gemfile
  22. +76 −51 Gemfile.lock
  23. +0 −60 README
  24. +85 −42 README.md
  25. +2 −2 Rakefile
  26. 0  {public → app/assets}/images/rails.png
  27. +15 −0 app/assets/javascripts/application.js
  28. +13 −0 app/assets/stylesheets/application.css
  29. +0 −5 app/controllers/home_controller.rb
  30. +0 −83 app/controllers/posts_controller.rb
  31. +0 −2  app/helpers/home_helper.rb
  32. +0 −2  app/helpers/posts_helper.rb
  33. 0  app/mailers/.gitkeep
  34. 0  app/models/.gitkeep
  35. +0 −2  app/models/post.rb
  36. +0 −2  app/views/home/index.html.erb
  37. +4 −4 app/views/layouts/application.html.erb
  38. +0 −29 app/views/posts/_form.html.erb
  39. +0 −6 app/views/posts/edit.html.erb
  40. +0 −27 app/views/posts/index.html.erb
  41. +0 −5 app/views/posts/new.html.erb
  42. +0 −20 app/views/posts/show.html.erb
  43. +1 −1  config.ru
  44. +27 −7 config/application.rb
  45. +8 −14 config/database.yml
  46. +0 −22 config/database.yml.sqlite3
  47. +1 −1  config/environment.rb
  48. +16 −5 config/environments/development.rb
  49. +32 −14 config/environments/production.rb
  50. +10 −8 config/environments/test.rb
  51. +5 −0 config/initializers/inflections.rb
  52. +1 −8 config/initializers/secret_token.rb
  53. +2 −8 config/initializers/session_store.rb
  54. +14 −0 config/initializers/wrap_parameters.rb
  55. +1 −1  config/locales/en.yml
  56. +3 −8 config/routes.rb
  57. +0 −15 db/migrate/20110810175718_create_posts.rb
  58. +2 −2 db/seeds.rb
  59. 0  lib/assets/.gitkeep
  60. +0 −31 lib/openshift_secret_generator.rb
  61. 0  log/.gitkeep
  62. +0 −1  public/500.html
  63. +158 −0 public/index.html
  64. +0 −2  public/javascripts/application.js
  65. +0 −965 public/javascripts/controls.js
  66. +0 −974 public/javascripts/dragdrop.js
  67. +0 −1,123 public/javascripts/effects.js
  68. +0 −6,001 public/javascripts/prototype.js
  69. +0 −191 public/javascripts/rails.js
  70. +0 −56 public/stylesheets/scaffold.css
  71. +1 −1  script/rails
  72. 0  test/fixtures/.gitkeep
  73. +0 −11 test/fixtures/posts.yml
  74. 0  test/functional/.gitkeep
  75. +0 −9 test/functional/home_controller_test.rb
  76. +0 −49 test/functional/posts_controller_test.rb
  77. 0  test/integration/.gitkeep
  78. +4 −1 test/performance/browsing_test.rb
  79. 0  test/unit/.gitkeep
  80. +0 −4 test/unit/helpers/home_helper_test.rb
  81. +0 −4 test/unit/helpers/posts_helper_test.rb
  82. +0 −88 test/unit/helpers/secret_generator_test.rb
  83. +0 −8 test/unit/post_test.rb
  84. 0  vendor/assets/javascripts/.gitkeep
  85. 0  vendor/assets/stylesheets/.gitkeep
View
20 .gitignore
@@ -1,5 +1,15 @@
-.bundle
-db/*.sqlite3
-log/*.log
-tmp/
-.project
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+#
+# If you find yourself ignoring temporary files generated by your text editor
+# or operating system, you probably want to add a global ignore instead:
+# git config --global core.excludesfile ~/.gitignore_global
+
+# Ignore bundler config
+/.bundle
+
+# Ignore the default SQLite database.
+/db/*.sqlite3
+
+# Ignore all logfiles and tempfiles.
+/log/*.log
+/tmp
View
2  .openshift/action_hooks/build
@@ -1,5 +1,5 @@
#!/bin/bash
-# This is a simple build script and will be executed on your CI system if
+# This is a simple build script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the deploy step. This script gets executed directly, so it
# could be python, php, ruby, etc.
View
2  .openshift/action_hooks/deploy
@@ -42,4 +42,4 @@ fi
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
bundle exec rake db:migrate RAILS_ENV="production"
-popd > /dev/null
+popd > /dev/null
View
4 .openshift/action_hooks/post_deploy
@@ -1,4 +1,4 @@
#!/bin/bash
-# This is a simple post deploy hook executed after your application
+# This is a simple post deploy hook executed after your application
# is deployed and started. This script gets executed directly, so
-# it could be python, php, ruby, etc.
+# it could be python, php, ruby, etc.
View
14 .openshift/action_hooks/post_start_ruby-1.9
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
+# immediately before (re)starting or stopping the specified cartridge.
+# They are able to make any desired environment variable changes as
+# well as other adjustments to the application environment.
+
+# The post_start_cartridge and post_stop_cartridge hooks are executed
+# immediately after (re)starting or stopping the specified cartridge.
+
+# Exercise caution when adding commands to these hooks. They can
+# prevent your application from stopping cleanly or starting at all.
+# Application start and stop is subject to different timeouts
+# throughout the system.
View
14 .openshift/action_hooks/post_stop_ruby-1.9
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
+# immediately before (re)starting or stopping the specified cartridge.
+# They are able to make any desired environment variable changes as
+# well as other adjustments to the application environment.
+
+# The post_start_cartridge and post_stop_cartridge hooks are executed
+# immediately after (re)starting or stopping the specified cartridge.
+
+# Exercise caution when adding commands to these hooks. They can
+# prevent your application from stopping cleanly or starting at all.
+# Application start and stop is subject to different timeouts
+# throughout the system.
View
21 .openshift/action_hooks/pre_build
@@ -1,5 +1,22 @@
#!/bin/bash
-# This is a simple script and will be executed on your CI system if
+# This is a simple script and will be executed on your CI system if
# available. Otherwise it will execute while your application is stopped
# before the build step. This script gets executed directly, so it
-# could be python, php, ruby, etc.
+# could be python, php, ruby, etc.
+
+data="${OPENSHIFT_DATA_DIR}/assets"
+assets="${OPENSHIFT_REPO_DIR}/public"
+
+# Make the data directory if it doesn't exist
+if [ ! -d "$data" ]; then
+ mkdir $data;
+fi
+
+# Remove the assets directory if it's empty
+find $assets/assets -maxdepth 0 -type d -empty -delete 2> /dev/null
+
+# Try to make the symlink
+ln -s $data $assets 2> /dev/null
+if [ $? -gt 0 ]; then
+ echo "Unable to create symlink to assets directory, using existing directory in repository"
+fi
View
14 .openshift/action_hooks/pre_start_ruby-1.9
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
+# immediately before (re)starting or stopping the specified cartridge.
+# They are able to make any desired environment variable changes as
+# well as other adjustments to the application environment.
+
+# The post_start_cartridge and post_stop_cartridge hooks are executed
+# immediately after (re)starting or stopping the specified cartridge.
+
+# Exercise caution when adding commands to these hooks. They can
+# prevent your application from stopping cleanly or starting at all.
+# Application start and stop is subject to different timeouts
+# throughout the system.
View
14 .openshift/action_hooks/pre_stop_ruby-1.9
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# The pre_start_cartridge and pre_stop_cartridge hooks are *SOURCED*
+# immediately before (re)starting or stopping the specified cartridge.
+# They are able to make any desired environment variable changes as
+# well as other adjustments to the application environment.
+
+# The post_start_cartridge and post_stop_cartridge hooks are executed
+# immediately after (re)starting or stopping the specified cartridge.
+
+# Exercise caution when adding commands to these hooks. They can
+# prevent your application from stopping cleanly or starting at all.
+# Application start and stop is subject to different timeouts
+# throughout the system.
View
22 .openshift/cron/README.cron
@@ -0,0 +1,22 @@
+Run scripts or jobs on a periodic basis
+=======================================
+Any scripts or jobs added to the minutely, hourly, daily, weekly or monthly
+directories will be run on a scheduled basis (frequency is as indicated by the
+name of the directory) using run-parts.
+
+run-parts ignores any files that are hidden or dotfiles (.*) or backup
+files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved}
+
+The presence of two specially named files jobs.deny and jobs.allow controls
+how run-parts executes your scripts/jobs.
+ jobs.deny ===> Prevents specific scripts or jobs from being executed.
+ jobs.allow ===> Only execute the named scripts or jobs (all other/non-named
+ scripts that exist in this directory are ignored).
+
+The principles of jobs.deny and jobs.allow are the same as those of cron.deny
+and cron.allow and are described in detail at:
+ http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/ch-Automating_System_Tasks.html#s2-autotasks-cron-access
+
+See: man crontab or above link for more details and see the the weekly/
+ directory for an example.
+
View
0  public/stylesheets/.gitkeep → .openshift/cron/daily/.gitignore
File renamed without changes
View
0  public/.gitkeep → .openshift/cron/hourly/.gitignore
File renamed without changes
View
0  .openshift/cron/minutely/.gitignore
No changes.
View
0  .openshift/cron/monthly/.gitignore
No changes.
View
16 .openshift/cron/weekly/README
@@ -0,0 +1,16 @@
+Run scripts or jobs on a weekly basis
+=====================================
+Any scripts or jobs added to this directory will be run on a scheduled basis
+(weekly) using run-parts.
+
+run-parts ignores any files that are hidden or dotfiles (.*) or backup
+files (*~ or *,) or named *.{rpmsave,rpmorig,rpmnew,swp,cfsaved} and handles
+the files named jobs.deny and jobs.allow specially.
+
+In this specific example, the chronograph script is the only script or job file
+executed on a weekly basis (due to white-listing it in jobs.allow). And the
+README and chrono.dat file are ignored either as a result of being black-listed
+in jobs.deny or because they are NOT white-listed in the jobs.allow file.
+
+For more details, please see ../README.cron file.
+
View
1  .openshift/cron/weekly/chrono.dat
@@ -0,0 +1 @@
+Time And Relative D...n In Execution (Open)Shift!
View
3  .openshift/cron/weekly/chronograph
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "`date`: `cat $(dirname \"$0\")/chrono.dat`"
View
12 .openshift/cron/weekly/jobs.allow
@@ -0,0 +1,12 @@
+#
+# Script or job files listed in here (one entry per line) will be
+# executed on a weekly-basis.
+#
+# Example: The chronograph script will be executed weekly but the README
+# and chrono.dat files in this directory will be ignored.
+#
+# The README file is actually ignored due to the entry in the
+# jobs.deny which is checked before jobs.allow (this file).
+#
+chronograph
+
View
7 .openshift/cron/weekly/jobs.deny
@@ -0,0 +1,7 @@
+#
+# Any script or job files listed in here (one entry per line) will NOT be
+# executed (read as ignored by run-parts).
+#
+
+README
+
View
6 .openshift/markers/README
@@ -3,6 +3,6 @@ Markers
Adding marker files to this directory will have the following effects:
-force_clean_build - Previous output from bundle install --deployment will be
- removed and all gems will be reinstalled according to the current
- Gemfile/Gemfile.lock.
+force_clean_build - Previous output from bundle install --deployment will be
+ removed and all gems will be reinstalled according to the current
+ Gemfile/Gemfile.lock.
View
53 Gemfile
@@ -1,33 +1,46 @@
source 'http://mirror1.prod.rhcloud.com/mirror/ruby/'
-source :rubygems
+source 'https://rubygems.org'
-gem 'rails', '3.1.1'
+gem 'rails', '3.2.6'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
+gem 'mysql2'
gem 'sqlite3'
-gem 'mysql'
-# Use unicorn as the web server
+
+# Gems used only for assets and not required
+# in production environments by default.
+group :assets do
+ gem 'sass-rails', '~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
+ # gem 'therubyracer', :platforms => :ruby
+
+ gem 'uglifier', '>= 1.0.3'
+end
+
+gem 'jquery-rails'
+
+# To use ActiveModel has_secure_password
+# gem 'bcrypt-ruby', '~> 3.0.0'
+
+# To use Jbuilder templates for JSON
+# gem 'jbuilder'
+
+# Use unicorn as the app 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', :require => 'ruby-debug'
-
-# Bundle the extra gems:
-# gem 'bj'
-# gem 'nokogiri'
-# gem 'sqlite3-ruby', :require => 'sqlite3'
-# gem 'aws-s3', :require => 'aws/s3'
-
-# 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
+# To use debugger
+# gem 'debugger'
+
+# This version needs to be hardcoded for OpenShift compatability
+gem 'thor', '= 0.14.6'
+
+# This needs to be installed so we can run Rails console on OpenShift directly
+gem 'minitest'
View
127 Gemfile.lock
@@ -1,92 +1,117 @@
GEM
remote: http://mirror1.prod.rhcloud.com/mirror/ruby/
- remote: http://rubygems.org/
+ remote: https://rubygems.org/
specs:
- actionmailer (3.1.1)
- actionpack (= 3.1.1)
- mail (~> 2.3.0)
- actionpack (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
+ actionmailer (3.2.6)
+ actionpack (= 3.2.6)
+ mail (~> 2.4.4)
+ actionpack (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
builder (~> 3.0.0)
erubis (~> 2.7.0)
- i18n (~> 0.6)
- rack (~> 1.3.2)
- rack-cache (~> 1.1)
- rack-mount (~> 0.8.2)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
rack-test (~> 0.6.1)
- sprockets (~> 2.0.2)
- activemodel (3.1.1)
- activesupport (= 3.1.1)
+ sprockets (~> 2.1.3)
+ activemodel (3.2.6)
+ activesupport (= 3.2.6)
builder (~> 3.0.0)
- i18n (~> 0.6)
- activerecord (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
- arel (~> 2.2.1)
+ activerecord (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ arel (~> 3.0.2)
tzinfo (~> 0.3.29)
- activeresource (3.1.1)
- activemodel (= 3.1.1)
- activesupport (= 3.1.1)
- activesupport (3.1.1)
+ activeresource (3.2.6)
+ activemodel (= 3.2.6)
+ activesupport (= 3.2.6)
+ activesupport (3.2.6)
+ i18n (~> 0.6)
multi_json (~> 1.0)
- arel (2.2.1)
+ arel (3.0.2)
builder (3.0.0)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.3.3)
erubis (2.7.0)
+ execjs (1.4.0)
+ multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
- json (1.6.1)
- mail (2.3.0)
+ journey (1.0.4)
+ jquery-rails (2.0.2)
+ railties (>= 3.2.0, < 5.0)
+ thor (~> 0.14)
+ json (1.7.3)
+ mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
- mime-types (1.17.2)
- multi_json (1.0.3)
- mysql (2.8.1)
+ mime-types (1.19)
+ minitest (3.2.0)
+ multi_json (1.3.6)
+ mysql2 (0.3.11)
polyglot (0.3.3)
- rack (1.3.5)
- rack-cache (1.1)
+ rack (1.4.1)
+ rack-cache (1.2)
rack (>= 0.4)
- rack-mount (0.8.3)
- rack (>= 1.0.0)
rack-ssl (1.3.2)
rack
rack-test (0.6.1)
rack (>= 1.0)
- rails (3.1.1)
- actionmailer (= 3.1.1)
- actionpack (= 3.1.1)
- activerecord (= 3.1.1)
- activeresource (= 3.1.1)
- activesupport (= 3.1.1)
+ rails (3.2.6)
+ actionmailer (= 3.2.6)
+ actionpack (= 3.2.6)
+ activerecord (= 3.2.6)
+ activeresource (= 3.2.6)
+ activesupport (= 3.2.6)
bundler (~> 1.0)
- railties (= 3.1.1)
- railties (3.1.1)
- actionpack (= 3.1.1)
- activesupport (= 3.1.1)
+ railties (= 3.2.6)
+ railties (3.2.6)
+ actionpack (= 3.2.6)
+ activesupport (= 3.2.6)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
- thor (~> 0.14.6)
+ thor (>= 0.14.6, < 2.0)
rake (0.9.2.2)
- rdoc (3.11)
+ rdoc (3.12)
json (~> 1.4)
- sprockets (2.0.3)
+ sass (3.1.20)
+ sass-rails (3.2.5)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
- sqlite3 (1.3.4)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.31)
+ tzinfo (0.3.33)
+ uglifier (1.2.6)
+ execjs (>= 0.3.0)
+ multi_json (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
- mysql
- rails (= 3.1.1)
+ coffee-rails (~> 3.2.1)
+ jquery-rails
+ minitest
+ mysql2
+ rails (= 3.2.6)
+ sass-rails (~> 3.2.3)
sqlite3
+ thor (= 0.14.6)
+ uglifier (>= 1.0.3)
View
60 README
@@ -1,60 +0,0 @@
-Rails Sample App on OpenShift
-=========================
-
-Quickstart rails application for openshift.
-
-Running on OpenShift
---------------------
-
-Create an account at http://openshift.redhat.com/
-
-Create a rails application
-
- rhc app create -a railsapp -t ruby-1.8
-
-Add mysql support to your application
-
- rhc app cartridge add -a railsapp -c mysql-5.1
-
-Add this upstream rails quickstart repo
-
- cd railsapp
- git remote add upstream -m master git://github.com/openshift/rails-example.git
- git pull -s recursive -X theirs upstream master
-
-Then push the repo upstream
-
- git push
-
-That's it, you can now checkout your application at:
-
- http://railsapp-$yourlogin.rhcloud.com
-
-Security Considerations
------------------------
-This repository contains configuration files with security related variables.
-
-Since this is a shared repository, any applications derived from it will share those variables, thus reducing the security of your application.
-
-You should follow the directions below and push your updated files to OpenShift immediately.
-
-### Procedure
-
-The following table lists files and variables that should be changed.
-
-These values can be replaced by the output of `rake secret`, which generates a securely random 128 character string.
-
-<table>
- <tr>
- <th>File</th>
- <th>Variable</th>
- </tr>
- <tr>
- <td>config/initializers/secret_token.rb</td>
- <td>Railsapp::Application.config.secret_token</td>
- </tr>
- <tr>
- <td>config/initializers/session_store.rb</td>
- <td>Railsapp::Application.config.session_store</td>
- </tr>
-</table>
View
127 README.md
@@ -1,60 +1,103 @@
-Rails Sample App on OpenShift
-=========================
-
+# Rails Sample App on OpenShift #
Quickstart rails application for openshift.
-Running on OpenShift
---------------------
+The easiest way to install this application is to use the [OpenShift
+Instant Application][template]. If you'd like to install it
+manually, follow [these directions](#manual-installation).
+
+## OpenShift Considerations ##
+These are some special considerations you may need to keep in mind when
+running your application on OpenShift.
+
+### Database ###
+Your application is configured to use your OpenShift database in
+Production mode.
+Because it addresses these databases based on [OpenShift Environment
+Variables](http://red.ht/NvNoXC), you will need to change these if you
+want to use your application in Production mode outside of
+OpenShift.
+
+### Assets ###
+Your application is set to precompile the assets every time you push
+to OpenShift, so there is no need to store them in your git repository!
+
+Since your repository is non-persistent, we cannot store them directly
+in `public/assets` (which is the default location), because it would be
+overwritten the next time you pushed your application.
+Instead, we create a symlink from your persistent
+`$OPENSHIFT_DATA_DIR/assets` into your `public` folder, which Rails will
+then use.
+
+If you need to store your precompiled assets in your repository, you
+will need to modify your `.openshift/action_hooks/pre_build` to NOT
+create the symlink, otherwise it will overwrite your `public/assets`
+folder.
+
+### Security ###
+Since these quickstarts are shared code, we had to take special
+consideration to ensure that security related configuration variables
+was unique across applications.
+To accomplish this, we modified some of the configuration files (shown
+in the table below).
+Now instead of using the same default values, your application will
+generate it's own value using the `initialize_secret` function from `lib/openshift_secret_generator.rb`.
+
+This function uses a secure environment variable that only exists on
+your deployed application and not in your code anywhere.
+You can then use the function to generate any variables you need.
+Each of them will be unique so `initialize_secret(:a)` will differ
+from `initialize_secret(:b)` but they will also be consistent, so any
+time your application uses them (even across reboots), you know they
+will be the same.
+
+##### Modified Files #####
-Create an account at http://openshift.redhat.com/
+<table>
+ <tr>
+ <th>File</th>
+ <th>Variable</th>
+ </tr>
+ <tr>
+ <td>config/initializers/secret_token.rb</td>
+ <td>Railsapp::Application.config.secret_token</td>
+ </tr>
+ <tr>
+ <td>config/initializers/session_store.rb</td>
+ <td>Railsapp::Application.config.session_store</td>
+ </tr>
+</table>
-Create a rails application
+## Manual Installation ##
- rhc app create -a railsapp -t ruby-1.8
+1. Create an account at http://openshift.redhat.com/
-Add mysql support to your application
-
+1. Create a rails application
+
+ ```
+ rhc app create -a railsapp -t ruby-1.9
+ ```
+
+1. Add mysql support to your application
+
+ ```
rhc app cartridge add -a railsapp -c mysql-5.1
+ ```
-Add this upstream rails quickstart repo
+1. Add this upstream Rails quickstart repository
+ ```
cd railsapp
git remote add upstream -m master git://github.com/openshift/rails-example.git
git pull -s recursive -X theirs upstream master
+ ```
-Then push the repo upstream
+1. Push your new code
+ ```
git push
+ ```
-That's it, you can now checkout your application at:
-
- http://railsapp-$yournamespace.rhcloud.com
+1. That's it! Enjoy your new Rails application!
-Security Considerations
------------------------
-This repository contains configuration files with security related variables.
-Since this is a shared repository, any applications derived from it will share those variables, thus reducing the security of your application.
-
-You should follow the directions below and push your updated files to OpenShift immediately.
-
-### Procedure
-
-The following table lists files and variables that should be changed.
-
-These values can be replaced by the output of `rake secret`, which generates a securely random 128 character string.
-
-<table>
- <tr>
- <th>File</th>
- <th>Variable</th>
- </tr>
- <tr>
- <td>config/initializers/secret_token.rb</td>
- <td>Railsapp::Application.config.secret_token</td>
- </tr>
- <tr>
- <td>config/initializers/session_store.rb</td>
- <td>Railsapp::Application.config.session_store</td>
- </tr>
-</table>
+[template]: https://openshift.redhat.com/app/console/application_types/rails
View
4 Rakefile
@@ -1,7 +1,7 @@
+#!/usr/bin/env 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.
require File.expand_path('../config/application', __FILE__)
-require 'rake'
-Railsapp::Application.load_tasks
+RailsApp::Application.load_tasks
View
0  public/images/rails.png → app/assets/images/rails.png
File renamed without changes
View
15 app/assets/javascripts/application.js
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// the compiled file.
+//
+// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
+// GO AFTER THE REQUIRES BELOW.
+//
+//= require jquery
+//= require jquery_ujs
+//= require_tree .
View
13 app/assets/stylesheets/application.css
@@ -0,0 +1,13 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
View
5 app/controllers/home_controller.rb
@@ -1,5 +0,0 @@
-class HomeController < ApplicationController
- def index
- end
-
-end
View
83 app/controllers/posts_controller.rb
@@ -1,83 +0,0 @@
-class PostsController < ApplicationController
- # GET /posts
- # GET /posts.xml
- def index
- @posts = Post.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @posts }
- end
- end
-
- # GET /posts/1
- # GET /posts/1.xml
- def show
- @post = Post.find(params[:id])
-
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @post }
- end
- end
-
- # GET /posts/new
- # GET /posts/new.xml
- def new
- @post = Post.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @post }
- end
- end
-
- # GET /posts/1/edit
- def edit
- @post = Post.find(params[:id])
- end
-
- # POST /posts
- # POST /posts.xml
- def create
- @post = Post.new(params[:post])
-
- respond_to do |format|
- if @post.save
- format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
- format.xml { render :xml => @post, :status => :created, :location => @post }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # PUT /posts/1
- # PUT /posts/1.xml
- def update
- @post = Post.find(params[:id])
-
- respond_to do |format|
- if @post.update_attributes(params[:post])
- format.html { redirect_to(@post, :notice => 'Post was successfully updated.') }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
- end
- end
- end
-
- # DELETE /posts/1
- # DELETE /posts/1.xml
- def destroy
- @post = Post.find(params[:id])
- @post.destroy
-
- respond_to do |format|
- format.html { redirect_to(posts_url) }
- format.xml { head :ok }
- end
- end
-end
View
2  app/helpers/home_helper.rb
@@ -1,2 +0,0 @@
-module HomeHelper
-end
View
2  app/helpers/posts_helper.rb
@@ -1,2 +0,0 @@
-module PostsHelper
-end
View
0  app/mailers/.gitkeep
No changes.
View
0  app/models/.gitkeep
No changes.
View
2  app/models/post.rb
@@ -1,2 +0,0 @@
-class Post < ActiveRecord::Base
-end
View
2  app/views/home/index.html.erb
@@ -1,2 +0,0 @@
-<h1>Home#index</h1>
-<p>Find me in app/views/home/index.html.erb</p>
View
8 app/views/layouts/application.html.erb
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<html>
<head>
- <title>Railsapp</title>
- <%= stylesheet_link_tag :all %>
- <%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
+ <title>RailsApp</title>
+ <%= stylesheet_link_tag "application", :media => "all" %>
+ <%= javascript_include_tag "application" %>
+ <%= csrf_meta_tags %>
</head>
<body>
View
29 app/views/posts/_form.html.erb
@@ -1,29 +0,0 @@
-<%= form_for(@post) do |f| %>
- <% if @post.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
-
- <ul>
- <% @post.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <div class="field">
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </div>
- <div class="field">
- <%= f.label :title %><br />
- <%= f.text_field :title %>
- </div>
- <div class="field">
- <%= f.label :content %><br />
- <%= f.text_area :content %>
- </div>
- <div class="actions">
- <%= f.submit %>
- </div>
-<% end %>
View
6 app/views/posts/edit.html.erb
@@ -1,6 +0,0 @@
-<h1>Editing post</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Show', @post %> |
-<%= link_to 'Back', posts_path %>
View
27 app/views/posts/index.html.erb
@@ -1,27 +0,0 @@
-<h1>Listing posts</h1>
-
-<table>
- <tr>
- <th>Name</th>
- <th>Title</th>
- <th>Content</th>
- <th></th>
- <th></th>
- <th></th>
- </tr>
-
-<% @posts.each do |post| %>
- <tr>
- <td><%= post.name %></td>
- <td><%= post.title %></td>
- <td><%= post.content %></td>
- <td><%= link_to 'Show', post %></td>
- <td><%= link_to 'Edit', edit_post_path(post) %></td>
- <td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
-<% end %>
-</table>
-
-<br />
-
-<%= link_to 'New Post', new_post_path %>
View
5 app/views/posts/new.html.erb
@@ -1,5 +0,0 @@
-<h1>New post</h1>
-
-<%= render 'form' %>
-
-<%= link_to 'Back', posts_path %>
View
20 app/views/posts/show.html.erb
@@ -1,20 +0,0 @@
-<p id="notice"><%= notice %></p>
-
-<p>
- <b>Name:</b>
- <%= @post.name %>
-</p>
-
-<p>
- <b>Title:</b>
- <%= @post.title %>
-</p>
-
-<p>
- <b>Content:</b>
- <%= @post.content %>
-</p>
-
-
-<%= link_to 'Edit', edit_post_path(@post) %> |
-<%= link_to 'Back', posts_path %>
View
2  config.ru
@@ -1,4 +1,4 @@
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
-run Railsapp::Application
+run RailsApp::Application
View
34 config/application.rb
@@ -2,11 +2,14 @@
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)
+if defined?(Bundler)
+ # If you precompile assets before deploying to production, use this line
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
+ # If you want your assets lazily compiled in production, use this line
+ # Bundler.require(:default, :assets, Rails.env)
+end
-module Railsapp
+module RailsApp
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
@@ -30,13 +33,30 @@ class Application < Rails::Application
# 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]
+
+ # Enable escaping HTML in JSON.
+ config.active_support.escape_html_entities_in_json = true
+
+ # Use SQL instead of Active Record's schema dumper when creating the 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
+
+ # Enforce whitelist mode for mass assignment.
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
+ # parameters by using an attr_accessible or attr_protected declaration.
+ config.active_record.whitelist_attributes = true
+
+ # Enable the asset pipeline
+ config.assets.enabled = true
+
+ # Version of your assets, change this if you want to expire all your assets
+ config.assets.version = '1.0'
end
end
View
22 config/database.yml
@@ -1,27 +1,21 @@
-# SQLite version 3.x
-# gem install sqlite3
-development:
+test:
adapter: sqlite3
- database: db/development.sqlite3
+ database: db/test.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:
+development:
adapter: sqlite3
- database: db/test.sqlite3
+ database: db/development.sqlite3
pool: 5
timeout: 5000
production:
- adapter: mysql
+ adapter: mysql2
encoding: utf8
- database: <%=ENV['OPENSHIFT_APP_NAME']%>
+ reconnect: false
pool: 5
- host: <%=ENV['OPENSHIFT_DB_HOST']%>
- port: <%=ENV['OPENSHIFT_DB_PORT']%>
+ database: <%=ENV['OPENSHIFT_APP_NAME']%>
username: <%=ENV['OPENSHIFT_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_DB_PASSWORD']%>
- socket: <%=ENV['OPENSHIFT_DB_SOCKET']%>
+ socket: <%=ENV['OPENSHIFT_DB_SOCKET']%>
View
22 config/database.yml.sqlite3
@@ -1,22 +0,0 @@
-# SQLite version 3.x
-# gem install sqlite3
-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: <%=ENV['OPENSHIFT_DATA_DIR']>production.sqlite3
- pool: 5
- timeout: 5000
View
2  config/environment.rb
@@ -2,4 +2,4 @@
require File.expand_path('../application', __FILE__)
# Initialize the rails application
-Railsapp::Application.initialize!
+RailsApp::Application.initialize!
View
21 config/environments/development.rb
@@ -1,9 +1,9 @@
-Railsapp::Application.configure do
+RailsApp::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.
+ # every request. This slows down response time but is perfect for development
+ # since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
@@ -11,7 +11,6 @@
# 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
@@ -22,5 +21,17 @@
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
-end
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
+
+ # Do not compress assets
+ config.assets.compress = false
+
+ # Expands the lines which load the assets
+ config.assets.debug = true
+end
View
46 config/environments/production.rb
@@ -1,7 +1,6 @@
-Railsapp::Application.configure do
+RailsApp::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
@@ -9,31 +8,46 @@
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"
+ # Disable Rails's static asset server (Apache or nginx will already do this)
+ config.serve_static_assets = false
+
+ # Compress JavaScripts and CSS
+ config.assets.compress = true
+
+ # Don't fallback to assets pipeline if a precompiled asset is missed
+ config.assets.compile = false
+
+ # Generate digests for assets URLs
+ config.assets.digest = true
+
+ # Defaults to nil and saved in location specified by config.assets.prefix
+ # config.assets.manifest = YOUR_PATH
- # For nginx:
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
+ # Specifies the header that your server uses for sending files
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
- # If you have no front-end server that supports something like X-Sendfile,
- # just comment this out and Rails will serve the files
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
+ # config.force_ssl = true
# See everything in the log (default is :info)
# config.log_level = :debug
+ # Prepend all log lines with the following tags
+ # config.log_tags = [ :subdomain, :uuid ]
+
# Use a different logger for distributed setups
- # config.logger = SyslogLogger.new
+ # config.logger = ActiveSupport::TaggedLogging.new(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
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
+ # config.assets.precompile += %w( search.js )
+
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
@@ -46,4 +60,8 @@
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
+
+ # Log the query plan for queries taking more than this (works
+ # with SQLite, MySQL, and PostgreSQL)
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
end
View
18 config/environments/test.rb
@@ -1,13 +1,17 @@
-Railsapp::Application.configure do
+RailsApp::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
+ # 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!
+ # 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.
+ # Configure static asset server for tests with Cache-Control for performance
+ config.serve_static_assets = true
+ config.static_cache_control = "public, max-age=3600"
+
+ # Log error messages when you accidentally call methods on nil
config.whiny_nils = true
# Show full error reports and disable caching
@@ -25,10 +29,8 @@
# 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
+ # Raise exception on mass assignment protection for Active Record models
+ config.active_record.mass_assignment_sanitizer = :strict
# Print deprecation notices to the stderr
config.active_support.deprecation = :stderr
View
5 config/initializers/inflections.rb
@@ -8,3 +8,8 @@
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
+#
+# These inflection rules are supported but not enabled by default:
+# ActiveSupport::Inflector.inflections do |inflect|
+# inflect.acronym 'RESTful'
+# end
View
9 config/initializers/secret_token.rb
@@ -1,14 +1,7 @@
-require File.join(Rails.root,'lib','openshift_secret_generator.rb')
-
# 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.
-
-# Set token based on intialize_secret function (defined in initializers/secret_generator.rb)
-Railsapp::Application.config.secret_token = initialize_secret(
- :token,
- '335a4e365ef2daeea969640d74e18f0e3cd9fae1abd8f4125691a880774ea6d456a29c0831aa6921bf86a710fe555e916f0673f5657619ec9df22e0409bec345'
-)
+RailsApp::Application.config.secret_token = '1dcdc33f3d7941da1628655ccb823d8b12baebb423945e4fceef7ead9d7fbee25d49ff51bdaff781fc2d2c46ac5cf08f0a356e54c5a44e31812d0d2385dc24fc'
View
10 config/initializers/session_store.rb
@@ -1,14 +1,8 @@
-require File.join(Rails.root,'lib','openshift_secret_generator.rb')
-
# Be sure to restart your server when you modify this file.
-# Set token based on intialize_secret function (defined in initializers/secret_generator.rb)
-Railsapp::Application.config.session_store :cookie_store, :key => initialize_secret(
- :session_store,
- '_railsapp_session'
-)
+RailsApp::Application.config.session_store :cookie_store, key: '_rails_app_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")
-# Railsapp::Application.config.session_store :active_record_store
+# RailsApp::Application.config.session_store :active_record_store
View
14 config/initializers/wrap_parameters.rb
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+#
+# This file contains settings for ActionController::ParamsWrapper which
+# is enabled by default.
+
+# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
+ActiveSupport.on_load(:action_controller) do
+ wrap_parameters format: [:json]
+end
+
+# Disable root element in JSON by default.
+ActiveSupport.on_load(:active_record) do
+ self.include_root_in_json = false
+end
View
2  config/locales/en.yml
@@ -1,5 +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.
+# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
en:
hello: "Hello world"
View
11 config/routes.rb
@@ -1,8 +1,4 @@
-Railsapp::Application.routes.draw do
- resources :posts
-
- get "home/index"
-
+RailsApp::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -52,12 +48,11 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
- # root :to => "welcome#index"
+ # root :to => 'welcome#index'
# See how all your routes lay out with "rake routes"
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
- # match ':controller(/:action(/:id(.:format)))'
-root :to => "home#index"
+ # match ':controller(/:action(/:id))(.:format)'
end
View
15 db/migrate/20110810175718_create_posts.rb
@@ -1,15 +0,0 @@
-class CreatePosts < ActiveRecord::Migration
- def self.up
- create_table :posts do |t|
- t.string :name
- t.string :title
- t.text :content
-
- t.timestamps
- end
- end
-
- def self.down
- drop_table :posts
- end
-end
View
4 db/seeds.rb
@@ -3,5 +3,5 @@
#
# Examples:
#
-# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
-# Mayor.create(:name => 'Daley', :city => cities.first)
+# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
+# Mayor.create(name: 'Emanuel', city: cities.first)
View
0  lib/assets/.gitkeep
No changes.
View
31 lib/openshift_secret_generator.rb
@@ -1,31 +0,0 @@
-# Create random key based on the OPENSHIFT_SECRET_TOKEN
-
-def initialize_secret(name,default)
- # Only generate token based if we're running on OPENSHIFT
- if secret = get_env_secret
- # Create seed for random function from secret and name
- seed = [secret,name.to_s].join('-')
- # Generate hash from seed
- hash = Digest::SHA512.hexdigest(seed)
- # Set token, ensuring it is the same length as the default
- hash[0,default.length]
- else
- Rails.logger.warn "Unable to get OPENSHIFT_SECRET_TOKEN, using default"
- default
- end
-end
-
-def get_env_secret
- ENV['OPENSHIFT_SECRET_TOKEN'] || generate_secret_token
-end
-
-def generate_secret_token
- Rails.logger.debug "No secret token environment variable set"
- (name,uuid) = ENV.values_at('OPENSHIFT_APP_NAME','OPENSHIFT_APP_UUID')
- if name && uuid
- Rails.logger.debug "Running on Openshift, creating OPENSHIFT_SECRET_TOKEN"
- Digest::SHA256.hexdigest([name,uuid].join('-'))
- else
- nil
- end
-end
View
0  log/.gitkeep
No changes.
View
1  public/500.html
@@ -20,7 +20,6 @@
<!-- 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
158 public/index.html
@@ -0,0 +1,158 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+ <title>OpenShift - Rails 3.2</title>
+ <style>
+ html {
+ background: black;
+ }
+ body {
+ background: #333;
+ background: -webkit-linear-gradient(top, black, #666);
+ background: -o-linear-gradient(top, black, #666);
+ background: -moz-linear-gradient(top, black, #666);
+ background: linear-gradient(top, black, #666);
+ color: white;
+ font-family: "Helvetica Neue",Helvetica,"Liberation Sans",Arial,sans-serif;
+ width: 40em;
+ margin: 0 auto;
+ padding: 3em;
+ }
+ a {
+ color: white;
+ }
+
+ h1 {
+ text-transform: capitalize;
+ -moz-text-shadow: -1px -1px 0 black;
+ -webkit-text-shadow: 2px 2px 2px black;
+ text-shadow: -1px -1px 0 black;
+ box-shadow: 1px 2px 2px rgba(0, 0, 0, 0.5);
+ background: #CC0000;
+ width: 22.5em;
+ margin: 1em -2em;
+ padding: .3em 0 .3em 1.5em;
+ position: relative;
+ }
+ h1:before {
+ content: '';
+ width: 0;
+ height: 0;
+ border: .5em solid #91010B;
+ border-left-color: transparent;
+ border-bottom-color: transparent;
+ position: absolute;
+ bottom: -1em;
+ left: 0;
+ z-index: -1000;
+ }
+ h1:after {
+ content: '';
+ width: 0;
+ height: 0;
+ border: .5em solid #91010B;
+ border-right-color: transparent;
+ border-bottom-color: transparent;
+ position: absolute;
+ bottom: -1em;
+ right: 0;
+ z-index: -1000;
+ }
+ h2 {
+ margin: 2em 0 .5em;
+ border-bottom: 1px solid #999;
+ }
+
+ pre {
+ background: black;
+ padding: 1em 0 0;
+ -webkit-border-radius: 1em;
+ -moz-border-radius: 1em;
+ border-radius: 1em;
+ color: #9cf;
+ }
+
+ ul {
+ margin: 0;
+ padding: 0;
+ }
+ li {
+ list-style-type: none;
+ padding: .5em 0;
+ }
+
+ .brand {
+ display: block;
+ text-decoration: none;
+ }
+ .brand .brand-image {
+ float: left;
+ }
+ .brand .brand-text {
+ float: left;
+ font-size: 24px;
+ line-height: 24px;
+ padding: 4px 0;
+ color: white;
+ text-transform: uppercase;
+ }
+ .brand:hover,
+ .brand:active {
+ text-decoration: underline;
+ }
+
+ .brand:before,
+ .brand:after {
+ content: ' ';
+ display: table;
+ }
+ .brand:after {
+ clear: both;
+ }
+ </style>
+ </head>
+ <body>
+ <a href="http://openshift.com" class="brand">
+ <img class="brand-image"
+ alt="OpenShift logo"
+ src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAgCAYAAABU1PscAAAAAXNSR0IArs4c6QAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAARHgAAER4B27UUrQAABUhJREFUWMPFWFlsVGUU/s5/70zbaSltA7RQpJ2lC9CFkQkWIgSJxkAhRA0JCYFq4hPG6JsoGKNCtPigxqhvGlPAuGIaE4igNaElbIW2yNL2tkOtTYGWCqWF2e79fCh7p1Bmpnge/3vuOef7z/nPJiTxMHS6pMRuu6YqFNTTAJYSyAU4GZB0AH2AGCANAfc5Qrba6T3HrmECScYLwCioSIcV2AjidQDZ45Q/LJRaWrLV03X89P8GwHB5XwG4DcDkGPWEBKimNrzN094efGQAzjm9GWHFr4R4LiHKgFaSL3r8zYcmHEBbkW+KFo7UEyhKsNeHlMgyV8eJo4kQpqId9ub6HCoc+XWcxl8lcBTATwDax8GfZtHa054/f/bNg8ZcnyOhHjBc834E8MJ9/vML8aYZQX1hd1PP3WFXkhMRfYkIlpOoGomc0WRRTnch+XAQWG2KTNJNLbuy68C/cQMwXOWrAKkdgz8A8kMdg9X5fn/gQcI7POXLaMk3AGbe/P8SbF0D1KcGRGXpIJJpIQkWBHhnsf/Ie3GF0DmnMxmQT8bg7RellXr8ze+Ox3gAcBvNf+iUUhH5FODLSvScAerDGpiVxTAyGUYKzICA34nCwbhDyHB7N4L8PAofhVzh9jfvjffR/ZZTnupIsR8G0C9EjW7Tfnii/dBgrPL0u83kmjHy33Z3Z/zG97uKi7xpWA8GHZpE1mcZRne8MvXblfbxqQAWR+Fp+mdW5hZPjAqu5JVlhrTwOgrXi2ABbjjchF4FYGvi0qhprgagjYod4OeldXWRWBUEtdBjEH4mwIJ7vF2V4Dqgot0+NEFdPAqmdZ5tAXA8Slx6LrpKsxMHQJge5ft1v0oe2OOu+PZ39+LCOFqImqiXo8JzAeBkXlnmnoKK9LgACJl2R9gELsHW1saUwKCpnbIoa8UMTokVgGXJmSjHkfNWUlWDy9d6USVdyoiEF8b1iElxQKHuPG1D/bCtVEBhCiykMQQFgCK2mN2sSx+tkdcbhGq7wKSkK9RnmsCG2xVSLsflAR1S6eloWhawtF8yGJGskSJDBdQR8pIjZMXcfFmm1gOg2lRaSRdT1AD1PBPQbCAyxcRMifCpc41HEtILNbh9s8SSvYTUmBp2LDGOdCOB1OD0XbeByWliwY5bugc9nU2T4wqhCx7PNAV9bSGwARp3TzVaP0j09GQUzJubLUgefY3SEHMh63MVr4FIlYL+7C1AlCwAmxM+/plYy6hhgN2xp1HBawAr72krnH3uoicTaXyHx7uIwKZoT0QhUhszAAI7x7ivL0a60/jp77yyTFrWt6N6rxE99c7OkxdiBhC2y/cAorXHpama/aNG8dkOO32b6p3zTzXmeysfPu4LkkKafA3IrGjfCfPtuGfiPlfx+xBsuWtwpa3zIuy2YaoZ5o0eSQc5TVnb53aeeAuk9eBtRvkqUH0MoTsqA7nL429eFzeA3lyfQ08eaiNgCrjTYNozQ1S+WyUfQCosTLqZ+oiDUNwhggPujpZTuCMXGwUV6cJgKYnNIJffR3df2NLLZ5871puQrUR//pzpU7rOnAfJP53eDELrsoPpk4RIGRn5xqIBAAdBOCAoBjBjPJsJUdZSt9HSOGFrld5cn2M4KbwfkIUJzqYhQlYWdJ7YN2FrFQCY3nPsmk61AuSuRNYyUdaiRBk/7tViR37Zcir1JYC8WNshgjWWPfhq0dmzVx/5bhQAWnLKU1Md8gZHOsjxAgmD2GEKq4s6m1sxASQPu16HiBh53goqPg9ac0TEcwNQEOBlQAZEcMgC94dDZt2c7r8GMIH0H43ZRDC51RVCAAAAAElFTkSuQmCC">
+ <div class="brand-text"><strong>Open</strong>Shift</div>
+ </a>
+ <h1>
+ OpenShift - Rails 3.2
+ </h1>
+ <p>
+ This application was created using <a href="https://github.com/openshift/rails-example">this OpenShift quickstart</a>.
+ </p>
+ <p>
+ It contains everything you need to be up and running with a fully functional Rails application!
+ </p>
+ <p>
+ In order to commit to your new project, go to your projects git repo (created with the rhc app create command). Make your changes, then run:
+ </p>
+ <pre>
+ git commit -a -m 'Some commit message'
+ git push
+ </pre>
+ <p>
+ Then reload this page.
+ </p>
+
+ <h2>
+ What's next?
+ </h2>
+ <ul>
+ <li>
+ Why not visit us at <a href="http://openshift.redhat.com">http://openshift.redhat.com</a>, or
+ </li>
+ <li>
+ You could get help in the <a href="http://www.redhat.com/openshift">OpenShift forums</a>, or
+ </li>
+ <li>
+ You're welcome to come chat with us in our IRC channel at #openshift on freenode.net
+ </li>
+ </ul>
+ </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);