diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-16 17:10:40 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-19 16:10:43 +0200 |
commit | d57b19380eaad8bda63743107f085e72935343b9 (patch) | |
tree | 7414fbcb3d2609b48f2974e90d0646169d59b524 /railties/lib/generator/generators/app.thor | |
parent | ceede90017bb1c753b5ca8b80216d59400b0f0ba (diff) | |
download | rails-d57b19380eaad8bda63743107f085e72935343b9.tar.gz rails-d57b19380eaad8bda63743107f085e72935343b9.tar.bz2 rails-d57b19380eaad8bda63743107f085e72935343b9.zip |
Add base and port actions. Not functional though.
Diffstat (limited to 'railties/lib/generator/generators/app.thor')
-rw-r--r-- | railties/lib/generator/generators/app.thor | 237 |
1 files changed, 117 insertions, 120 deletions
diff --git a/railties/lib/generator/generators/app.thor b/railties/lib/generator/generators/app.thor index 8dc94641b3..4aa2022759 100644 --- a/railties/lib/generator/generators/app.thor +++ b/railties/lib/generator/generators/app.thor @@ -1,168 +1,165 @@ +require File.dirname(__FILE__) + '/../base' require 'rbconfig' require 'digest/md5' require 'active_support/secure_random' require 'rails/version' -class App < Thor::Group - include Thor::Actions +module Rails::Generators + class App < Base + DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) + DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db ) + DEFAULT_DATABASE = 'sqlite3' - def self.source_root - @source_root ||= File.join(File.dirname(__FILE__), '..', 'templates', 'app') - end - - DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']) - DATABASES = %w( mysql oracle postgresql sqlite2 sqlite3 frontbase ibm_db ) - DEFAULT_DATABASE = 'sqlite3' - - argument :app_path, :type => :string + argument :app_path, :type => :string - class_option :ruby, :type => :string, :aliases => "-d", :default => DEFAULT_SHEBANG, - :desc => "Path to the Ruby binary of your choice" + class_option :ruby, :type => :string, :aliases => "-d", :default => DEFAULT_SHEBANG, + :desc => "Path to the Ruby binary of your choice" - class_option :database, :type => :string, :aliases => "-d", :default => DEFAULT_DATABASE, - :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})" + class_option :database, :type => :string, :aliases => "-d", :default => DEFAULT_DATABASE, + :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})" - class_option :with_dispatchers, :type => :boolean, :aliases => "-D", :default => false, - :desc => "Add CGI/FastCGI/mod_ruby dispatchers code" + class_option :with_dispatchers, :type => :boolean, :aliases => "-D", :default => false, + :desc => "Add CGI/FastCGI/mod_ruby dispatchers code" - class_option :freeze, :type => :boolean, :aliases => "-f", :default => false, - :desc => "Freeze Rails in vendor/rails from the gems" + class_option :freeze, :type => :boolean, :aliases => "-f", :default => false, + :desc => "Freeze Rails in vendor/rails from the gems" - class_option :template, :type => :string, :aliases => "-m", - :desc => "Use an application template that lives at path (can be a filesystem path or URL)." + class_option :template, :type => :string, :aliases => "-m", + :desc => "Use an application template that lives at path (can be a filesystem path or URL)." - def create_root - self.root = File.expand_path(app_path, root) - empty_directory '.' + def create_root + self.root = File.expand_path(app_path, root) + empty_directory '.' - app_name # Sets the app name - FileUtils.cd(root) - end + app_name # Sets the app name + FileUtils.cd(root) + end - def create_root_files - copy_file "Rakefile" - copy_file "README" - end + def create_root_files + copy_file "Rakefile" + copy_file "README" + end - def create_app_files - directory "app" - end + def create_app_files + directory "app" + end - def create_config_files - empty_directory "config" + def create_config_files + empty_directory "config" - inside "config" do - copy_file "boot.rb" - copy_file "routes.rb" + inside "config" do + copy_file "boot.rb" + copy_file "routes.rb" - template "databases/#{options[:database]}.yml", "database.yml" - template "environment.rb" + template "databases/#{options[:database]}.yml", "database.yml" + template "environment.rb" - directory "environments" - directory "initializers" - directory "locales" + directory "environments" + directory "initializers" + directory "locales" + end end - end - def create_db_files - directory "db" - end + def create_db_files + directory "db" + end - def create_doc_files - directory "doc" - end + def create_doc_files + directory "doc" + end - def create_lib_files - empty_directory "lib" - empty_directory "lib/tasks" - end + def create_lib_files + empty_directory "lib" + empty_directory "lib/tasks" + end - def create_log_files - empty_directory "log" + def create_log_files + empty_directory "log" - inside "log" do - %w( server production development test ).each do |file| - create_file "#{file}.log" - chmod "#{file}.log", 0666, false + inside "log" do + %w( server production development test ).each do |file| + create_file "#{file}.log" + chmod "#{file}.log", 0666, false + end end end - end - def create_public_files - directory "public" - end + def create_public_files + directory "public" + end - def create_dispatch_files - return unless options.with_dispatchers? + def create_dispatch_files + return unless options.with_dispatchers? - copy_file "dispatchers/config.ru", "config.ru" + copy_file "dispatchers/config.ru", "config.ru" - template "dispatchers/dispatch.rb", "public/dispatch.rb" - chmod "public/dispatch.rb", 0755, false + template "dispatchers/dispatch.rb", "public/dispatch.rb" + chmod "public/dispatch.rb", 0755, false - template "dispatchers/dispatch.rb", "public/dispatch.cgi" - chmod "public/dispatch.cgi", 0755, false + template "dispatchers/dispatch.rb", "public/dispatch.cgi" + chmod "public/dispatch.cgi", 0755, false - template "dispatchers/dispatch.fcgi", "public/dispatch.fcgi" - chmod "public/dispatch.fcgi", 0755, false - end + template "dispatchers/dispatch.fcgi", "public/dispatch.fcgi" + chmod "public/dispatch.fcgi", 0755, false + end - def create_javascript_files - directory "javascripts/prototype", "public/javascripts" - end + def create_javascript_files + directory "javascripts/prototype", "public/javascripts" + end - def create_script_files - directory "script" - chmod "script", 0755, false - end + def create_script_files + directory "script" + chmod "script", 0755, false + end - def create_test_files - directory "test" - end + def create_test_files + directory "test" + end - def create_tmp_files - empty_directory "tmp" + def create_tmp_files + empty_directory "tmp" - inside "tmp" do - %w(sessions sockets cache pids).each do |dir| - empty_directory dir + inside "tmp" do + %w(sessions sockets cache pids).each do |dir| + empty_directory dir + end end end - end - def create_vendor_files - empty_directory "vendor/plugins" - end + def create_vendor_files + empty_directory "vendor/plugins" + end - protected + protected - def app_name - @app_name ||= File.basename(root) - end + def app_name + @app_name ||= File.basename(root) + end - def app_secret - ActiveSupport::SecureRandom.hex(64) - end + def app_secret + ActiveSupport::SecureRandom.hex(64) + end - def freeze - options[:freeze] - end + def freeze + options[:freeze] + end - def shebang - options[:ruby] || "#!/usr/bin/env ruby" - end + def shebang + options[:ruby] || "#!/usr/bin/env ruby" + end - def mysql_socket - @mysql_socket ||= [ - "/tmp/mysql.sock", # default - "/var/run/mysqld/mysqld.sock", # debian/gentoo - "/var/tmp/mysql.sock", # freebsd - "/var/lib/mysql/mysql.sock", # fedora - "/opt/local/lib/mysql/mysql.sock", # fedora - "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql - "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 - "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 - "/opt/lampp/var/mysql/mysql.sock" # xampp for linux - ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ - end + def mysql_socket + @mysql_socket ||= [ + "/tmp/mysql.sock", # default + "/var/run/mysqld/mysqld.sock", # debian/gentoo + "/var/tmp/mysql.sock", # freebsd + "/var/lib/mysql/mysql.sock", # fedora + "/opt/local/lib/mysql/mysql.sock", # fedora + "/opt/local/var/run/mysqld/mysqld.sock", # mac + darwinports + mysql + "/opt/local/var/run/mysql4/mysqld.sock", # mac + darwinports + mysql4 + "/opt/local/var/run/mysql5/mysqld.sock", # mac + darwinports + mysql5 + "/opt/lampp/var/mysql/mysql.sock" # xampp for linux + ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ + end + end end |