Skip to content

Commit

Permalink
Added new generator framework that informs about its doings on genera…
Browse files Browse the repository at this point in the history
…tion 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
  • Loading branch information
dhh committed Feb 7, 2005
1 parent 838c5a3 commit daee6fd
Show file tree
Hide file tree
Showing 61 changed files with 1,850 additions and 644 deletions.
5 changes: 5 additions & 0 deletions railties/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
*SVN*

* 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]


*0.9.5* (January 25th, 2005)

* Fixed dependency reloading by switching to a remove_const approach where all Active Records, Active Record Observers, and Action Controllers are reloading by undefining their classes. This enables you to remove methods in all three types and see the change reflected immediately and it fixes #539. This also means that only those three types of classes will benefit from the const_missing and reloading approach. If you want other classes (like some in lib/) to reload, you must use require_dependency to do it.
Expand Down
13 changes: 2 additions & 11 deletions railties/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/testing

LOG_FILES = %w( apache.log development.log test.log production.log )
HTML_FILES = %w( 404.html 500.html index.html )
BIN_FILES = %w( generate breakpointer console server )
GENERATORS = %w( controller mailer model scaffold )
BIN_FILES = %w( generate destroy breakpointer console server update )

VENDOR_LIBS = %w( actionpack activerecord actionmailer railties )
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport railties )


desc "Default Task"
Expand Down Expand Up @@ -142,14 +141,6 @@ task :copy_configs do
cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"
end

task :copy_generators do
mkdir_p File.join(PKG_DESTINATION, 'script/generators')

GENERATORS.each do |dir|
cp_r File.join('generators', dir), File.join(PKG_DESTINATION, 'script', 'generators', dir)
end
end

task :copy_binfiles do
BIN_FILES.each do |file|
dest_file = File.join(PKG_DESTINATION, 'script', file)
Expand Down
8 changes: 8 additions & 0 deletions railties/bin/destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/local/bin/ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'rails_generator'
require 'rails_generator/simple_logger'
require 'rails_generator/scripts/destroy'

Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(STDOUT)
Rails::Generator::Scripts::Destroy.new.run(ARGV)
73 changes: 4 additions & 69 deletions railties/bin/generate
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
#!/usr/local/bin/ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'rails_generator'
require 'rails_generator/simple_logger'
require 'rails_generator/scripts/generate'

ARGV.shift unless ARGV.empty? or not ['--help', '-h'].include?(ARGV[0])

def find_synonyms(word)
require 'open-uri'
require 'timeout'

uri = "http://wordnet.princeton.edu/cgi-bin/webwn2.0?stage=2" +
"&word=%s&posnumber=1&searchtypenumber=2&senses=&showglosses=1"

timeout(5) do
open(uri % word) do |stream|
data = stream.read.gsub("&nbsp;", " ").gsub("<BR>", "")
data.scan(/^Sense \d+\n.+?\n\n/m)
end
end
rescue Timeout::Error, Exception
return nil
end

unless ARGV.empty?
begin
name = ARGV.shift
generator = Rails::Generator.instance(name, ARGV)

if msg = generator.collision_with_builtin? then
$stderr.puts msg

if synonyms = find_synonyms(generator.class_name) then
$stderr.puts(
"", "Here are a few synonyms from WordNet. Maybe they will help you find an alternative name.",
"", synonyms
)
end
else
generator.generate
end
rescue Rails::Generator::UsageError => e
puts e.message
end
else
builtin_generators = Rails::Generator.builtin_generators.join(', ')
contrib_generators = Rails::Generator.contrib_generators.join(', ')

$stderr.puts <<end_usage
#{$0} generator [args]
Rails comes with #{builtin_generators} generators.
#{$0} controller Login login logout
#{$0} model Account
#{$0} mailer AccountMailer
#{$0} scaffold Account action another_action
end_usage

unless contrib_generators.empty?
$stderr.puts " Installed generators (in #{RAILS_ROOT}/script/generators):"
$stderr.puts " #{contrib_generators}"
$stderr.puts
end

