aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-02 11:40:00 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-02 11:40:00 +0200
commit826a6a72fe8ab44080312b8bcc1f5dfd39c5a163 (patch)
tree9a4d518b70d01f7b78acc6451a1a6d3d67b9a1fe
parentec55e59e993d6c39c6ba8d57d4ef6d270ee8c14f (diff)
downloadrails-826a6a72fe8ab44080312b8bcc1f5dfd39c5a163.tar.gz
rails-826a6a72fe8ab44080312b8bcc1f5dfd39c5a163.tar.bz2
rails-826a6a72fe8ab44080312b8bcc1f5dfd39c5a163.zip
Updated rake tasks.
-rw-r--r--railties/README243
-rw-r--r--railties/Rakefile188
-rwxr-xr-xrailties/bin/railsgen (renamed from railties/bin/gen)0
3 files changed, 257 insertions, 174 deletions
diff --git a/railties/README b/railties/README
new file mode 100644
index 0000000000..37ec8ea211
--- /dev/null
+++ b/railties/README
@@ -0,0 +1,243 @@
+== Welcome to Rails
+
+Rails is a web-application framework that includes everything needed to create
+database-backed web applications according to the Model-View-Control pattern.
+
+This pattern splits the view (also called the presentation) into "dumb" templates
+that are primarily responsible for inserting pre-built data in between HTML tags.
+The model contains the "smart" domain objects (such as Account, Product, Person,
+Post) that holds all the business logic and knows how to persist themselves to
+a database. The controller handles the incoming requests (such as Save New Account,
+Update Product, Show Post) by manipulating the model and directing data to the view.
+
+In Rails, the model is handled by what's called an object-relational mapping
+layer entitled Active Record. This layer allows you to present the data from
+database rows as objects and embellish these data objects with business logic
+methods. You can read more about Active Record in
+link:files/vendor/rails/activerecord/README.html.
+
+The controller and view are handled by the Action Pack, which handles both
+layers by its two parts: Action View and Action Controller. These two layers
+are bundled in a single package due to their heavy interdependence. This is
+unlike the relationship between the Active Record and Action Pack that is much
+more separate. Each of these packages can be used independently outside of
+Rails. You can read more about Action Pack in
+link:files/vendor/rails/actionpack/README.html.
+
+
+== Getting Started
+
+1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
+ and your application name. Ex: rails myapp
+2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
+3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
+4. Follow the guidelines to start developing your application
+
+
+== Web Servers
+
+By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
+with a variety of other web servers.
+
+Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
+suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
+getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
+More info at: http://mongrel.rubyforge.org
+
+Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
+Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
+FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
+
+== Apache .htaccess example for FCGI/CGI
+
+# General Apache options
+AddHandler fastcgi-script .fcgi
+AddHandler cgi-script .cgi
+Options +FollowSymLinks +ExecCGI
+
+# If you don't want Rails to look in certain directories,
+# use the following rewrite rules so that Apache won't rewrite certain requests
+#
+# Example:
+# RewriteCond %{REQUEST_URI} ^/notrails.*
+# RewriteRule .* - [L]
+
+# Redirect all requests not available on the filesystem to Rails
+# By default the cgi dispatcher is used which is very slow
+#
+# For better performance replace the dispatcher with the fastcgi one
+#
+# Example:
+# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
+RewriteEngine On
+
+# If your Rails application is accessed via an Alias directive,
+# then you MUST also set the RewriteBase in this htaccess file.
+#
+# Example:
+# Alias /myrailsapp /path/to/myrailsapp/public
+# RewriteBase /myrailsapp
+
+RewriteRule ^$ index.html [QSA]
+RewriteRule ^([^.]+)$ $1.html [QSA]
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
+
+# In case Rails experiences terminal errors
+# Instead of displaying this message you can supply a file here which will be rendered instead
+#
+# Example:
+# ErrorDocument 500 /500.html
+
+ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
+
+
+== Debugging Rails
+
+Sometimes your application goes wrong. Fortunately there are a lot of tools that
+will help you debug it and get it back on the rails.
+
+First area to check is the application log files. Have "tail -f" commands running
+on the server.log and development.log. Rails will automatically display debugging
+and runtime information to these files. Debugging info will also be shown in the
+browser on requests from 127.0.0.1.
+
+You can also log your own messages directly into the log file from your code using
+the Ruby logger class from inside your controllers. Example:
+
+ class WeblogController < ActionController::Base
+ def destroy
+ @weblog = Weblog.find(params[:id])
+ @weblog.destroy
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
+ end
+ end
+
+The result will be a message in your log file along the lines of:
+
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
+
+More information on how to use the logger is at http://www.ruby-doc.org/core/
+
+Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
+
+* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
+* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
+
+These two online (and free) books will bring you up to speed on the Ruby language
+and also on programming in general.
+
+
+== Debugger
+
+Debugger support is available through the debugger command when you start your Mongrel or
+Webrick server with --debugger. This means that you can break out of execution at any point
+in the code, investigate and change the model, AND then resume execution!
+You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
+Example:
+
+ class WeblogController < ActionController::Base
+ def index
+ @posts = Post.find(:all)
+ debugger
+ end
+ end
+
+So the controller will accept the action, run the first line, then present you
+with a IRB prompt in the server window. Here you can do things like:
+
+ >> @posts.inspect
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
+ >> @posts.first.title = "hello from a debugger"
+ => "hello from a debugger"
+
+...and even better is that you can examine how your runtime objects actually work:
+
+ >> f = @posts.first
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
+ >> f.
+ Display all 152 possibilities? (y or n)
+
+Finally, when you're ready to resume execution, you enter "cont"
+
+
+== Console
+
+You can interact with the domain model by starting the console through <tt>script/console</tt>.
+Here you'll have all parts of the application configured, just like it is when the
+application is running. You can inspect domain models, change values, and save to the
+database. Starting the script without arguments will launch it in the development environment.
+Passing an argument will specify a different environment, like <tt>script/console production</tt>.
+
+To reload your controllers and models after launching the console run <tt>reload!</tt>
+
+== dbconsole
+
+You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
+You would be connected to the database with the credentials defined in database.yml.
+Starting the script without arguments will connect you to the development database. Passing an
+argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
+Currently works for mysql, postgresql and sqlite.
+
+== Description of Contents
+
+app
+ Holds all the code that's specific to this particular application.
+
+app/controllers
+ Holds controllers that should be named like weblogs_controller.rb for
+ automated URL mapping. All controllers should descend from ApplicationController
+ which itself descends from ActionController::Base.
+
+app/models
+ Holds models that should be named like post.rb.
+ Most models will descend from ActiveRecord::Base.
+
+app/views
+ Holds the template files for the view that should be named like
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
+ syntax.
+
+app/views/layouts
+ Holds the template files for layouts to be used with views. This models the common
+ header/footer method of wrapping views. In your views, define a layout using the
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
+ call <% yield %> to render the view using this layout.
+
+app/helpers
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
+ for you automatically when using script/generate for controllers. Helpers can be used to
+ wrap functionality for your views into methods.
+
+config
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
+
+db
+ Contains the database schema in schema.rb. db/migrate contains all
+ the sequence of Migrations for your schema.
+
+doc
+ This directory is where your application documentation will be stored when generated
+ using <tt>rake doc:app</tt>
+
+lib
+ Application specific libraries. Basically, any kind of custom code that doesn't
+ belong under controllers, models, or helpers. This directory is in the load path.
+
+public
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
+ set as the DOCUMENT_ROOT of your web server.
+
+script
+ Helper scripts for automation and generation.
+
+test
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
+ test files will be generated for you and placed in this directory.
+
+vendor
+ External libraries that the application depends on. Also includes the plugins subdirectory.
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
+ This directory is in the load path.
diff --git a/railties/Rakefile b/railties/Rakefile
index 35ae15ff0f..475954d064 100644
--- a/railties/Rakefile
+++ b/railties/Rakefile
@@ -41,56 +41,22 @@ Rake::TestTask.new("regular_test") do |t|
t.verbose = true
end
-
-BASE_DIRS = %w(
- app
- config/environments
- config/initializers
- config/locales
- db
- doc
- log
- lib
- lib/tasks
- public
- script
- script/performance
- test
- vendor
- vendor/plugins
- tmp/sessions
- tmp/cache
- tmp/sockets
- tmp/pids
-)
-
-APP_DIRS = %w( models controllers helpers views views/layouts )
-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( 422.html 404.html 500.html index.html robots.txt favicon.ico images/rails.png
- javascripts/prototype.js javascripts/application.js
- javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
-BIN_FILES = %w( about console destroy generate performance/benchmarker performance/profiler runner server plugin )
-
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport activeresource railties )
-
desc "Generates a fresh Rails package with documentation"
-task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
+task :fresh_rails => [ :clean, :create_rails, :copy_vendor_libraries, :generate_documentation ]
desc "Generates a fresh Rails package using GEMs with documentation"
-task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
+task :fresh_gem_rails => [ :clean, :create_rails ]
desc "Generates a fresh Rails package without documentation (faster)"
-task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
+task :fresh_rails_without_docs => [ :clean, :create_rails, :copy_vendor_libraries ]
-desc "Generates a fresh Rails package without documentation (faster)"
-task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
+desc "Generates a fresh Rails package without documentation using links (faster)"
+task :fresh_rails_without_docs_using_links => [ :clean, :create_rails, :link_vendor_libraries ]
desc "Generates minimal Rails package using symlinks"
-task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
+task :dev => [ :clean, :create_rails, :link_vendor_libraries ]
desc "Packages the fresh Rails package with documentation"
task :package => [ :clean, :fresh_rails ] do
@@ -112,44 +78,22 @@ task :update_js do
end
end
-# Make directory structure ----------------------------------------------------------------
-
-def make_dest_dirs(dirs, path = '.')
- mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
-end
-
-desc "Make the directory structure for the new Rails application"
-task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
-
-task(:make_base_dirs) { make_dest_dirs BASE_DIRS }
-task(:make_app_dirs) { make_dest_dirs APP_DIRS, 'app' }
-task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public' }
-task(:make_test_dirs) { make_dest_dirs TEST_DIRS, 'test' }
-
+# Run application generator -------------------------------------------------------------
-# Initialize file stubs -------------------------------------------------------------------
-
-desc "Initialize empty file stubs (such as for logging)"
-task :initialize_file_stubs => [ :initialize_log_files ]
-
-task :initialize_log_files do
- log_dir = File.join(PKG_DESTINATION, 'log')
- chmod 0777, log_dir
- LOG_FILES.each do |log_file|
- log_path = File.join(log_dir, log_file)
- touch log_path
- chmod 0666, log_path
- end
+task :create_rails do
+ require File.join(File.dirname(__FILE__), 'lib', 'generators')
+ require 'generators/rails/app/app_generator'
+ Rails::Generators::AppGenerator.start [ File.basename(PKG_DESTINATION), "--quiet" ],
+ :root => File.expand_path(File.dirname(PKG_DESTINATION))
end
-
# Copy Vendors ----------------------------------------------------------------------------
desc "Copy in all the Rails packages to vendor"
task :copy_vendor_libraries do
mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
- FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".svn")))
+ FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".git")))
end
desc "Link in all the Rails packages to vendor"
@@ -159,96 +103,6 @@ task :link_vendor_libraries do
end
-# Copy Ties Content -----------------------------------------------------------------------
-
-desc "Make copies of all the default content of ties"
-task :copy_ties_content => [
- :copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
- :copy_configs, :copy_binfiles, :copy_test_helpers, :copy_app_doc_readme ]
-
-task :copy_dispatches do
- copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
- chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"
-
- copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
- chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"
-
- copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
- chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
-end
-
-task :copy_html_files do
- HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
-end
-
-task :copy_application do
- cp "helpers/application_controller.rb", "#{PKG_DESTINATION}/app/controllers/application_controller.rb"
- cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
-end
-
-task :copy_configs do
- app_name = "rails"
- socket = nil
- require 'erb'
- File.open("#{PKG_DESTINATION}/config/database.yml", 'w') {|f| f.write ERB.new(IO.read("configs/databases/sqlite3.yml"), nil, '-').result(binding)}
-
- cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
-
- cp "configs/initializers/backtrace_silencers.rb", "#{PKG_DESTINATION}/config/initializers/backtrace_silencers.rb"
- cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
- cp "configs/initializers/mime_types.rb", "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
- cp "configs/initializers/new_rails_defaults.rb", "#{PKG_DESTINATION}/config/initializers/new_rails_defaults.rb"
-
- cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"
-
- cp "configs/seeds.rb", "#{PKG_DESTINATION}/db/seeds.rb"
-
- cp "environments/boot.rb", "#{PKG_DESTINATION}/config/boot.rb"
- cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
- cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
- cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
- cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"
-
-end
-
-task :copy_binfiles do
- BIN_FILES.each do |file|
- dest_file = File.join(PKG_DESTINATION, 'script', file)
- copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
- chmod 0755, dest_file
- end
-end
-
-task :copy_rootfiles do
- cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
- cp "README", "#{PKG_DESTINATION}/README"
- cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
-end
-
-task :copy_test_helpers do
- cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
-end
-
-task :copy_app_doc_readme do
- cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
-end
-
-def copy_with_rewritten_ruby_path(src_file, dest_file)
- ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
-
- File.open(dest_file, 'w') do |df|
- File.open(src_file) do |sf|
- line = sf.gets
- if (line =~ /#!.+ruby\s*/) != nil
- df.puts("#!#{ruby}")
- else
- df.puts(line)
- end
- df.write(sf.read)
- end
- end
-end
-
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"'
task :generate_guides do
ENV["WARN_BROKEN_LINKS"] = "1" # authors can't disable this
@@ -266,7 +120,6 @@ task :generate_rails_framework_doc do
end
task :generate_app_doc do
- cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
system %{cd #{PKG_DESTINATION}; rake doc:app}
end
@@ -279,30 +132,17 @@ Rake::RDocTask.new { |rdoc|
rdoc.rdoc_files.include('README', 'CHANGELOG')
rdoc.rdoc_files.include('lib/*.rb')
rdoc.rdoc_files.include('lib/rails/*.rb')
- rdoc.rdoc_files.include('lib/rails_generator/*.rb')
+ rdoc.rdoc_files.include('lib/generators/*.rb')
rdoc.rdoc_files.include('lib/commands/**/*.rb')
}
# Generate GEM ----------------------------------------------------------------------------
-task :copy_gem_environment do
- cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
- chmod 0755, dest_file
-end
-
-
PKG_FILES = FileList[
'[a-zA-Z]*',
'bin/**/*',
'builtin/**/*',
- 'configs/**/*',
- 'doc/**/*',
- 'dispatches/**/*',
- 'environments/**/*',
'guides/**/*',
- 'helpers/**/*',
- 'generators/**/*',
- 'html/**/*',
'lib/**/*'
] - [ 'test' ]
diff --git a/railties/bin/gen b/railties/bin/railsgen
index 809e75acb5..809e75acb5 100755
--- a/railties/bin/gen
+++ b/railties/bin/railsgen