diff options
author | José Valim <jose.valim@gmail.com> | 2009-06-15 21:09:34 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-06-19 16:10:42 +0200 |
commit | 489f42215223bda3a0a2d8f9b740007a6ee3fc54 (patch) | |
tree | e31789294be49231f2bd9eb6a5a64b791c264dd2 /railties/lib/generator/generators/app.thor | |
parent | 8037fee9ff1dd13c421e6689229457c1ef084074 (diff) | |
download | rails-489f42215223bda3a0a2d8f9b740007a6ee3fc54.tar.gz rails-489f42215223bda3a0a2d8f9b740007a6ee3fc54.tar.bz2 rails-489f42215223bda3a0a2d8f9b740007a6ee3fc54.zip |
Initial scratch of application generator.
Diffstat (limited to 'railties/lib/generator/generators/app.thor')
-rw-r--r-- | railties/lib/generator/generators/app.thor | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/railties/lib/generator/generators/app.thor b/railties/lib/generator/generators/app.thor new file mode 100644 index 0000000000..6e9bae9ce0 --- /dev/null +++ b/railties/lib/generator/generators/app.thor @@ -0,0 +1,88 @@ +require 'rbconfig' + +class App < Thor::Group + include Thor::Actions + + 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 + + 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 :with_dispatchers, :type => :boolean, :aliases => "-D", :default => false, + :desc => "Add CGI/FastCGI/mod_ruby dispatches code" + + 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)." + + def create_root + self.root = File.expand_path(app_path, root) + empty_directory '.' + + app_name # Sets the app name + FileUtils.cd(root) + end + + def create_root_files + copy_file "Rakefile" + copy_file "README" + end + + def create_app_files + %w( + app/controllers + app/helpers + app/models + app/views/layouts + ).each { |path| empty_directory(path) } + + directory "app" + end + + def directories + %w( + config/environments + config/initializers + config/locales + db + doc + lib + lib/tasks + log + public/images + public/javascripts + public/stylesheets + script/performance + test/fixtures + test/functional + test/integration + test/performance + test/unit + vendor + vendor/plugins + tmp/sessions + tmp/sockets + tmp/cache + tmp/pids + ).each { |path| empty_directory(path) } + end + + protected + + def app_name + @app_name ||= File.basename(root) + end +end |