$stderr.puts <<end_usage
More generators are available at http://rubyonrails.org/show/Generators
1. Download, for example, login_generator.tar.gz
2. Unzip to directory #{RAILS_ROOT}/script/generators/login
3. Generate without args for usage information
#{$0} login
end_usage
exit 0
end
Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(STDOUT)
Rails::Generator::Scripts::Generate.new.run(ARGV)
33 changes: 6 additions & 27 deletions railties/bin/rails
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
if ARGV[0]
ENV["RAILS_PKG_DESTINATION"] = File.expand_path(ARGV[0])
if RUBY_PLATFORM =~ /mswin32/
Dir.chdir File.dirname(__FILE__)
system %{rake.cmd fresh_gem_rails}
else
system %{ cd #{File.dirname(__FILE__)}; rake fresh_gem_rails }
end
else
puts <<-HELP
require File.dirname(__FILE__) + '/../lib/rails_generator'
require 'rails_generator/simple_logger'
require 'rails_generator/scripts/generate'

NAME
rails - creates a new Rails installation

SYNOPSIS
rails [full path]

DESCRIPTION
This generator will create a suggested directory structure, lots of minor helper
files, and a default configuration for creating a new Rails application. Once the
generator is done, you're advised to look at the README in the root of the folder.

EXAMPLE
rails ~/Code/Ruby/weblog

This will generate a new Rails installation in the ~/Code/Ruby/weblog folder.
HELP
end
Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(STDOUT)
Rails::Generator::Base.use_application_sources!
Rails::Generator::Scripts::Generate.new.run(ARGV, :generator => 'app')
8 changes: 8 additions & 0 deletions railties/bin/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/local/bin/ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'rails_generator'
require 'rails_generator/simple_logger'
require 'rails_generator/scripts/update'

Rails::Generator::Base.logger = Rails::Generator::SimpleLogger.new(STDOUT)
Rails::Generator::Scripts::Update.new.run(ARGV)
4 changes: 2 additions & 2 deletions railties/fresh_rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ task :doc => [ :appdoc, :stats ]
desc "Run the unit tests in test/unit"
Rake::TestTask.new("test_units") { |t|
t.libs << "test"
t.pattern = 'test/unit/*_test.rb'
t.pattern = 'test/unit/**/*_test.rb'
t.verbose = true
}

desc "Run the functional tests in test/functional"
Rake::TestTask.new("test_functional") { |t|
t.libs << "test"
t.pattern = 'test/functional/*_test.rb'
t.pattern = 'test/functional/**/*_test.rb'
t.verbose = true
}

Expand Down
28 changes: 0 additions & 28 deletions railties/generators/controller/USAGE

This file was deleted.

26 changes: 0 additions & 26 deletions railties/generators/controller/controller_generator.rb

This file was deleted.

27 changes: 0 additions & 27 deletions railties/generators/mailer/USAGE

This file was deleted.

22 changes: 0 additions & 22 deletions railties/generators/mailer/mailer_generator.rb

This file was deleted.

17 changes: 0 additions & 17 deletions railties/generators/model/USAGE
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
GENERATOR
model - create model stub files

SYNOPSIS
generate model ModelName

DESCRIPTION
The model generator takes a model name and generates an empty model in
app/models, a test suite in test/unit with one passing test case, and a
fixtures YAML file in the test/fixtures directory.

EXAMPLE
./script/generate model Account

This will generate an Account class in app/models/account.rb, an
AccountTest in test/unit/account_test.rb, and the fixtures file
test/fixtures/account.yml.
10 changes: 0 additions & 10 deletions railties/generators/model/model_generator.rb

This file was deleted.

1 change: 0 additions & 1 deletion railties/generators/model/templates/fixtures.yml

This file was deleted.

27 changes: 0 additions & 27 deletions railties/generators/scaffold/USAGE

This file was deleted.

Loading

0 comments on commit daee6fd

Please sign in to comment.