From b661c9603a3d053f940e50fc1b63ff568f9b98f8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 8 Nov 2005 04:26:34 +0000 Subject: Added an omnipresent RailsInfoController with a properties action that delivers an HTML rendering of Rails::Info (but only when local_request? is true). Added a new default index.html which fetches this with Ajax. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2933 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/CHANGELOG | 4 + railties/Rakefile | 2 +- .../builtin/controllers/rails_info_controller.rb | 11 + railties/html/images/rails.png | Bin 0 -> 1787 bytes railties/html/index.html | 343 ++++++++++++++++----- railties/lib/initializer.rb | 3 +- .../generators/applications/app/app_generator.rb | 1 + railties/lib/rails_info.rb | 10 + railties/lib/railties_path.rb | 2 +- railties/lib/tasks/javascripts.rake | 2 +- railties/test/rails_info_controller_test.rb | 54 ++++ 11 files changed, 357 insertions(+), 75 deletions(-) create mode 100644 railties/builtin/controllers/rails_info_controller.rb create mode 100644 railties/html/images/rails.png create mode 100644 railties/test/rails_info_controller_test.rb (limited to 'railties') diff --git a/railties/CHANGELOG b/railties/CHANGELOG index f98bde50f0..6df4aeea07 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -1,3 +1,7 @@ +*SVN* + +* Added an omnipresent RailsInfoController with a properties action that delivers an HTML rendering of Rails::Info (but only when local_request? is true). Added a new default index.html which fetches this with Ajax. [Sam Stephenson] + *0.14.3 (RC4)* (November 7th, 2005) * Add 'add_new_scripts' rake task for adding new rails scripts to script/* [Jamis Buck] diff --git a/railties/Rakefile b/railties/Rakefile index 2f31df3809..e425f9a4dd 100644 --- a/railties/Rakefile +++ b/railties/Rakefile @@ -34,7 +34,7 @@ PUBLIC_DIRS = %w( images javascripts stylesheets ) TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/test ) LOG_FILES = %w( server.log development.log test.log production.log ) -HTML_FILES = %w( 404.html 500.html index.html robots.txt favicon.ico +HTML_FILES = %w( 404.html 500.html index.html robots.txt favicon.ico images/rails.png javascripts/prototype.js javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js ) BIN_FILES = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/spinner runner server plugin ) diff --git a/railties/builtin/controllers/rails_info_controller.rb b/railties/builtin/controllers/rails_info_controller.rb new file mode 100644 index 0000000000..ca2801e075 --- /dev/null +++ b/railties/builtin/controllers/rails_info_controller.rb @@ -0,0 +1,11 @@ +module Controllers #:nodoc: + class RailsInfoController < ApplicationController + def properties + if local_request? + render :inline => Rails::Info.to_html + else + render :text => '

For security purposes, this information is only available to local requests.

', :status => 500 + end + end + end +end \ No newline at end of file diff --git a/railties/html/images/rails.png b/railties/html/images/rails.png new file mode 100644 index 0000000000..b8441f182e Binary files /dev/null and b/railties/html/images/rails.png differ diff --git a/railties/html/index.html b/railties/html/index.html index d780f8e029..952ee4febb 100644 --- a/railties/html/index.html +++ b/railties/html/index.html @@ -1,78 +1,279 @@ - + - - Rails: Welcome on board - - - + #header { + background-image: url("images/rails.png"); + background-repeat: no-repeat; + background-position: top left; + height: 64px; + } + #header h1, #header h2 {margin: 0} + #header h2 { + color: #888; + font-weight: normal; + font-size: 16px; + } + + + #about h3 { + margin: 0; + margin-bottom: 10px; + font-size: 14px; + } + + #about-content { + background-color: #ffd; + border: 1px solid #fc0; + margin-left: -11px; + } + #about-content table { + margin-top: 10px; + margin-bottom: 10px; + font-size: 11px; + border-collapse: collapse; + } + #about-content td { + padding: 10px; + padding-top: 3px; + padding-bottom: 3px; + } + #about-content td.name {color: #555} + #about-content td.value {color: #000} + + #about-content.failure { + background-color: #fcc; + border: 1px solid #f00; + } + #about-content.failure p { + margin: 0; + padding: 10px; + } + + + #getting-started { + border-top: 1px solid #ccc; + margin-top: 25px; + padding-top: 15px; + } + #getting-started h1 { + margin: 0; + font-size: 20px; + } + #getting-started h2 { + margin: 0; + font-size: 14px; + font-weight: normal; + color: #333; + margin-bottom: 25px; + } + #getting-started ol { + margin-left: 0; + padding-left: 0; + } + #getting-started li { + font-size: 18px; + color: #888; + margin-bottom: 25px; + } + #getting-started li h2 { + margin: 0; + font-weight: normal; + font-size: 18px; + color: #333; + } + #getting-started li p { + color: #555; + font-size: 13px; + } + + + #search { + margin: 0; + padding-top: 10px; + padding-bottom: 10px; + font-size: 11px; + } + #search input { + font-size: 11px; + margin: 2px; + } + #search-text {width: 170px} + + + #sidebar ul { + margin-left: 0; + padding-left: 0; + } + #sidebar ul h3 { + margin-top: 25px; + font-size: 16px; + padding-bottom: 10px; + border-bottom: 1px solid #ccc; + } + #sidebar li { + list-style-type: none; + } + #sidebar ul.links li { + margin-bottom: 5px; + } + + + + + + + +
+ -

Congratulations, you've put Ruby on Rails!

+
+ -

Before you move on, verify that the following conditions have been met:

- -
    -
  1. The log and public directories must be writable to the web server (chmod -R 775 log and chmod -R 775 public). -
  2. - The shebang line in the public/dispatch* files must reference your Ruby installation.
    - You might need to change it to #!/usr/bin/env ruby or point directly at the installation. -
  3. -
  4. - Rails on Apache needs to have the cgi handler and mod_rewrite enabled.
    - Somewhere in your httpd.conf, you should have:
    - AddHandler cgi-script .cgi
    - LoadModule rewrite_module libexec/httpd/mod_rewrite.so
    - AddModule mod_rewrite.c -
  5. -
- -

Take the following steps to get started:

- -
    -
  1. Create empty development and test databases for your application.
    - Recommendation: Use *_development and *_test names, such as basecamp_development and basecamp_test
    - Warning: Don't point your test database at your development database, it'll destroy the latter on test runs! -
  2. Edit config/database.yml with your database settings. -
  3. Create controllers and models using the generator in script/generate
    - Help: Run the generator with no arguments for documentation -
  4. See all the tests run by running rake. -
  5. Develop your Rails application! -
  6. Setup Apache with FastCGI (and Ruby bindings), if you need better performance -
  7. Remove the dispatches you don't use (so if you're on FastCGI, delete/move dispatch.rb, dispatch.cgi and gateway.cgi)
  8. -
- -

- Trying to setup a default page for Rails using Routes? You'll have to delete this file (public/index.html) to get under way. Then define a new route in config/routes.rb of the form: -

  map.connect '', :controller => 'wiki/page', :action => 'show', :title => 'Welcome'
-

- -

- Having problems getting up and running? First try debugging it yourself by looking at the log files.
- Then try the friendly Rails community on the web or on IRC - (FreeNode#rubyonrails). -

- - - + + +
+

Getting started

+

Here’s how to get rolling:

+ +
    +
  1. +

    Create your databases and edit database.yml

    +

    Instructions here

    +
  2. + +
  3. +

    Use script/generate to create your models and controllers

    +

    Instructions here

    +
  4. + +
  5. +

    Set up a default route and remove or rename this file

    +

    Instructions here

    +
  6. +
+
+
+ + +
+ + \ No newline at end of file diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 31edd69f46..1535b7213f 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -1,5 +1,6 @@ require 'logger' require 'set' +require File.join(File.dirname(__FILE__), 'railties_path') RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV) @@ -488,7 +489,7 @@ module Rails end def default_controller_paths - [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components') ] + [ File.join(root_path, 'app', 'controllers'), File.join(root_path, 'components'), File.join(RAILTIES_PATH, 'builtin', 'controllers') ] end def default_dependency_mechanism diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb index 01f371ce42..aee2cced24 100644 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb @@ -64,6 +64,7 @@ class AppGenerator < Rails::Generator::Base m.template "html/favicon.ico", "public/favicon.ico" m.template "html/robots.txt", "public/robots.txt" + m.file "html/images/rails.png", "public/images/rails.png" # Javascripts m.file "html/javascripts/prototype.js", "public/javascripts/prototype.js" diff --git a/railties/lib/rails_info.rb b/railties/lib/rails_info.rb index c0237dab7c..5c71a289c2 100644 --- a/railties/lib/rails_info.rb +++ b/railties/lib/rails_info.rb @@ -42,6 +42,16 @@ module Rails alias inspect to_s + def to_html + returning table = '' do + properties.each do |(name, value)| + table << %() + table << %() + end + table << '
#{CGI.escapeHTML(name)}#{CGI.escapeHTML(value)}
' + end + end + protected def svn_info Dir.chdir("#{RAILS_ROOT}/vendor/rails") do diff --git a/railties/lib/railties_path.rb b/railties/lib/railties_path.rb index b08ced8be5..817940504d 100644 --- a/railties/lib/railties_path.rb +++ b/railties/lib/railties_path.rb @@ -1 +1 @@ -RAILTIES_PATH = File.expand_path(File.dirname(__FILE__)) \ No newline at end of file +RAILTIES_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..')) \ No newline at end of file diff --git a/railties/lib/tasks/javascripts.rake b/railties/lib/tasks/javascripts.rake index 91965c8918..5fc01562e8 100644 --- a/railties/lib/tasks/javascripts.rake +++ b/railties/lib/tasks/javascripts.rake @@ -2,5 +2,5 @@ desc "Update your javascripts from your current rails install." task :update_javascripts do require 'railties_path' - FileUtils.cp(Dir[RAILTIES_PATH + '/../html/javascripts/*.js'], RAILS_ROOT + '/public/javascripts/') + FileUtils.cp(Dir[RAILTIES_PATH + '/html/javascripts/*.js'], RAILS_ROOT + '/public/javascripts/') end diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb new file mode 100644 index 0000000000..1488387f3c --- /dev/null +++ b/railties/test/rails_info_controller_test.rb @@ -0,0 +1,54 @@ +$:.unshift File.dirname(__FILE__) + "/../lib" +$:.unshift File.dirname(__FILE__) + "/../builtin/controllers" +$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" +$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" + +require 'test/unit' +require 'action_controller' +require 'action_controller/test_process' +require 'rails_info' + +module Controllers; def self.const_available?(constant); false end end + +class ApplicationController < ActionController::Base + @local_request = false + class << self + cattr_accessor :local_request + end + +protected + def local_request? + self.class.local_request + end +end + +ActionController::Routing::Routes.draw do |map| + map.connect ':controller/:action/:id' +end + +require 'rails_info_controller' + +# Re-raise errors caught by the controller. +class Controllers::RailsInfoController; def rescue_action(e) raise e end; end + +class RailsInfoControllerTest < Test::Unit::TestCase + def setup + @controller = Controllers::RailsInfoController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_rails_info_properties_table_rendered_for_local_request + Controllers::RailsInfoController.local_request = true + get :properties + assert_tag :tag => 'table' + assert_response :success + end + + def test_rails_info_properties_error_rendered_for_non_local_request + Controllers::RailsInfoController.local_request = false + get :properties + assert_tag :tag => 'p' + assert_response 500 + end +end -- cgit v1.2.3