aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails_generator/generators/applications/app/app_generator.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 13:14:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-07 13:14:05 +0000
commitdaee6fd92ac16878f6806c3382a9e74592aa9656 (patch)
treed477c6502960cb141403f8b4640dd483b487e5df /railties/lib/rails_generator/generators/applications/app/app_generator.rb
parent838c5a3d82367977d13ced01f9e28c22ccff32ef (diff)
downloadrails-daee6fd92ac16878f6806c3382a9e74592aa9656.tar.gz
rails-daee6fd92ac16878f6806c3382a9e74592aa9656.tar.bz2
rails-daee6fd92ac16878f6806c3382a9e74592aa9656.zip
Added new generator framework that informs about its doings on generation and enables updating and destruction of generated artifacts. See the new script/destroy and script/update for more details #487 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@518 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator/generators/applications/app/app_generator.rb')
-rw-r--r--railties/lib/rails_generator/generators/applications/app/app_generator.rb118
1 files changed, 118 insertions, 0 deletions
diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb
new file mode 100644
index 0000000000..0beb11b237
--- /dev/null
+++ b/railties/lib/rails_generator/generators/applications/app/app_generator.rb
@@ -0,0 +1,118 @@
+class AppGenerator < Rails::Generator::Base
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
+ Config::CONFIG['ruby_install_name'])
+
+ default_options :gem => true, :shebang => DEFAULT_SHEBANG
+ mandatory_options :source => "#{File.dirname(__FILE__)}/../.."
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.empty?
+ @destination_root = args.shift
+ puts "eek! #{destination_root.inspect}"
+ end
+
+ def manifest
+ script_options = { :chmod => 0755, :shebang => options[:shebang] }
+
+ record do |m|
+ # Root directory and all subdirectories.
+ m.directory ''
+ BASEDIRS.each { |path| m.directory path }
+
+ # Root
+ m.file "fresh_rakefile", "Rakefile"
+ m.file "README", "README"
+ m.file "CHANGELOG", "CHANGELOG"
+
+ # Application
+ m.template "helpers/application.rb", "app/controllers/application.rb"
+ m.template "helpers/application_helper.rb", "app/helpers/application_helper.rb"
+ m.template "helpers/test_helper.rb", "test/test_helper.rb"
+
+ # database.yml and .htaccess
+ m.template "configs/database.yml", "config/database.yml"
+ m.template "configs/apache.conf", "public/.htaccess"
+
+ # Environments
+ if options[:gem]
+ m.file "environments/shared_for_gem.rb", "config/environment.rb"
+ else
+ m.file "environments/shared.rb", "config/environment.rb"
+ end
+ m.file "environments/production.rb", "config/environments/production.rb"
+ m.file "environments/development.rb", "config/environments/development.rb"
+ m.file "environments/test.rb", "config/environments/test.rb"
+
+ # Scripts
+ %w(console destroy generate server).each do |file|
+ m.file "bin/#{file}", "script/#{file}", script_options
+ end
+ if options[:gem]
+ m.file "bin/breakpointer_for_gem", "script/breakpointer", script_options
+ else
+ m.file "bin/breakpointer", "script/breakpointer", script_options
+ end
+
+ # Dispatches
+ m.file "dispatches/dispatch.rb", "public/dispatch.rb", script_options
+ m.file "dispatches/dispatch.rb", "public/dispatch.cgi", script_options
+ m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", script_options
+
+ # HTML files
+ %w(404 500 index).each do |file|
+ m.template "html/#{file}.html", "public/#{file}.html"
+ end
+
+ # Docs
+ m.template "doc/index.html", "public/_doc/index.html"
+ m.file "doc/README_FOR_APP", "doc/README_FOR_APP"
+
+ # Logs
+ %w(apache production development test).each { |file|
+ m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666
+ }
+ end
+ end
+
+ protected
+ def banner
+ "Usage: #{$0} /path/to/your/app [options]"
+ end
+
+ def add_options!(opt)
+ opt.separator ''
+ opt.separator 'Options:'
+ opt.on("--ruby [#{DEFAULT_SHEBANG}]",
+ "Path to the Ruby binary of your choice.") { |options[:shebang]| }
+ opt.on("--without-gems",
+ "Don't use the Rails gems for your app.",
+ "WARNING: see note below.") { |options[:gem]| }
+ end
+
+
+ # Installation skeleton. Intermediate directories are automatically
+ # created so don't sweat their absence here.
+ BASEDIRS = %w(
+ app/controllers
+ app/helpers
+ app/models
+ app/views/layouts
+ config/environments
+ db
+ doc
+ lib
+ log
+ public/_doc
+ public/images
+ public/javascripts
+ public/stylesheets
+ script
+ test/fixtures
+ test/functional
+ test/mocks/development
+ test/mocks/testing
+ test/unit
+ vendor
+ )
+end