diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-07-31 16:21:07 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-07-31 16:21:07 -0300 |
commit | 3de59e916d6a3d4eab202cf0c99b1f88905a3b43 (patch) | |
tree | def6d6a808ebe187be1f37f8a739fd786cc11f02 /railties/lib/rails_generator | |
parent | c1cbf02e3170f1004daf4a146cbc41176c2458d3 (diff) | |
parent | 62fd1d3716b4b5fd1d91cdcc77003efe80fc5a7e (diff) | |
download | rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.gz rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.tar.bz2 rails-3de59e916d6a3d4eab202cf0c99b1f88905a3b43.zip |
Merge commit 'rails/master'
Conflicts:
activerecord/lib/active_record/associations.rb
Diffstat (limited to 'railties/lib/rails_generator')
99 files changed, 0 insertions, 3670 deletions
diff --git a/railties/lib/rails_generator/base.rb b/railties/lib/rails_generator/base.rb deleted file mode 100644 index aa7081f8da..0000000000 --- a/railties/lib/rails_generator/base.rb +++ /dev/null @@ -1,266 +0,0 @@ -require File.dirname(__FILE__) + '/options' -require File.dirname(__FILE__) + '/manifest' -require File.dirname(__FILE__) + '/spec' -require File.dirname(__FILE__) + '/generated_attribute' - -module Rails - # Rails::Generator is a code generation platform tailored for the Rails - # web application framework. Generators are easily invoked within Rails - # applications to add and remove components such as models and controllers. - # New generators are easy to create and may be distributed as RubyGems, - # tarballs, or Rails plugins for inclusion system-wide, per-user, - # or per-application. - # - # For actual examples see the rails_generator/generators directory in the - # Rails source (or the +railties+ directory if you have frozen the Rails - # source in your application). - # - # Generators may subclass other generators to provide variations that - # require little or no new logic but replace the template files. - # - # For a RubyGem, put your generator class and templates in the +lib+ - # directory. For a Rails plugin, make a +generators+ directory at the - # root of your plugin. - # - # The layout of generator files can be seen in the built-in - # +controller+ generator: - # - # generators/ - # components/ - # controller/ - # controller_generator.rb - # templates/ - # controller.rb - # functional_test.rb - # helper.rb - # view.html.erb - # - # The directory name (+controller+) matches the name of the generator file - # (controller_generator.rb) and class (ControllerGenerator). The files - # that will be copied or used as templates are stored in the +templates+ - # directory. - # - # The filenames of the templates don't matter, but choose something that - # will be self-explanatory since you will be referencing these in the - # +manifest+ method inside your generator subclass. - # - # - module Generator - class GeneratorError < StandardError; end - class UsageError < GeneratorError; end - - - # The base code generator is bare-bones. It sets up the source and - # destination paths and tells the logger whether to keep its trap shut. - # - # It's useful for copying files such as stylesheets, images, or - # javascripts. - # - # For more comprehensive template-based passive code generation with - # arguments, you'll want Rails::Generator::NamedBase. - # - # Generators create a manifest of the actions they perform then hand - # the manifest to a command which replays the actions to do the heavy - # lifting (such as checking for existing files or creating directories - # if needed). Create, destroy, and list commands are included. Since a - # single manifest may be used by any command, creating new generators is - # as simple as writing some code templates and declaring what you'd like - # to do with them. - # - # The manifest method must be implemented by subclasses, returning a - # Rails::Generator::Manifest. The +record+ method is provided as a - # convenience for manifest creation. Example: - # - # class StylesheetGenerator < Rails::Generator::Base - # def manifest - # record do |m| - # m.directory('public/stylesheets') - # m.file('application.css', 'public/stylesheets/application.css') - # end - # end - # end - # - # See Rails::Generator::Commands::Create for a list of methods available - # to the manifest. - class Base - include Options - - # Declare default options for the generator. These options - # are inherited to subclasses. - default_options :collision => :ask, :quiet => false - - # A logger instance available everywhere in the generator. - cattr_accessor :logger - - # Every generator that is dynamically looked up is tagged with a - # Spec describing where it was found. - class_inheritable_accessor :spec - - attr_reader :source_root, :destination_root, :args - - def initialize(runtime_args, runtime_options = {}) - @args = runtime_args - parse!(@args, runtime_options) - - # Derive source and destination paths. - @source_root = options[:source] || File.join(spec.path, 'templates') - if options[:destination] - @destination_root = options[:destination] - elsif defined? ::RAILS_ROOT - @destination_root = ::RAILS_ROOT - end - - # Silence the logger if requested. - logger.quiet = options[:quiet] - - # Raise usage error if help is requested. - usage if options[:help] - end - - # Generators must provide a manifest. Use the +record+ method to create - # a new manifest and record your generator's actions. - def manifest - raise NotImplementedError, "No manifest for '#{spec.name}' generator." - end - - # Return the full path from the source root for the given path. - # Example for source_root = '/source': - # source_path('some/path.rb') == '/source/some/path.rb' - # - # The given path may include a colon ':' character to indicate that - # the file belongs to another generator. This notation allows any - # generator to borrow files from another. Example: - # source_path('model:fixture.yml') = '/model/source/path/fixture.yml' - def source_path(relative_source) - # Check whether we're referring to another generator's file. - name, path = relative_source.split(':', 2) - - # If not, return the full path to our source file. - if path.nil? - File.join(source_root, name) - - # Otherwise, ask our referral for the file. - else - # FIXME: this is broken, though almost always true. Others' - # source_root are not necessarily the templates dir. - File.join(self.class.lookup(name).path, 'templates', path) - end - end - - # Return the full path from the destination root for the given path. - # Example for destination_root = '/dest': - # destination_path('some/path.rb') == '/dest/some/path.rb' - def destination_path(relative_destination) - File.join(destination_root, relative_destination) - end - - def after_generate - end - - protected - # Convenience method for generator subclasses to record a manifest. - def record - Rails::Generator::Manifest.new(self) { |m| yield m } - end - - # Override with your own usage banner. - def banner - "Usage: #{$0} #{spec.name} [options]" - end - - # Read USAGE from file in generator base path. - def usage_message - File.read(File.join(spec.path, 'USAGE')) rescue '' - end - end - - - # The base generator for named components: models, controllers, mailers, - # etc. The target name is taken as the first argument and inflected to - # singular, plural, class, file, and table forms for your convenience. - # The remaining arguments are aliased to +actions+ as an array for - # controller and mailer convenience. - # - # Several useful local variables and methods are populated in the - # +initialize+ method. See below for a list of Attributes and - # External Aliases available to both the manifest and to all templates. - # - # If no name is provided, the generator raises a usage error with content - # optionally read from the USAGE file in the generator's base path. - # - # For example, the +controller+ generator takes the first argument as - # the name of the class and subsequent arguments as the names of - # actions to be generated: - # - # ./script/generate controller Article index new create - # - # See Rails::Generator::Base for a discussion of manifests, - # Rails::Generator::Commands::Create for methods available to the manifest, - # and Rails::Generator for a general discussion of generators. - class NamedBase < Base - attr_reader :name, :class_name, :singular_name, :plural_name, :table_name - attr_reader :class_path, :file_path, :class_nesting, :class_nesting_depth - alias_method :file_name, :singular_name - alias_method :actions, :args - - def initialize(runtime_args, runtime_options = {}) - super - - # Name argument is required. - usage if runtime_args.empty? - - @args = runtime_args.dup - base_name = @args.shift - assign_names!(base_name) - end - - protected - # Override with your own usage banner. - def banner - "Usage: #{$0} #{spec.name} #{spec.name.camelize}Name [options]" - end - - def attributes - @attributes ||= @args.collect do |attribute| - Rails::Generator::GeneratedAttribute.new(*attribute.split(":")) - end - end - - - private - def assign_names!(name) - @name = name - base_name, @class_path, @file_path, @class_nesting, @class_nesting_depth = extract_modules(@name) - @class_name_without_nesting, @singular_name, @plural_name = inflect_names(base_name) - @table_name = (!defined?(ActiveRecord::Base) || ActiveRecord::Base.pluralize_table_names) ? plural_name : singular_name - @table_name.gsub! '/', '_' - if @class_nesting.empty? - @class_name = @class_name_without_nesting - else - @table_name = @class_nesting.underscore << "_" << @table_name - @class_name = "#{@class_nesting}::#{@class_name_without_nesting}" - end - end - - # Extract modules from filesystem-style or ruby-style path: - # good/fun/stuff - # Good::Fun::Stuff - # produce the same results. - def extract_modules(name) - modules = name.include?('/') ? name.split('/') : name.split('::') - name = modules.pop - path = modules.map { |m| m.underscore } - file_path = (path + [name.underscore]).join('/') - nesting = modules.map { |m| m.camelize }.join('::') - [name, path, file_path, nesting, modules.size] - end - - def inflect_names(name) - camel = name.camelize - under = camel.underscore - plural = under.pluralize - [camel, under, plural] - end - end - end -end diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb deleted file mode 100644 index b684dc92be..0000000000 --- a/railties/lib/rails_generator/commands.rb +++ /dev/null @@ -1,621 +0,0 @@ -require 'delegate' -require 'optparse' -require 'fileutils' -require 'tempfile' -require 'erb' - -module Rails - module Generator - module Commands - # Here's a convenient way to get a handle on generator commands. - # Command.instance('destroy', my_generator) instantiates a Destroy - # delegate of my_generator ready to do your dirty work. - def self.instance(command, generator) - const_get(command.to_s.camelize).new(generator) - end - - # Even more convenient access to commands. Include Commands in - # the generator Base class to get a nice #command instance method - # which returns a delegate for the requested command. - def self.included(base) - base.send(:define_method, :command) do |command| - Commands.instance(command, self) - end - end - - - # Generator commands delegate Rails::Generator::Base and implement - # a standard set of actions. Their behavior is defined by the way - # they respond to these actions: Create brings life; Destroy brings - # death; List passively observes. - # - # Commands are invoked by replaying (or rewinding) the generator's - # manifest of actions. See Rails::Generator::Manifest and - # Rails::Generator::Base#manifest method that generator subclasses - # are required to override. - # - # Commands allows generators to "plug in" invocation behavior, which - # corresponds to the GoF Strategy pattern. - class Base < DelegateClass(Rails::Generator::Base) - # Replay action manifest. RewindBase subclass rewinds manifest. - def invoke! - manifest.replay(self) - after_generate - end - - def dependency(generator_name, args, runtime_options = {}) - logger.dependency(generator_name) do - self.class.new(instance(generator_name, args, full_options(runtime_options))).invoke! - end - end - - # Does nothing for all commands except Create. - def class_collisions(*class_names) - end - - # Does nothing for all commands except Create. - def readme(*args) - end - - protected - def current_migration_number - Dir.glob("#{RAILS_ROOT}/#{@migration_directory}/[0-9]*_*.rb").inject(0) do |max, file_path| - n = File.basename(file_path).split('_', 2).first.to_i - if n > max then n else max end - end - end - - def next_migration_number - current_migration_number + 1 - end - - def migration_directory(relative_path) - directory(@migration_directory = relative_path) - end - - def existing_migrations(file_name) - Dir.glob("#{@migration_directory}/[0-9]*_*.rb").grep(/[0-9]+_#{file_name}.rb$/) - end - - def migration_exists?(file_name) - not existing_migrations(file_name).empty? - end - - def next_migration_string(padding = 3) - if ActiveRecord::Base.timestamped_migrations - Time.now.utc.strftime("%Y%m%d%H%M%S") - else - "%.#{padding}d" % next_migration_number - end - end - - def gsub_file(relative_destination, regexp, *args, &block) - path = destination_path(relative_destination) - content = File.read(path).gsub(regexp, *args, &block) - File.open(path, 'wb') { |file| file.write(content) } - end - - private - # Ask the user interactively whether to force collision. - def force_file_collision?(destination, src, dst, file_options = {}, &block) - $stdout.print "overwrite #{destination}? (enter \"h\" for help) [Ynaqdh] " - case $stdin.gets.chomp - when /\Ad\z/i - Tempfile.open(File.basename(destination), File.dirname(dst)) do |temp| - temp.write render_file(src, file_options, &block) - temp.rewind - $stdout.puts `#{diff_cmd} "#{dst}" "#{temp.path}"` - end - puts "retrying" - raise 'retry diff' - when /\Aa\z/i - $stdout.puts "forcing #{spec.name}" - options[:collision] = :force - when /\Aq\z/i - $stdout.puts "aborting #{spec.name}" - raise SystemExit - when /\An\z/i then :skip - when /\Ay\z/i then :force - else - $stdout.puts <<-HELP -Y - yes, overwrite -n - no, do not overwrite -a - all, overwrite this and all others -q - quit, abort -d - diff, show the differences between the old and the new -h - help, show this help -HELP - raise 'retry' - end - rescue - retry - end - - def diff_cmd - ENV['RAILS_DIFF'] || 'diff -u' - end - - def render_template_part(template_options) - # Getting Sandbox to evaluate part template in it - part_binding = template_options[:sandbox].call.sandbox_binding - part_rel_path = template_options[:insert] - part_path = source_path(part_rel_path) - - # Render inner template within Sandbox binding - rendered_part = ERB.new(File.readlines(part_path).join, nil, '-').result(part_binding) - begin_mark = template_part_mark(template_options[:begin_mark], template_options[:mark_id]) - end_mark = template_part_mark(template_options[:end_mark], template_options[:mark_id]) - begin_mark + rendered_part + end_mark - end - - def template_part_mark(name, id) - "<!--[#{name}:#{id}]-->\n" - end - end - - # Base class for commands which handle generator actions in reverse, such as Destroy. - class RewindBase < Base - # Rewind action manifest. - def invoke! - manifest.rewind(self) - end - end - - - # Create is the premier generator command. It copies files, creates - # directories, renders templates, and more. - class Create < Base - - # Check whether the given class names are already taken by - # Ruby or Rails. In the future, expand to check other namespaces - # such as the rest of the user's app. - def class_collisions(*class_names) - path = class_names.shift - class_names.flatten.each do |class_name| - # Convert to string to allow symbol arguments. - class_name = class_name.to_s - - # Skip empty strings. - next if class_name.strip.empty? - - # Split the class from its module nesting. - nesting = class_name.split('::') - name = nesting.pop - - # Hack to limit const_defined? to non-inherited on 1.9. - extra = [] - extra << false unless Object.method(:const_defined?).arity == 1 - - # Extract the last Module in the nesting. - last = nesting.inject(Object) { |last, nest| - break unless last.const_defined?(nest, *extra) - last.const_get(nest) - } - - # If the last Module exists, check whether the given - # class exists and raise a collision if so. - if last and last.const_defined?(name.camelize, *extra) - raise_class_collision(class_name) - end - end - end - - # Copy a file from source to destination with collision checking. - # - # The file_options hash accepts :chmod and :shebang and :collision options. - # :chmod sets the permissions of the destination file: - # file 'config/empty.log', 'log/test.log', :chmod => 0664 - # :shebang sets the #!/usr/bin/ruby line for scripts - # file 'bin/generate.rb', 'script/generate', :chmod => 0755, :shebang => '/usr/bin/env ruby' - # :collision sets the collision option only for the destination file: - # file 'settings/server.yml', 'config/server.yml', :collision => :skip - # - # Collisions are handled by checking whether the destination file - # exists and either skipping the file, forcing overwrite, or asking - # the user what to do. - def file(relative_source, relative_destination, file_options = {}, &block) - # Determine full paths for source and destination files. - source = source_path(relative_source) - destination = destination_path(relative_destination) - destination_exists = File.exist?(destination) - - # If source and destination are identical then we're done. - if destination_exists and identical?(source, destination, &block) - return logger.identical(relative_destination) - end - - # Check for and resolve file collisions. - if destination_exists - - # Make a choice whether to overwrite the file. :force and - # :skip already have their mind made up, but give :ask a shot. - choice = case (file_options[:collision] || options[:collision]).to_sym #|| :ask - when :ask then force_file_collision?(relative_destination, source, destination, file_options, &block) - when :force then :force - when :skip then :skip - else raise "Invalid collision option: #{options[:collision].inspect}" - end - - # Take action based on our choice. Bail out if we chose to - # skip the file; otherwise, log our transgression and continue. - case choice - when :force then logger.force(relative_destination) - when :skip then return(logger.skip(relative_destination)) - else raise "Invalid collision choice: #{choice}.inspect" - end - - # File doesn't exist so log its unbesmirched creation. - else - logger.create relative_destination - end - - # If we're pretending, back off now. - return if options[:pretend] - - # Write destination file with optional shebang. Yield for content - # if block given so templaters may render the source file. If a - # shebang is requested, replace the existing shebang or insert a - # new one. - File.open(destination, 'wb') do |dest| - dest.write render_file(source, file_options, &block) - end - - # Optionally change permissions. - if file_options[:chmod] - FileUtils.chmod(file_options[:chmod], destination) - end - - # Optionally add file to subversion or git - system("svn add #{destination}") if options[:svn] - system("git add -v #{relative_destination}") if options[:git] - end - - # Checks if the source and the destination file are identical. If - # passed a block then the source file is a template that needs to first - # be evaluated before being compared to the destination. - def identical?(source, destination, &block) - return false if File.directory? destination - source = block_given? ? File.open(source) {|sf| yield(sf)} : IO.read(source) - destination = IO.read(destination) - source == destination - end - - # Generate a file for a Rails application using an ERuby template. - # Looks up and evaluates a template by name and writes the result. - # - # The ERB template uses explicit trim mode to best control the - # proliferation of whitespace in generated code. <%- trims leading - # whitespace; -%> trims trailing whitespace including one newline. - # - # A hash of template options may be passed as the last argument. - # The options accepted by the file are accepted as well as :assigns, - # a hash of variable bindings. Example: - # template 'foo', 'bar', :assigns => { :action => 'view' } - # - # Template is implemented in terms of file. It calls file with a - # block which takes a file handle and returns its rendered contents. - def template(relative_source, relative_destination, template_options = {}) - file(relative_source, relative_destination, template_options) do |file| - # Evaluate any assignments in a temporary, throwaway binding. - vars = template_options[:assigns] || {} - b = template_options[:binding] || binding - vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } - - # Render the source file with the temporary binding. - ERB.new(file.read, nil, '-').result(b) - end - end - - def complex_template(relative_source, relative_destination, template_options = {}) - options = template_options.dup - options[:assigns] ||= {} - options[:assigns]['template_for_inclusion'] = render_template_part(template_options) - template(relative_source, relative_destination, options) - end - - # Create a directory including any missing parent directories. - # Always skips directories which exist. - def directory(relative_path) - path = destination_path(relative_path) - if File.exist?(path) - logger.exists relative_path - else - logger.create relative_path - unless options[:pretend] - FileUtils.mkdir_p(path) - # git doesn't require adding the paths, adding the files later will - # automatically do a path add. - - # Subversion doesn't do path adds, so we need to add - # each directory individually. - # So stack up the directory tree and add the paths to - # subversion in order without recursion. - if options[:svn] - stack = [relative_path] - until File.dirname(stack.last) == stack.last # dirname('.') == '.' - stack.push File.dirname(stack.last) - end - stack.reverse_each do |rel_path| - svn_path = destination_path(rel_path) - system("svn add -N #{svn_path}") unless File.directory?(File.join(svn_path, '.svn')) - end - end - end - end - end - - # Display a README. - def readme(*relative_sources) - relative_sources.flatten.each do |relative_source| - logger.readme relative_source - puts File.read(source_path(relative_source)) unless options[:pretend] - end - end - - # When creating a migration, it knows to find the first available file in db/migrate and use the migration.rb template. - def migration_template(relative_source, relative_destination, template_options = {}) - migration_directory relative_destination - migration_file_name = template_options[:migration_file_name] || file_name - raise "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}" if migration_exists?(migration_file_name) - template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options) - end - - def route_resources(*resources) - resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') - sentinel = 'ActionController::Routing::Routes.draw do |map|' - - logger.route "map.resources #{resource_list}" - unless options[:pretend] - gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n map.resources #{resource_list}\n" - end - end - end - - private - def render_file(path, options = {}) - File.open(path, 'rb') do |file| - if block_given? - yield file - else - content = '' - if shebang = options[:shebang] - content << "#!#{shebang}\n" - if line = file.gets - content << "line\n" if line !~ /^#!/ - end - end - content << file.read - end - end - end - - # Raise a usage error with an informative WordNet suggestion. - # Thanks to Florian Gross (flgr). - def raise_class_collision(class_name) - message = <<end_message - The name '#{class_name}' is either already used in your application or reserved by Ruby on Rails. - Please choose an alternative and run this generator again. -end_message - if suggest = find_synonyms(class_name) - if suggest.any? - message << "\n Suggestions: \n\n" - message << suggest.join("\n") - end - end - raise UsageError, message - end - - SYNONYM_LOOKUP_URI = "http://wordnet.princeton.edu/perl/webwn?s=%s" - - # Look up synonyms on WordNet. Thanks to Florian Gross (flgr). - def find_synonyms(word) - require 'open-uri' - require 'timeout' - timeout(5) do - open(SYNONYM_LOOKUP_URI % word) do |stream| - # Grab words linked to dictionary entries as possible synonyms - data = stream.read.gsub(" ", " ").scan(/<a href="webwn.*?">([\w ]*?)<\/a>/s).uniq - end - end - rescue Exception - return nil - end - end - - - # Undo the actions performed by a generator. Rewind the action - # manifest and attempt to completely erase the results of each action. - class Destroy < RewindBase - # Remove a file if it exists and is a file. - def file(relative_source, relative_destination, file_options = {}) - destination = destination_path(relative_destination) - if File.exist?(destination) - logger.rm relative_destination - unless options[:pretend] - if options[:svn] - # If the file has been marked to be added - # but has not yet been checked in, revert and delete - if options[:svn][relative_destination] - system("svn revert #{destination}") - FileUtils.rm(destination) - else - # If the directory is not in the status list, it - # has no modifications so we can simply remove it - system("svn rm #{destination}") - end - elsif options[:git] - if options[:git][:new][relative_destination] - # file has been added, but not committed - system("git reset HEAD #{relative_destination}") - FileUtils.rm(destination) - elsif options[:git][:modified][relative_destination] - # file is committed and modified - system("git rm -f #{relative_destination}") - else - # If the directory is not in the status list, it - # has no modifications so we can simply remove it - system("git rm #{relative_destination}") - end - else - FileUtils.rm(destination) - end - end - else - logger.missing relative_destination - return - end - end - - # Templates are deleted just like files and the actions take the - # same parameters, so simply alias the file method. - alias_method :template, :file - - # Remove each directory in the given path from right to left. - # Remove each subdirectory if it exists and is a directory. - def directory(relative_path) - parts = relative_path.split('/') - until parts.empty? - partial = File.join(parts) - path = destination_path(partial) - if File.exist?(path) - if Dir[File.join(path, '*')].empty? - logger.rmdir partial - unless options[:pretend] - if options[:svn] - # If the directory has been marked to be added - # but has not yet been checked in, revert and delete - if options[:svn][relative_path] - system("svn revert #{path}") - FileUtils.rmdir(path) - else - # If the directory is not in the status list, it - # has no modifications so we can simply remove it - system("svn rm #{path}") - end - # I don't think git needs to remove directories?.. - # or maybe they have special consideration... - else - FileUtils.rmdir(path) - end - end - else - logger.notempty partial - end - else - logger.missing partial - end - parts.pop - end - end - - def complex_template(*args) - # nothing should be done here - end - - # When deleting a migration, it knows to delete every file named "[0-9]*_#{file_name}". - def migration_template(relative_source, relative_destination, template_options = {}) - migration_directory relative_destination - - migration_file_name = template_options[:migration_file_name] || file_name - unless migration_exists?(migration_file_name) - puts "There is no migration named #{migration_file_name}" - return - end - - - existing_migrations(migration_file_name).each do |file_path| - file(relative_source, file_path, template_options) - end - end - - def route_resources(*resources) - resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') - look_for = "\n map.resources #{resource_list}\n" - logger.route "map.resources #{resource_list}" - gsub_file 'config/routes.rb', /(#{look_for})/mi, '' - end - end - - - # List a generator's action manifest. - class List < Base - def dependency(generator_name, args, options = {}) - logger.dependency "#{generator_name}(#{args.join(', ')}, #{options.inspect})" - end - - def class_collisions(*class_names) - logger.class_collisions class_names.join(', ') - end - - def file(relative_source, relative_destination, options = {}) - logger.file relative_destination - end - - def template(relative_source, relative_destination, options = {}) - logger.template relative_destination - end - - def complex_template(relative_source, relative_destination, options = {}) - logger.template "#{options[:insert]} inside #{relative_destination}" - end - - def directory(relative_path) - logger.directory "#{destination_path(relative_path)}/" - end - - def readme(*args) - logger.readme args.join(', ') - end - - def migration_template(relative_source, relative_destination, options = {}) - migration_directory relative_destination - logger.migration_template file_name - end - - def route_resources(*resources) - resource_list = resources.map { |r| r.to_sym.inspect }.join(', ') - logger.route "map.resources #{resource_list}" - end - end - - # Update generator's action manifest. - class Update < Create - def file(relative_source, relative_destination, options = {}) - # logger.file relative_destination - end - - def template(relative_source, relative_destination, options = {}) - # logger.template relative_destination - end - - def complex_template(relative_source, relative_destination, template_options = {}) - - begin - dest_file = destination_path(relative_destination) - source_to_update = File.readlines(dest_file).join - rescue Errno::ENOENT - logger.missing relative_destination - return - end - - logger.refreshing "#{template_options[:insert].gsub(/\.erb/,'')} inside #{relative_destination}" - - begin_mark = Regexp.quote(template_part_mark(template_options[:begin_mark], template_options[:mark_id])) - end_mark = Regexp.quote(template_part_mark(template_options[:end_mark], template_options[:mark_id])) - - # Refreshing inner part of the template with freshly rendered part. - rendered_part = render_template_part(template_options) - source_to_update.gsub!(/#{begin_mark}.*?#{end_mark}/m, rendered_part) - - File.open(dest_file, 'w') { |file| file.write(source_to_update) } - end - - def directory(relative_path) - # logger.directory "#{destination_path(relative_path)}/" - end - end - - end - end -end diff --git a/railties/lib/rails_generator/generated_attribute.rb b/railties/lib/rails_generator/generated_attribute.rb deleted file mode 100644 index a3d4a01142..0000000000 --- a/railties/lib/rails_generator/generated_attribute.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'optparse' - -module Rails - module Generator - class GeneratedAttribute - attr_accessor :name, :type, :column - - def initialize(name, type) - @name, @type = name, type.to_sym - @column = ActiveRecord::ConnectionAdapters::Column.new(name, nil, @type) - end - - def field_type - @field_type ||= case type - when :integer, :float, :decimal then :text_field - when :datetime, :timestamp, :time then :datetime_select - when :date then :date_select - when :string then :text_field - when :text then :text_area - when :boolean then :check_box - else - :text_field - end - end - - def default - @default ||= case type - when :integer then 1 - when :float then 1.5 - when :decimal then "9.99" - when :datetime, :timestamp, :time then Time.now.to_s(:db) - when :date then Date.today.to_s(:db) - when :string then "MyString" - when :text then "MyText" - when :boolean then false - else - "" - end - end - - def reference? - [ :references, :belongs_to ].include?(self.type) - end - end - end -end diff --git a/railties/lib/rails_generator/generators/applications/app/USAGE b/railties/lib/rails_generator/generators/applications/app/USAGE deleted file mode 100644 index 36d6061a59..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/USAGE +++ /dev/null @@ -1,9 +0,0 @@ -Description: - The 'rails' command creates a new Rails application with a default - directory structure and configuration at the path you specify. - -Example: - rails ~/Code/Ruby/weblog - - This generates a skeletal Rails installation in ~/Code/Ruby/weblog. - See the README in the newly created application to get going. diff --git a/railties/lib/rails_generator/generators/applications/app/app_generator.rb b/railties/lib/rails_generator/generators/applications/app/app_generator.rb deleted file mode 100644 index c8c2239f34..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/app_generator.rb +++ /dev/null @@ -1,263 +0,0 @@ -require 'rbconfig' -require File.dirname(__FILE__) + '/template_runner' -require 'digest/md5' -require 'active_support/secure_random' - -class AppGenerator < Rails::Generator::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' - - mandatory_options :source => "#{File.dirname(__FILE__)}/../../../../.." - default_options :db => (ENV["RAILS_DEFAULT_DATABASE"] || DEFAULT_DATABASE), - :shebang => DEFAULT_SHEBANG, :with_dispatchers => false, :freeze => false - - - def initialize(runtime_args, runtime_options = {}) - super - - usage if args.empty? - usage("Databases supported for preconfiguration are: #{DATABASES.join(", ")}") if (options[:db] && !DATABASES.include?(options[:db])) - - @destination_root = args.shift - @app_name = File.basename(File.expand_path(@destination_root)) - end - - def manifest - record do |m| - create_directories(m) - create_root_files(m) - create_app_files(m) - create_config_files(m) - create_script_files(m) - create_test_files(m) - create_public_files(m) - create_documentation_file(m) - create_log_files(m) - end - end - - def after_generate - if options[:template] - Rails::TemplateRunner.new(options[:template], @destination_root) - end - end - - protected - def banner - "Usage: #{$0} /path/to/your/app [options]" - end - - def add_options!(opt) - opt.separator '' - opt.separator 'Options:' - opt.on("-r", "--ruby=path", String, - "Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).", - "Default: #{DEFAULT_SHEBANG}") { |v| options[:shebang] = v } - - opt.on("-d", "--database=name", String, - "Preconfigure for selected database (options: #{DATABASES.join('/')}).", - "Default: #{DEFAULT_DATABASE}") { |v| options[:db] = v } - - opt.on("-D", "--with-dispatchers", - "Add CGI/FastCGI/mod_ruby dispatches code to generated application skeleton", - "Default: false") { |v| options[:with_dispatchers] = v } - - opt.on("-f", "--freeze", - "Freeze Rails in vendor/rails from the gems generating the skeleton", - "Default: false") { |v| options[:freeze] = v } - - opt.on("-m", "--template=path", String, - "Use an application template that lives at path (can be a filesystem path or URL).", - "Default: (none)") { |v| options[:template] = v } - - end - - - private - def create_directories(m) - m.directory '' - - # Intermediate directories are automatically created so don't sweat their absence here. - %w( - app/controllers - app/helpers - app/models - app/views/layouts - 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| m.directory(path) } - end - - def create_root_files(m) - m.file "fresh_rakefile", "Rakefile" - m.file "README", "README" - end - - def create_app_files(m) - m.file "helpers/application_controller.rb", "app/controllers/application_controller.rb" - m.file "helpers/application_helper.rb", "app/helpers/application_helper.rb" - end - - def create_config_files(m) - create_database_configuration_file(m) - create_routes_file(m) - create_locale_file(m) - create_seeds_file(m) - create_initializer_files(m) - create_environment_files(m) - end - - def create_documentation_file(m) - m.file "doc/README_FOR_APP", "doc/README_FOR_APP" - end - - def create_log_files(m) - %w( server production development test ).each do |file| - m.file "configs/empty.log", "log/#{file}.log", :chmod => 0666 - end - end - - def create_public_files(m) - create_dispatch_files(m) - create_error_files(m) - create_welcome_file(m) - create_browser_convention_files(m) - create_rails_image(m) - create_javascript_files(m) - end - - def create_script_files(m) - %w( - about console dbconsole destroy generate runner server plugin - performance/benchmarker performance/profiler - ).each do |file| - m.file "bin/#{file}", "script/#{file}", { - :chmod => 0755, - :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] - } - end - end - - def create_test_files(m) - m.file "helpers/test_helper.rb", "test/test_helper.rb" - m.file "helpers/performance_test.rb", "test/performance/browsing_test.rb" - end - - - def create_database_configuration_file(m) - m.template "configs/databases/#{options[:db]}.yml", "config/database.yml", :assigns => { - :app_name => @app_name, - :socket => options[:db] == "mysql" ? mysql_socket_location : nil } - end - - def create_routes_file(m) - m.file "configs/routes.rb", "config/routes.rb" - end - - def create_seeds_file(m) - m.file "configs/seeds.rb", "db/seeds.rb" - end - - def create_initializer_files(m) - %w( - backtrace_silencers - inflections - mime_types - new_rails_defaults - ).each do |initializer| - m.file "configs/initializers/#{initializer}.rb", "config/initializers/#{initializer}.rb" - end - - m.template "configs/initializers/session_store.rb", "config/initializers/session_store.rb", - :assigns => { :app_name => @app_name, :app_secret => ActiveSupport::SecureRandom.hex(64) } - end - - def create_locale_file(m) - m.file "configs/locales/en.yml", "config/locales/en.yml" - end - - def create_environment_files(m) - m.template "environments/environment.rb", "config/environment.rb", - :assigns => { :freeze => options[:freeze] } - - m.file "environments/boot.rb", "config/boot.rb" - 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" - end - - - def create_dispatch_files(m) - if options[:with_dispatchers] - dispatcher_options = { :chmod => 0755, :shebang => options[:shebang] } - - m.file "dispatches/config.ru", "config.ru" - m.file "dispatches/dispatch.rb", "public/dispatch.rb", dispatcher_options - m.file "dispatches/dispatch.rb", "public/dispatch.cgi", dispatcher_options - m.file "dispatches/dispatch.fcgi", "public/dispatch.fcgi", dispatcher_options - end - end - - def create_error_files(m) - %w( 404 422 500 ).each do |file| - m.file "html/#{file}.html", "public/#{file}.html" - end - end - - def create_welcome_file(m) - m.file 'html/index.html', 'public/index.html' - end - - def create_browser_convention_files(m) - m.file "html/favicon.ico", "public/favicon.ico" - m.file "html/robots.txt", "public/robots.txt" - end - - def create_rails_image(m) - m.file "html/images/rails.png", "public/images/rails.png" - end - - def create_javascript_files(m) - %w( prototype effects dragdrop controls application ).each do |javascript| - m.file "html/javascripts/#{javascript}.js", "public/javascripts/#{javascript}.js" - end - end - - - def mysql_socket_location - [ - "/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
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/scm/git.rb b/railties/lib/rails_generator/generators/applications/app/scm/git.rb deleted file mode 100644 index 445de6ab42..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/scm/git.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Rails - class Git < Scm - def self.clone(repos, branch=nil) - `git clone #{repos}` - - if branch - `cd #{repos.split('/').last}/` - `git checkout #{branch}` - end - end - - def self.run(command) - `git #{command}` - end - end -end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/scm/scm.rb b/railties/lib/rails_generator/generators/applications/app/scm/scm.rb deleted file mode 100644 index f6c08cad39..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/scm/scm.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Rails - class Scm - private - def self.hash_to_parameters(hash) - hash.collect { |key, value| "--#{key} #{(value.kind_of?(String) ? value : "")}"}.join(" ") - end - end -end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/scm/svn.rb b/railties/lib/rails_generator/generators/applications/app/scm/svn.rb deleted file mode 100644 index 22b5966d25..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/scm/svn.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Rails - class Svn < Scm - def self.checkout(repos, branch = nil) - `svn checkout #{repos}/#{branch || "trunk"}` - end - end -end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb deleted file mode 100644 index 0e24d11950..0000000000 --- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb +++ /dev/null @@ -1,401 +0,0 @@ -require File.dirname(__FILE__) + '/scm/scm' -require File.dirname(__FILE__) + '/scm/git' -require File.dirname(__FILE__) + '/scm/svn' - -require 'open-uri' -require 'fileutils' - -module Rails - class TemplateRunner - attr_reader :root - attr_writer :logger - - def initialize(template, root = '') # :nodoc: - @root = File.expand_path(File.directory?(root) ? root : File.join(Dir.pwd, root)) - - log 'applying', "template: #{template}" - - load_template(template) - - log 'applied', "#{template}" - end - - def load_template(template) - begin - code = open(template).read - in_root { self.instance_eval(code) } - rescue LoadError, Errno::ENOENT => e - raise "The template [#{template}] could not be loaded. Error: #{e}" - end - end - - # Create a new file in the Rails project folder. Specify the - # relative path from RAILS_ROOT. Data is the return value of a block - # or a data string. - # - # ==== Examples - # - # file("lib/fun_party.rb") do - # hostname = ask("What is the virtual hostname I should use?") - # "vhost.name = #{hostname}" - # end - # - # file("config/apach.conf", "your apache config") - # - def file(filename, data = nil, log_action = true, &block) - log 'file', filename if log_action - dir, file = [File.dirname(filename), File.basename(filename)] - - inside(dir) do - File.open(file, "w") do |f| - if block_given? - f.write(block.call) - else - f.write(data) - end - end - end - end - - # Install a plugin. You must provide either a Subversion url or Git url. - # For a Git-hosted plugin, you can specify if it should be added as a submodule instead of cloned. - # - # ==== Examples - # - # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git' - # plugin 'restful-authentication', :git => 'git://github.com/technoweenie/restful-authentication.git', :submodule => true - # plugin 'restful-authentication', :svn => 'svn://svnhub.com/technoweenie/restful-authentication/trunk' - # - def plugin(name, options) - log 'plugin', name - - if options[:git] && options[:submodule] - in_root do - Git.run("submodule add #{options[:git]} vendor/plugins/#{name}") - end - elsif options[:git] || options[:svn] - in_root do - run_ruby_script("script/plugin install #{options[:svn] || options[:git]}", false) - end - else - log "! no git or svn provided for #{name}. skipping..." - end - end - - # Adds an entry into config/environment.rb for the supplied gem : - def gem(name, options = {}) - log 'gem', name - env = options.delete(:env) - - gems_code = "config.gem '#{name}'" - - if options.any? - opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ") - gems_code << ", #{opts}" - end - - environment gems_code, :env => env - end - - # Adds a line inside the Initializer block for config/environment.rb. Used by #gem - # If options :env is specified, the line is appended to the corresponding - # file in config/environments/#{env}.rb - def environment(data = nil, options = {}, &block) - sentinel = 'Rails::Initializer.run do |config|' - - data = block.call if !data && block_given? - - in_root do - if options[:env].nil? - gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n " << data - end - else - Array.wrap(options[:env]).each do|env| - append_file "config/environments/#{env}.rb", "\n#{data}" - end - end - end - end - - # Run a command in git. - # - # ==== Examples - # - # git :init - # git :add => "this.file that.rb" - # git :add => "onefile.rb", :rm => "badfile.cxx" - # - def git(command = {}) - in_root do - if command.is_a?(Symbol) - log 'running', "git #{command}" - Git.run(command.to_s) - else - command.each do |command, options| - log 'running', "git #{command} #{options}" - Git.run("#{command} #{options}") - end - end - end - end - - # Create a new file in the vendor/ directory. Code can be specified - # in a block or a data string can be given. - # - # ==== Examples - # - # vendor("sekrit.rb") do - # sekrit_salt = "#{Time.now}--#{3.years.ago}--#{rand}--" - # "salt = '#{sekrit_salt}'" - # end - # - # vendor("foreign.rb", "# Foreign code is fun") - # - def vendor(filename, data = nil, &block) - log 'vendoring', filename - file("vendor/#{filename}", data, false, &block) - end - - # Create a new file in the lib/ directory. Code can be specified - # in a block or a data string can be given. - # - # ==== Examples - # - # lib("crypto.rb") do - # "crypted_special_value = '#{rand}--#{Time.now}--#{rand(1337)}--'" - # end - # - # lib("foreign.rb", "# Foreign code is fun") - # - def lib(filename, data = nil, &block) - log 'lib', filename - file("lib/#{filename}", data, false, &block) - end - - # Create a new Rakefile with the provided code (either in a block or a string). - # - # ==== Examples - # - # rakefile("bootstrap.rake") do - # project = ask("What is the UNIX name of your project?") - # - # <<-TASK - # namespace :#{project} do - # task :bootstrap do - # puts "i like boots!" - # end - # end - # TASK - # end - # - # rakefile("seed.rake", "puts 'im plantin ur seedz'") - # - def rakefile(filename, data = nil, &block) - log 'rakefile', filename - file("lib/tasks/#{filename}", data, false, &block) - end - - # Create a new initializer with the provided code (either in a block or a string). - # - # ==== Examples - # - # initializer("globals.rb") do - # data = "" - # - # ['MY_WORK', 'ADMINS', 'BEST_COMPANY_EVAR'].each do - # data << "#{const} = :entp" - # end - # - # data - # end - # - # initializer("api.rb", "API_KEY = '123456'") - # - def initializer(filename, data = nil, &block) - log 'initializer', filename - file("config/initializers/#{filename}", data, false, &block) - end - - # Generate something using a generator from Rails or a plugin. - # The second parameter is the argument string that is passed to - # the generator or an Array that is joined. - # - # ==== Example - # - # generate(:authenticated, "user session") - # - def generate(what, *args) - log 'generating', what - argument = args.map {|arg| arg.to_s }.flatten.join(" ") - - in_root { run_ruby_script("script/generate #{what} #{argument}", false) } - end - - # Executes a command - # - # ==== Example - # - # inside('vendor') do - # run('ln -s ~/edge rails) - # end - # - def run(command, log_action = true) - log 'executing', "#{command} from #{Dir.pwd}" if log_action - `#{command}` - end - - # Executes a ruby script (taking into account WIN32 platform quirks) - def run_ruby_script(command, log_action = true) - ruby_command = RUBY_PLATFORM=~ /win32/ ? 'ruby ' : '' - run("#{ruby_command}#{command}", log_action) - end - - # Runs the supplied rake task - # - # ==== Example - # - # rake("db:migrate") - # rake("db:migrate", :env => "production") - # rake("gems:install", :sudo => true) - # - def rake(command, options = {}) - log 'rake', command - env = options[:env] || 'development' - sudo = options[:sudo] ? 'sudo ' : '' - in_root { run("#{sudo}rake #{command} RAILS_ENV=#{env}", false) } - end - - # Just run the capify command in root - # - # ==== Example - # - # capify! - # - def capify! - log 'capifying' - in_root { run('capify .', false) } - end - - # Add Rails to /vendor/rails - # - # ==== Example - # - # freeze! - # - def freeze!(args = {}) - log 'vendor', 'rails edge' - in_root { run('rake rails:freeze:edge', false) } - end - - # Make an entry in Rails routing file conifg/routes.rb - # - # === Example - # - # route "map.root :controller => :welcome" - # - def route(routing_code) - log 'route', routing_code - sentinel = 'ActionController::Routing::Routes.draw do |map|' - - in_root do - gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |match| - "#{match}\n #{routing_code}\n" - end - end - end - - protected - - # Get a user's input - # - # ==== Example - # - # answer = ask("Should I freeze the latest Rails?") - # freeze! if ask("Should I freeze the latest Rails?") == "yes" - # - def ask(string) - log '', string - STDIN.gets.strip - end - - # Do something in the root of the Rails application or - # a provided subfolder; the full path is yielded to the block you provide. - # The path is set back to the previous path when the method exits. - def inside(dir = '', &block) - folder = File.join(root, dir) - FileUtils.mkdir_p(folder) unless File.exist?(folder) - FileUtils.cd(folder) { block.arity == 1 ? yield(folder) : yield } - end - - def in_root - FileUtils.cd(root) { yield } - end - - # Helper to test if the user says yes(y)? - # - # ==== Example - # - # freeze! if yes?("Should I freeze the latest Rails?") - # - def yes?(question) - answer = ask(question).downcase - answer == "y" || answer == "yes" - end - - # Helper to test if the user does NOT say yes(y)? - # - # ==== Example - # - # capify! if no?("Will you be using vlad to deploy your application?") - # - def no?(question) - !yes?(question) - end - - # Run a regular expression replacement on a file - # - # ==== Example - # - # gsub_file 'app/controllers/application_controller.rb', /#\s*(filter_parameter_logging :password)/, '\1' - # - def gsub_file(relative_destination, regexp, *args, &block) - path = destination_path(relative_destination) - content = File.read(path).gsub(regexp, *args, &block) - File.open(path, 'wb') { |file| file.write(content) } - end - - # Append text to a file - # - # ==== Example - # - # append_file 'config/environments/test.rb', 'config.gem "rspec"' - # - def append_file(relative_destination, data) - path = destination_path(relative_destination) - File.open(path, 'ab') { |file| file.write(data) } - end - - def destination_path(relative_destination) - File.join(root, relative_destination) - end - - def log(action, message = '') - logger.log(action, message) - end - - def logger - @logger ||= Rails::Generator::Base.logger - end - - def logger - @logger ||= if defined?(Rails::Generator::Base) - Rails::Generator::Base.logger - else - require 'rails_generator/simple_logger' - Rails::Generator::SimpleLogger.new(STDOUT) - end - end - - end -end diff --git a/railties/lib/rails_generator/generators/components/controller/USAGE b/railties/lib/rails_generator/generators/components/controller/USAGE deleted file mode 100644 index 362872e84a..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/USAGE +++ /dev/null @@ -1,30 +0,0 @@ -Description: - Stubs out a new controller and its views. Pass the controller name, either - CamelCased or under_scored, and a list of views as arguments. - - To create a controller within a module, specify the controller name as a - path like 'parent_module/controller_name'. - - This generates a controller class in app/controllers, view templates in - app/views/controller_name, a helper class in app/helpers, a functional - test suite in test/functional and a helper test suite in test/unit/helpers. - -Example: - `./script/generate controller CreditCard open debit credit close` - - Credit card controller with URLs like /credit_card/debit. - Controller: app/controllers/credit_card_controller.rb - Functional Test: test/functional/credit_card_controller_test.rb - Views: app/views/credit_card/debit.html.erb [...] - Helper: app/helpers/credit_card_helper.rb - Helper Test: test/unit/helpers/credit_card_helper_test.rb - -Modules Example: - `./script/generate controller 'admin/credit_card' suspend late_fee` - - Credit card admin controller with URLs /admin/credit_card/suspend. - Controller: app/controllers/admin/credit_card_controller.rb - Functional Test: test/functional/admin/credit_card_controller_test.rb - Views: app/views/admin/credit_card/debit.html.erb [...] - Helper: app/helpers/admin/credit_card_helper.rb - Helper Test: test/unit/helpers/admin/credit_card_helper_test.rb diff --git a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb b/railties/lib/rails_generator/generators/components/controller/controller_generator.rb deleted file mode 100644 index dc126e8a98..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/controller_generator.rb +++ /dev/null @@ -1,43 +0,0 @@ -class ControllerGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper", "#{class_name}HelperTest" - - # Controller, helper, views, and test directories. - m.directory File.join('app/controllers', class_path) - m.directory File.join('app/helpers', class_path) - m.directory File.join('app/views', class_path, file_name) - m.directory File.join('test/functional', class_path) - m.directory File.join('test/unit/helpers', class_path) - - # Controller class, functional test, and helper class. - m.template 'controller.rb', - File.join('app/controllers', - class_path, - "#{file_name}_controller.rb") - - m.template 'functional_test.rb', - File.join('test/functional', - class_path, - "#{file_name}_controller_test.rb") - - m.template 'helper.rb', - File.join('app/helpers', - class_path, - "#{file_name}_helper.rb") - - m.template 'helper_test.rb', - File.join('test/unit/helpers', - class_path, - "#{file_name}_helper_test.rb") - - # View template for each action. - actions.each do |action| - path = File.join('app/views', class_path, file_name, "#{action}.html.erb") - m.template 'view.html.erb', path, - :assigns => { :action => action, :path => path } - end - end - end -end diff --git a/railties/lib/rails_generator/generators/components/controller/templates/controller.rb b/railties/lib/rails_generator/generators/components/controller/templates/controller.rb deleted file mode 100644 index cda2659e69..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/templates/controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class <%= class_name %>Controller < ApplicationController -<% for action in actions -%> - def <%= action %> - end - -<% end -%> -end diff --git a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb deleted file mode 100644 index 62fa5d86fd..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= class_name %>ControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/controller/templates/helper.rb b/railties/lib/rails_generator/generators/components/controller/templates/helper.rb deleted file mode 100644 index 3fe2ecdc74..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/templates/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module <%= class_name %>Helper -end diff --git a/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb deleted file mode 100644 index 591e40900e..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/templates/helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class <%= class_name %>HelperTest < ActionView::TestCase -end diff --git a/railties/lib/rails_generator/generators/components/controller/templates/view.html.erb b/railties/lib/rails_generator/generators/components/controller/templates/view.html.erb deleted file mode 100644 index ad85431f98..0000000000 --- a/railties/lib/rails_generator/generators/components/controller/templates/view.html.erb +++ /dev/null @@ -1,2 +0,0 @@ -<h1><%= class_name %>#<%= action %></h1> -<p>Find me in <%= path %></p> diff --git a/railties/lib/rails_generator/generators/components/helper/USAGE b/railties/lib/rails_generator/generators/components/helper/USAGE deleted file mode 100644 index ef27ca617e..0000000000 --- a/railties/lib/rails_generator/generators/components/helper/USAGE +++ /dev/null @@ -1,24 +0,0 @@ -Description: - Stubs out a new helper. Pass the helper name, either - CamelCased or under_scored. - - To create a helper within a module, specify the helper name as a - path like 'parent_module/helper_name'. - - This generates a helper class in app/helpers and a helper test - suite in test/unit/helpers. - -Example: - `./script/generate helper CreditCard` - - Credit card helper. - Helper: app/helpers/credit_card_helper.rb - Test: test/unit/helpers/credit_card_helper_test.rb - -Modules Example: - `./script/generate helper 'admin/credit_card'` - - Credit card admin helper. - Helper: app/helpers/admin/credit_card_helper.rb - Test: test/unit/helpers/admin/credit_card_helper_test.rb - diff --git a/railties/lib/rails_generator/generators/components/helper/helper_generator.rb b/railties/lib/rails_generator/generators/components/helper/helper_generator.rb deleted file mode 100644 index f7831f7c7a..0000000000 --- a/railties/lib/rails_generator/generators/components/helper/helper_generator.rb +++ /dev/null @@ -1,25 +0,0 @@ -class HelperGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_path, "#{class_name}Helper", "#{class_name}HelperTest" - - # Helper and helper test directories. - m.directory File.join('app/helpers', class_path) - m.directory File.join('test/unit/helpers', class_path) - - # Helper and helper test class. - - m.template 'helper.rb', - File.join('app/helpers', - class_path, - "#{file_name}_helper.rb") - - m.template 'helper_test.rb', - File.join('test/unit/helpers', - class_path, - "#{file_name}_helper_test.rb") - - end - end -end diff --git a/railties/lib/rails_generator/generators/components/helper/templates/helper.rb b/railties/lib/rails_generator/generators/components/helper/templates/helper.rb deleted file mode 100644 index 3fe2ecdc74..0000000000 --- a/railties/lib/rails_generator/generators/components/helper/templates/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module <%= class_name %>Helper -end diff --git a/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb deleted file mode 100644 index 591e40900e..0000000000 --- a/railties/lib/rails_generator/generators/components/helper/templates/helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class <%= class_name %>HelperTest < ActionView::TestCase -end diff --git a/railties/lib/rails_generator/generators/components/integration_test/USAGE b/railties/lib/rails_generator/generators/components/integration_test/USAGE deleted file mode 100644 index 09e2691f69..0000000000 --- a/railties/lib/rails_generator/generators/components/integration_test/USAGE +++ /dev/null @@ -1,8 +0,0 @@ -Description: - Stubs out a new integration test. Pass the name of the test, either - CamelCased or under_scored, as an argument. The new test class is - generated in test/integration/testname_test.rb - -Example: - `./script/generate integration_test GeneralStories` creates a GeneralStories - integration test in test/integration/general_stories_test.rb diff --git a/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb b/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb deleted file mode 100644 index 44323f28ca..0000000000 --- a/railties/lib/rails_generator/generators/components/integration_test/integration_test_generator.rb +++ /dev/null @@ -1,16 +0,0 @@ -class IntegrationTestGenerator < Rails::Generator::NamedBase - default_options :skip_migration => false - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # integration test directory - m.directory File.join('test/integration', class_path) - - # integration test stub - m.template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb") - end - end -end diff --git a/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb b/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb deleted file mode 100644 index 2c57158b1c..0000000000 --- a/railties/lib/rails_generator/generators/components/integration_test/templates/integration_test.rb +++ /dev/null @@ -1,10 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActionController::IntegrationTest - fixtures :all - - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/mailer/USAGE b/railties/lib/rails_generator/generators/components/mailer/USAGE deleted file mode 100644 index 61a649ed4d..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/USAGE +++ /dev/null @@ -1,16 +0,0 @@ -Description: - Stubs out a new mailer and its views. Pass the mailer name, either - CamelCased or under_scored, and an optional list of emails as arguments. - - This generates a mailer class in app/models, view templates in - app/views/mailer_name, a unit test in test/unit, and fixtures in - test/fixtures. - -Example: - `./script/generate mailer Notifications signup forgot_password invoice` - - creates a Notifications mailer class, views, test, and fixtures: - Mailer: app/models/notifications.rb - Views: app/views/notifications/signup.erb [...] - Test: test/unit/test/unit/notifications_test.rb - Fixtures: test/fixtures/notifications/signup [...] diff --git a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb b/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb deleted file mode 100644 index ba6d60cac6..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/mailer_generator.rb +++ /dev/null @@ -1,30 +0,0 @@ -class MailerGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # Mailer, view, test, and fixture directories. - m.directory File.join('app/models', class_path) - m.directory File.join('app/views', file_path) - m.directory File.join('test/unit', class_path) - m.directory File.join('test/fixtures', file_path) - - # Mailer class and unit test. - m.template "mailer.rb", File.join('app/models', class_path, "#{file_name}.rb") - m.template "unit_test.rb", File.join('test/unit', class_path, "#{file_name}_test.rb") - - # View template and fixture for each action. - actions.each do |action| - relative_path = File.join(file_path, action) - view_path = File.join('app/views', "#{relative_path}.erb") - fixture_path = File.join('test/fixtures', relative_path) - - m.template "view.erb", view_path, - :assigns => { :action => action, :path => view_path } - m.template "fixture.erb", fixture_path, - :assigns => { :action => action, :path => view_path } - end - end - end -end diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/fixture.erb b/railties/lib/rails_generator/generators/components/mailer/templates/fixture.erb deleted file mode 100644 index 6899257ddc..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/fixture.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= class_name %>#<%= action %> - -Find me in <%= path %> diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml b/railties/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +++ /dev/null diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/mailer.rb b/railties/lib/rails_generator/generators/components/mailer/templates/mailer.rb deleted file mode 100644 index ce15ae9de9..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/mailer.rb +++ /dev/null @@ -1,15 +0,0 @@ -class <%= class_name %> < ActionMailer::Base - -<% for action in actions -%> - - def <%= action %>(sent_at = Time.now) - subject '<%= class_name %>#<%= action %>' - recipients '' - from '' - sent_on sent_at - - body :greeting => 'Hi,' - end -<% end -%> - -end diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb deleted file mode 100644 index 4de94076e9..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActionMailer::TestCase -<% for action in actions -%> - test "<%= action %>" do - @expected.subject = '<%= class_name %>#<%= action %>' - @expected.body = read_fixture('<%= action %>') - @expected.date = Time.now - - assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded - end - -<% end -%> -<% if actions.blank? -%> - # replace this with your real tests - test "the truth" do - assert true - end -<% end -%> -end diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/view.erb b/railties/lib/rails_generator/generators/components/mailer/templates/view.erb deleted file mode 100644 index 6899257ddc..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/view.erb +++ /dev/null @@ -1,3 +0,0 @@ -<%= class_name %>#<%= action %> - -Find me in <%= path %> diff --git a/railties/lib/rails_generator/generators/components/mailer/templates/view.rhtml b/railties/lib/rails_generator/generators/components/mailer/templates/view.rhtml deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/lib/rails_generator/generators/components/mailer/templates/view.rhtml +++ /dev/null diff --git a/railties/lib/rails_generator/generators/components/metal/USAGE b/railties/lib/rails_generator/generators/components/metal/USAGE deleted file mode 100644 index 123ec6c03f..0000000000 --- a/railties/lib/rails_generator/generators/components/metal/USAGE +++ /dev/null @@ -1,8 +0,0 @@ -Description: - Cast some metal! - -Examples: - `./script/generate metal poller` - - This will create: - Metal: app/metal/poller.rb diff --git a/railties/lib/rails_generator/generators/components/metal/metal_generator.rb b/railties/lib/rails_generator/generators/components/metal/metal_generator.rb deleted file mode 100644 index 64f49d929d..0000000000 --- a/railties/lib/rails_generator/generators/components/metal/metal_generator.rb +++ /dev/null @@ -1,8 +0,0 @@ -class MetalGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - m.directory 'app/metal' - m.template 'metal.rb', File.join('app/metal', "#{file_name}.rb") - end - end -end diff --git a/railties/lib/rails_generator/generators/components/metal/templates/metal.rb b/railties/lib/rails_generator/generators/components/metal/templates/metal.rb deleted file mode 100644 index e94982b69a..0000000000 --- a/railties/lib/rails_generator/generators/components/metal/templates/metal.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Allow the metal piece to run in isolation -require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) - -class <%= class_name %> - def self.call(env) - if env["PATH_INFO"] =~ /^\/<%= file_name %>/ - [200, {"Content-Type" => "text/html"}, ["Hello, World!"]] - else - [404, {"Content-Type" => "text/html"}, ["Not Found"]] - end - end -end diff --git a/railties/lib/rails_generator/generators/components/migration/USAGE b/railties/lib/rails_generator/generators/components/migration/USAGE deleted file mode 100644 index b83c657963..0000000000 --- a/railties/lib/rails_generator/generators/components/migration/USAGE +++ /dev/null @@ -1,29 +0,0 @@ -Description: - Stubs out a new database migration. Pass the migration name, either - CamelCased or under_scored, and an optional list of attribute pairs as arguments. - - A migration class is generated in db/migrate prefixed by a timestamp of the current date and time. - - You can name your migration in either of these formats to generate add/remove - column lines from supplied attributes: AddColumnsToTable or RemoveColumnsFromTable - -Example: - `./script/generate migration AddSslFlag` - - If the current date is May 14, 2008 and the current time 09:09:12, this creates the AddSslFlag migration - db/migrate/20080514090912_add_ssl_flag.rb - - `./script/generate migration AddTitleBodyToPost title:string body:text published:boolean` - - This will create the AddTitleBodyToPost in db/migrate/20080514090912_add_title_body_to_post.rb with - this in the Up migration: - - add_column :posts, :title, :string - add_column :posts, :body, :text - add_column :posts, :published, :boolean - - And this in the Down migration: - - remove_column :posts, :published - remove_column :posts, :body - remove_column :posts, :title diff --git a/railties/lib/rails_generator/generators/components/migration/migration_generator.rb b/railties/lib/rails_generator/generators/components/migration/migration_generator.rb deleted file mode 100644 index acf41e07df..0000000000 --- a/railties/lib/rails_generator/generators/components/migration/migration_generator.rb +++ /dev/null @@ -1,20 +0,0 @@ -class MigrationGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - m.migration_template 'migration.rb', 'db/migrate', :assigns => get_local_assigns - end - end - - - private - def get_local_assigns - returning(assigns = {}) do - if class_name.underscore =~ /^(add|remove)_.*_(?:to|from)_(.*)/ - assigns[:migration_action] = $1 - assigns[:table_name] = $2.pluralize - else - assigns[:attributes] = [] - end - end - end -end diff --git a/railties/lib/rails_generator/generators/components/migration/templates/migration.rb b/railties/lib/rails_generator/generators/components/migration/templates/migration.rb deleted file mode 100644 index ca35a43229..0000000000 --- a/railties/lib/rails_generator/generators/components/migration/templates/migration.rb +++ /dev/null @@ -1,11 +0,0 @@ -class <%= class_name.underscore.camelize %> < ActiveRecord::Migration - def self.up<% attributes.each do |attribute| %> - <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%> - <%- end %> - end - - def self.down<% attributes.reverse.each do |attribute| %> - <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%> - <%- end %> - end -end diff --git a/railties/lib/rails_generator/generators/components/model/USAGE b/railties/lib/rails_generator/generators/components/model/USAGE deleted file mode 100644 index 24b03b4d4a..0000000000 --- a/railties/lib/rails_generator/generators/components/model/USAGE +++ /dev/null @@ -1,27 +0,0 @@ -Description: - Stubs out a new model. Pass the model name, either CamelCased or - under_scored, and an optional list of attribute pairs as arguments. - - Attribute pairs are column_name:sql_type arguments specifying the - model's attributes. Timestamps are added by default, so you don't have to - specify them by hand as 'created_at:datetime updated_at:datetime'. - - You don't have to think up every attribute up front, but it helps to - sketch out a few so you can start working with the model immediately. - - This generates a model class in app/models, a unit test in test/unit, - a test fixture in test/fixtures/singular_name.yml, and a migration in - db/migrate. - -Examples: - `./script/generate model account` - - creates an Account model, test, fixture, and migration: - Model: app/models/account.rb - Test: test/unit/account_test.rb - Fixtures: test/fixtures/accounts.yml - Migration: db/migrate/XXX_add_accounts.rb - - `./script/generate model post title:string body:text published:boolean` - - creates a Post model with a string title, text body, and published flag. diff --git a/railties/lib/rails_generator/generators/components/model/model_generator.rb b/railties/lib/rails_generator/generators/components/model/model_generator.rb deleted file mode 100644 index 582a28922f..0000000000 --- a/railties/lib/rails_generator/generators/components/model/model_generator.rb +++ /dev/null @@ -1,45 +0,0 @@ -class ModelGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # Model, test, and fixture directories. - m.directory File.join('app/models', class_path) - m.directory File.join('test/unit', class_path) - m.directory File.join('test/fixtures', class_path) - - # Model class, unit test, and fixtures. - m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") - m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") - - unless options[:skip_fixture] - m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") - end - - unless options[:skip_migration] - m.migration_template 'migration.rb', 'db/migrate', :assigns => { - :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" - }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}" - end - end - end - - protected - def banner - "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]" - end - - def add_options!(opt) - opt.separator '' - opt.separator 'Options:' - opt.on("--skip-timestamps", - "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v } - opt.on("--skip-migration", - "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } - opt.on("--skip-fixture", - "Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v} - end -end diff --git a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml deleted file mode 100644 index c21035113e..0000000000 --- a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml +++ /dev/null @@ -1,19 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html - -<% unless attributes.empty? -%> -one: -<% for attribute in attributes -%> - <%= attribute.name %>: <%= attribute.default %> -<% end -%> - -two: -<% for attribute in attributes -%> - <%= attribute.name %>: <%= attribute.default %> -<% end -%> -<% else -%> -# one: -# column: value -# -# two: -# column: value -<% end -%> diff --git a/railties/lib/rails_generator/generators/components/model/templates/migration.rb b/railties/lib/rails_generator/generators/components/model/templates/migration.rb deleted file mode 100644 index 382fd1156e..0000000000 --- a/railties/lib/rails_generator/generators/components/model/templates/migration.rb +++ /dev/null @@ -1,16 +0,0 @@ -class <%= migration_name %> < ActiveRecord::Migration - def self.up - create_table :<%= table_name %> do |t| -<% for attribute in attributes -%> - t.<%= attribute.type %> :<%= attribute.name %> -<% end -%> -<% unless options[:skip_timestamps] %> - t.timestamps -<% end -%> - end - end - - def self.down - drop_table :<%= table_name %> - end -end diff --git a/railties/lib/rails_generator/generators/components/model/templates/model.rb b/railties/lib/rails_generator/generators/components/model/templates/model.rb deleted file mode 100644 index 0656b06dfe..0000000000 --- a/railties/lib/rails_generator/generators/components/model/templates/model.rb +++ /dev/null @@ -1,5 +0,0 @@ -class <%= class_name %> < ActiveRecord::Base -<% attributes.select {|attr| attr.reference? }.each do |attribute| -%> - belongs_to :<%= attribute.name %> -<% end -%> -end diff --git a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb deleted file mode 100644 index 3e0bc29d3a..0000000000 --- a/railties/lib/rails_generator/generators/components/model/templates/unit_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/model_subclass/USAGE b/railties/lib/rails_generator/generators/components/model_subclass/USAGE deleted file mode 100644 index a4b558a401..0000000000 --- a/railties/lib/rails_generator/generators/components/model_subclass/USAGE +++ /dev/null @@ -1,13 +0,0 @@ -Description: - Create a model subclass of parent, used for Single Table Inheritance. - - Both subclass and parent name can be either CamelCased or under_scored. - - This generates a model class in app/models and a unit test in test/unit. - -Examples: - `./script/generate model_subclass admin user` - - creates an Admin model, which will inheritate from User model, test: - Model: app/models/admin.rb - Test: test/unit/admin_test.rb diff --git a/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb b/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb deleted file mode 100644 index e8ac3da2cd..0000000000 --- a/railties/lib/rails_generator/generators/components/model_subclass/model_subclass_generator.rb +++ /dev/null @@ -1,32 +0,0 @@ -class ModelSubclassGenerator < Rails::Generator::NamedBase - default_options :skip_unit_test => false - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # Model and test directories. - m.directory File.join('app/models', class_path) - m.directory File.join('test/unit', class_path) - - # Model class and unit test - m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb"), :assigns => assigns - m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb"), :assigns => assigns - - end - end - - protected - def banner - "Usage: #{$0} #{spec.name} Subclass Parent" - end - - def assigns - {:parent_class_name => parent_class_name} - end - - def parent_class_name - @args.first.try(:camelize) || usage - end -end diff --git a/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb b/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb deleted file mode 100644 index d0037b322b..0000000000 --- a/railties/lib/rails_generator/generators/components/model_subclass/templates/model.rb +++ /dev/null @@ -1,3 +0,0 @@ -class <%= class_name %> < <%= parent_class_name %> - -end
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb deleted file mode 100644 index 3e0bc29d3a..0000000000 --- a/railties/lib/rails_generator/generators/components/model_subclass/templates/unit_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/observer/USAGE b/railties/lib/rails_generator/generators/components/observer/USAGE deleted file mode 100644 index a5d744a3c2..0000000000 --- a/railties/lib/rails_generator/generators/components/observer/USAGE +++ /dev/null @@ -1,13 +0,0 @@ -Description: - Stubs out a new observer. Pass the observer name, either CamelCased or - under_scored, as an argument. - - The generator creates an observer class in app/models and a unit test in - test/unit. - -Example: - `./script/generate observer Account` - - creates an Account observer and unit test: - Observer: app/models/account_observer.rb - Test: test/unit/account_observer_test.rb diff --git a/railties/lib/rails_generator/generators/components/observer/observer_generator.rb b/railties/lib/rails_generator/generators/components/observer/observer_generator.rb deleted file mode 100644 index 3c4b330a80..0000000000 --- a/railties/lib/rails_generator/generators/components/observer/observer_generator.rb +++ /dev/null @@ -1,16 +0,0 @@ -class ObserverGenerator < Rails::Generator::NamedBase - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions "#{class_name}Observer", "#{class_name}ObserverTest" - - # Observer, and test directories. - m.directory File.join('app/models', class_path) - m.directory File.join('test/unit', class_path) - - # Observer class and unit test fixtures. - m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb") - m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb") - end - end -end diff --git a/railties/lib/rails_generator/generators/components/observer/templates/observer.rb b/railties/lib/rails_generator/generators/components/observer/templates/observer.rb deleted file mode 100644 index b9a3004161..0000000000 --- a/railties/lib/rails_generator/generators/components/observer/templates/observer.rb +++ /dev/null @@ -1,2 +0,0 @@ -class <%= class_name %>Observer < ActiveRecord::Observer -end diff --git a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb deleted file mode 100644 index 03f6d5666e..0000000000 --- a/railties/lib/rails_generator/generators/components/observer/templates/unit_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= class_name %>ObserverTest < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/performance_test/USAGE b/railties/lib/rails_generator/generators/components/performance_test/USAGE deleted file mode 100644 index d84051eb02..0000000000 --- a/railties/lib/rails_generator/generators/components/performance_test/USAGE +++ /dev/null @@ -1,8 +0,0 @@ -Description: - Stubs out a new performance test. Pass the name of the test, either - CamelCased or under_scored, as an argument. The new test class is - generated in test/performance/testname_test.rb - -Example: - `./script/generate performance_test GeneralStories` creates a GeneralStories - performance test in test/performance/general_stories_test.rb diff --git a/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb b/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb deleted file mode 100644 index 83ce8ac674..0000000000 --- a/railties/lib/rails_generator/generators/components/performance_test/performance_test_generator.rb +++ /dev/null @@ -1,16 +0,0 @@ -class PerformanceTestGenerator < Rails::Generator::NamedBase - default_options :skip_migration => false - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name, "#{class_name}Test" - - # performance test directory - m.directory File.join('test/performance', class_path) - - # performance test stub - m.template 'performance_test.rb', File.join('test/performance', class_path, "#{file_name}_test.rb") - end - end -end diff --git a/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb b/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb deleted file mode 100644 index 27c91b0fca..0000000000 --- a/railties/lib/rails_generator/generators/components/performance_test/templates/performance_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'test_helper' -require 'performance_test_help' - -class <%= class_name %>Test < ActionController::PerformanceTest - # Replace this with your real tests. - def test_homepage - get '/' - end -end diff --git a/railties/lib/rails_generator/generators/components/plugin/USAGE b/railties/lib/rails_generator/generators/components/plugin/USAGE deleted file mode 100644 index d2ecfc2d59..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/USAGE +++ /dev/null @@ -1,25 +0,0 @@ -Description: - Stubs out a new plugin. Pass the plugin name, either CamelCased or - under_scored, as an argument. Pass --with-generator to add an example - generator also. - - This creates a plugin in vendor/plugins including an init.rb and README - as well as standard lib, task, and test directories. - -Example: - `./script/generate plugin BrowserFilters` - - creates a standard browser_filters plugin: - vendor/plugins/browser_filters/README - vendor/plugins/browser_filters/init.rb - vendor/plugins/browser_filters/install.rb - vendor/plugins/browser_filters/lib/browser_filters.rb - vendor/plugins/browser_filters/test/browser_filters_test.rb - vendor/plugins/browser_filters/tasks/browser_filters_tasks.rake - - ./script/generate plugin BrowserFilters --with-generator - - creates a browser_filters generator also: - vendor/plugins/browser_filters/generators/browser_filters/browser_filters_generator.rb - vendor/plugins/browser_filters/generators/browser_filters/USAGE - vendor/plugins/browser_filters/generators/browser_filters/templates/ diff --git a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb b/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb deleted file mode 100644 index 6826998252..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/plugin_generator.rb +++ /dev/null @@ -1,39 +0,0 @@ -class PluginGenerator < Rails::Generator::NamedBase - attr_reader :plugin_path - - def initialize(runtime_args, runtime_options = {}) - @with_generator = runtime_args.delete("--with-generator") - super - @plugin_path = "vendor/plugins/#{file_name}" - end - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions class_name - - m.directory "#{plugin_path}/lib" - m.directory "#{plugin_path}/tasks" - m.directory "#{plugin_path}/test" - - m.template 'README', "#{plugin_path}/README" - m.template 'MIT-LICENSE', "#{plugin_path}/MIT-LICENSE" - m.template 'Rakefile', "#{plugin_path}/Rakefile" - m.template 'init.rb', "#{plugin_path}/init.rb" - m.template 'install.rb', "#{plugin_path}/install.rb" - m.template 'uninstall.rb', "#{plugin_path}/uninstall.rb" - m.template 'plugin.rb', "#{plugin_path}/lib/#{file_name}.rb" - m.template 'tasks.rake', "#{plugin_path}/tasks/#{file_name}_tasks.rake" - m.template 'unit_test.rb', "#{plugin_path}/test/#{file_name}_test.rb" - m.template 'test_helper.rb', "#{plugin_path}/test/test_helper.rb" - if @with_generator - m.directory "#{plugin_path}/generators" - m.directory "#{plugin_path}/generators/#{file_name}" - m.directory "#{plugin_path}/generators/#{file_name}/templates" - - m.template 'generator.rb', "#{plugin_path}/generators/#{file_name}/#{file_name}_generator.rb" - m.template 'USAGE', "#{plugin_path}/generators/#{file_name}/USAGE" - end - end - end -end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE b/railties/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE deleted file mode 100644 index 8717df053d..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) <%= Date.today.year %> [name of plugin creator] - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/README b/railties/lib/rails_generator/generators/components/plugin/templates/README deleted file mode 100644 index 702db07cb1..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/README +++ /dev/null @@ -1,13 +0,0 @@ -<%= class_name %> -<%= "=" * class_name.size %> - -Introduction goes here. - - -Example -======= - -Example goes here. - - -Copyright (c) <%= Date.today.year %> [name of plugin creator], released under the MIT license diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile b/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile deleted file mode 100644 index 85e8ff1834..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/Rakefile +++ /dev/null @@ -1,23 +0,0 @@ -require 'rake' -require 'rake/testtask' -require 'rake/rdoctask' - -desc 'Default: run unit tests.' -task :default => :test - -desc 'Test the <%= file_name %> plugin.' -Rake::TestTask.new(:test) do |t| - t.libs << 'lib' - t.libs << 'test' - t.pattern = 'test/**/*_test.rb' - t.verbose = true -end - -desc 'Generate documentation for the <%= file_name %> plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = '<%= class_name %>' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/USAGE b/railties/lib/rails_generator/generators/components/plugin/templates/USAGE deleted file mode 100644 index ea9f4f12cc..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/USAGE +++ /dev/null @@ -1,8 +0,0 @@ -Description: - Explain the generator - -Example: - ./script/generate <%= file_name %> Thing - - This will create: - what/will/it/create diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/generator.rb b/railties/lib/rails_generator/generators/components/plugin/templates/generator.rb deleted file mode 100644 index 3e800df6c5..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/generator.rb +++ /dev/null @@ -1,8 +0,0 @@ -class <%= class_name %>Generator < Rails::Generator::NamedBase - def manifest - record do |m| - # m.directory "lib" - # m.template 'README', "README" - end - end -end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/init.rb b/railties/lib/rails_generator/generators/components/plugin/templates/init.rb deleted file mode 100644 index 3c19a743c9..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/init.rb +++ /dev/null @@ -1 +0,0 @@ -# Include hook code here diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/install.rb b/railties/lib/rails_generator/generators/components/plugin/templates/install.rb deleted file mode 100644 index f7732d3796..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/install.rb +++ /dev/null @@ -1 +0,0 @@ -# Install hook code here diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/plugin.rb b/railties/lib/rails_generator/generators/components/plugin/templates/plugin.rb deleted file mode 100644 index d8d908a959..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/plugin.rb +++ /dev/null @@ -1 +0,0 @@ -# <%= class_name %> diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/tasks.rake b/railties/lib/rails_generator/generators/components/plugin/templates/tasks.rake deleted file mode 100644 index 72920a9d3a..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/tasks.rake +++ /dev/null @@ -1,4 +0,0 @@ -# desc "Explaining what the task does" -# task :<%= file_name %> do -# # Task goes here -# end diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb b/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb deleted file mode 100644 index cf148b8b47..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/test_helper.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'rubygems' -require 'active_support' -require 'active_support/test_case'
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/uninstall.rb b/railties/lib/rails_generator/generators/components/plugin/templates/uninstall.rb deleted file mode 100644 index 9738333463..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +++ /dev/null @@ -1 +0,0 @@ -# Uninstall hook code here diff --git a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb b/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb deleted file mode 100644 index 3e0bc29d3a..0000000000 --- a/railties/lib/rails_generator/generators/components/plugin/templates/unit_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= class_name %>Test < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/resource/USAGE b/railties/lib/rails_generator/generators/components/resource/USAGE deleted file mode 100644 index e6043f1de1..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/USAGE +++ /dev/null @@ -1,23 +0,0 @@ -Description: - Stubs out a new resource including an empty model and controller suitable - for a restful, resource-oriented application. Pass the singular model name, - either CamelCased or under_scored, as the first argument, and an optional - list of attribute pairs. - - Attribute pairs are column_name:sql_type arguments specifying the - model's attributes. Timestamps are added by default, so you don't have to - specify them by hand as 'created_at:datetime updated_at:datetime'. - - You don't have to think up every attribute up front, but it helps to - sketch out a few so you can start working with the resource immediately. - - This creates a model, controller, helper, tests and fixtures for all of them, - and the corresponding map.resources declaration in config/routes.rb - - Unlike the scaffold generator, the resource generator does not create - views or add any methods to the generated controller. - -Examples: - `./script/generate resource post` # no attributes - `./script/generate resource post title:string body:text published:boolean` - `./script/generate resource purchase order_id:integer amount:decimal` diff --git a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb b/railties/lib/rails_generator/generators/components/resource/resource_generator.rb deleted file mode 100644 index 4ee2fbff63..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/resource_generator.rb +++ /dev/null @@ -1,76 +0,0 @@ -class ResourceGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, :skip_migration => false - - attr_reader :controller_name, - :controller_class_path, - :controller_file_path, - :controller_class_nesting, - :controller_class_nesting_depth, - :controller_class_name, - :controller_singular_name, - :controller_plural_name - alias_method :controller_file_name, :controller_singular_name - alias_method :controller_table_name, :controller_plural_name - - def initialize(runtime_args, runtime_options = {}) - super - - @controller_name = @name.pluralize - - base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) - @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) - - if @controller_class_nesting.empty? - @controller_class_name = @controller_class_name_without_nesting - else - @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" - end - end - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper") - m.class_collisions(class_name) - - # Controller, helper, views, and test directories. - m.directory(File.join('app/models', class_path)) - m.directory(File.join('app/controllers', controller_class_path)) - m.directory(File.join('app/helpers', controller_class_path)) - m.directory(File.join('app/views', controller_class_path, controller_file_name)) - m.directory(File.join('test/functional', controller_class_path)) - m.directory(File.join('test/unit', class_path)) - m.directory(File.join('test/unit/helpers', class_path)) - - m.dependency 'model', [name] + @args, :collision => :skip - - m.template( - 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb") - ) - - m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) - m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) - m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) - - m.route_resources controller_file_name - end - end - - protected - def banner - "Usage: #{$0} resource ModelName [field:type, field:type]" - end - - def add_options!(opt) - opt.separator '' - opt.separator 'Options:' - opt.on("--skip-timestamps", - "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v } - opt.on("--skip-migration", - "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } - end - - def model_name - class_name.demodulize - end -end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/controller.rb b/railties/lib/rails_generator/generators/components/resource/templates/controller.rb deleted file mode 100644 index 765a942694..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/templates/controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class <%= controller_class_name %>Controller < ApplicationController -end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb deleted file mode 100644 index b1bb1dacbf..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/templates/functional_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test_helper' - -class <%= controller_class_name %>ControllerTest < ActionController::TestCase - # Replace this with your real tests. - test "the truth" do - assert true - end -end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/helper.rb b/railties/lib/rails_generator/generators/components/resource/templates/helper.rb deleted file mode 100644 index 9bd821b1b2..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/templates/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module <%= controller_class_name %>Helper -end diff --git a/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb deleted file mode 100644 index 061f64a5e3..0000000000 --- a/railties/lib/rails_generator/generators/components/resource/templates/helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class <%= controller_class_name %>HelperTest < ActionView::TestCase -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/USAGE b/railties/lib/rails_generator/generators/components/scaffold/USAGE deleted file mode 100644 index 810aea16f1..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/USAGE +++ /dev/null @@ -1,29 +0,0 @@ -Description: - Scaffolds an entire resource, from model and migration to controller and - views, along with a full test suite. The resource is ready to use as a - starting point for your RESTful, resource-oriented application. - - Pass the name of the model (in singular form), either CamelCased or - under_scored, as the first argument, and an optional list of attribute - pairs. - - Attribute pairs are column_name:sql_type arguments specifying the - model's attributes. Timestamps are added by default, so you don't have to - specify them by hand as 'created_at:datetime updated_at:datetime'. - - You don't have to think up every attribute up front, but it helps to - sketch out a few so you can start working with the resource immediately. - - For example, 'scaffold post title:string body:text published:boolean' - gives you a model with those three attributes, a controller that handles - the create/show/update/destroy, forms to create and edit your posts, and - an index that lists them all, as well as a map.resources :posts - declaration in config/routes.rb. - - If you want to remove all the generated files, run - 'script/destroy scaffold ModelName'. - -Examples: - `./script/generate scaffold post` - `./script/generate scaffold post title:string body:text published:boolean` - `./script/generate scaffold purchase order_id:integer amount:decimal` diff --git a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb b/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb deleted file mode 100644 index 2a5edeedb6..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +++ /dev/null @@ -1,102 +0,0 @@ -class ScaffoldGenerator < Rails::Generator::NamedBase - default_options :skip_timestamps => false, :skip_migration => false, :force_plural => false - - attr_reader :controller_name, - :controller_class_path, - :controller_file_path, - :controller_class_nesting, - :controller_class_nesting_depth, - :controller_class_name, - :controller_underscore_name, - :controller_singular_name, - :controller_plural_name - alias_method :controller_file_name, :controller_underscore_name - alias_method :controller_table_name, :controller_plural_name - - def initialize(runtime_args, runtime_options = {}) - super - - if @name == @name.pluralize && !options[:force_plural] - logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural." - @name = @name.singularize - end - - @controller_name = @name.pluralize - - base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) - @controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name) - @controller_singular_name=base_name.singularize - if @controller_class_nesting.empty? - @controller_class_name = @controller_class_name_without_nesting - else - @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" - end - end - - def manifest - record do |m| - # Check for class naming collisions. - m.class_collisions("#{controller_class_name}Controller", "#{controller_class_name}Helper") - m.class_collisions(class_name) - - # Controller, helper, views, test and stylesheets directories. - m.directory(File.join('app/models', class_path)) - m.directory(File.join('app/controllers', controller_class_path)) - m.directory(File.join('app/helpers', controller_class_path)) - m.directory(File.join('app/views', controller_class_path, controller_file_name)) - m.directory(File.join('app/views/layouts', controller_class_path)) - m.directory(File.join('test/functional', controller_class_path)) - m.directory(File.join('test/unit', class_path)) - m.directory(File.join('test/unit/helpers', class_path)) - m.directory(File.join('public/stylesheets', class_path)) - - for action in scaffold_views - m.template( - "view_#{action}.html.erb", - File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.erb") - ) - end - - # Layout and stylesheet. - m.template('layout.html.erb', File.join('app/views/layouts', controller_class_path, "#{controller_file_name}.html.erb")) - m.template('style.css', 'public/stylesheets/scaffold.css') - - m.template( - 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb") - ) - - m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")) - m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb")) - m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb")) - - m.route_resources controller_file_name - - m.dependency 'model', [name] + @args, :collision => :skip - end - end - - protected - # Override with your own usage banner. - def banner - "Usage: #{$0} scaffold ModelName [field:type, field:type]" - end - - def add_options!(opt) - opt.separator '' - opt.separator 'Options:' - opt.on("--skip-timestamps", - "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v } - opt.on("--skip-migration", - "Don't generate a migration file for this model") { |v| options[:skip_migration] = v } - opt.on("--force-plural", - "Forces the generation of a plural ModelName") { |v| options[:force_plural] = v } - end - - def scaffold_views - %w[ index show new edit ] - end - - def model_name - class_name.demodulize - end -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb deleted file mode 100644 index 4d190b9362..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/controller.rb +++ /dev/null @@ -1,85 +0,0 @@ -class <%= controller_class_name %>Controller < ApplicationController - # GET /<%= table_name %> - # GET /<%= table_name %>.xml - def index - @<%= table_name %> = <%= class_name %>.all - - respond_to do |format| - format.html # index.html.erb - format.xml { render :xml => @<%= table_name %> } - end - end - - # GET /<%= table_name %>/1 - # GET /<%= table_name %>/1.xml - def show - @<%= file_name %> = <%= class_name %>.find(params[:id]) - - respond_to do |format| - format.html # show.html.erb - format.xml { render :xml => @<%= file_name %> } - end - end - - # GET /<%= table_name %>/new - # GET /<%= table_name %>/new.xml - def new - @<%= file_name %> = <%= class_name %>.new - - respond_to do |format| - format.html # new.html.erb - format.xml { render :xml => @<%= file_name %> } - end - end - - # GET /<%= table_name %>/1/edit - def edit - @<%= file_name %> = <%= class_name %>.find(params[:id]) - end - - # POST /<%= table_name %> - # POST /<%= table_name %>.xml - def create - @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>]) - - respond_to do |format| - if @<%= file_name %>.save - flash[:notice] = '<%= class_name %> was successfully created.' - format.html { redirect_to(@<%= file_name %>) } - format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> } - else - format.html { render :action => "new" } - format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity } - end - end - end - - # PUT /<%= table_name %>/1 - # PUT /<%= table_name %>/1.xml - def update - @<%= file_name %> = <%= class_name %>.find(params[:id]) - - respond_to do |format| - if @<%= file_name %>.update_attributes(params[:<%= file_name %>]) - flash[:notice] = '<%= class_name %> was successfully updated.' - format.html { redirect_to(@<%= file_name %>) } - format.xml { head :ok } - else - format.html { render :action => "edit" } - format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity } - end - end - end - - # DELETE /<%= table_name %>/1 - # DELETE /<%= table_name %>/1.xml - def destroy - @<%= file_name %> = <%= class_name %>.find(params[:id]) - @<%= file_name %>.destroy - - respond_to do |format| - format.html { redirect_to(<%= table_name %>_url) } - format.xml { head :ok } - end - end -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb deleted file mode 100644 index cd2fc578bf..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'test_helper' - -class <%= controller_class_name %>ControllerTest < ActionController::TestCase - test "should get index" do - get :index - assert_response :success - assert_not_nil assigns(:<%= table_name %>) - end - - test "should get new" do - get :new - assert_response :success - end - - test "should create <%= file_name %>" do - assert_difference('<%= class_name %>.count') do - post :create, :<%= file_name %> => { } - end - - assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) - end - - test "should show <%= file_name %>" do - get :show, :id => <%= table_name %>(:one).to_param - assert_response :success - end - - test "should get edit" do - get :edit, :id => <%= table_name %>(:one).to_param - assert_response :success - end - - test "should update <%= file_name %>" do - put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { } - assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) - end - - test "should destroy <%= file_name %>" do - assert_difference('<%= class_name %>.count', -1) do - delete :destroy, :id => <%= table_name %>(:one).to_param - end - - assert_redirected_to <%= table_name %>_path - end -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/helper.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/helper.rb deleted file mode 100644 index 9bd821b1b2..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module <%= controller_class_name %>Helper -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb b/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb deleted file mode 100644 index 061f64a5e3..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class <%= controller_class_name %>HelperTest < ActionView::TestCase -end diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb deleted file mode 100644 index aacfbe4a8f..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/layout.html.erb +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE html> -<html> -<head> - <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> - <title><%= controller_class_name %>: <%%= controller.action_name %></title> - <%%= stylesheet_link_tag 'scaffold' %> -</head> -<body> - -<p style="color: green"><%%= flash[:notice] %></p> - -<%%= yield %> - -</body> -</html> diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/style.css b/railties/lib/rails_generator/generators/components/scaffold/templates/style.css deleted file mode 100644 index 093c20994d..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/style.css +++ /dev/null @@ -1,54 +0,0 @@ -body { background-color: #fff; color: #333; } - -body, p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; -} - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; -} - -a { color: #000; } -a:visited { color: #666; } -a:hover { color: #fff; background-color:#000; } - -.fieldWithErrors { - padding: 2px; - background-color: red; - display: table; -} - -#errorExplanation { - width: 400px; - border: 2px solid red; - padding: 7px; - padding-bottom: 12px; - margin-bottom: 20px; - background-color: #f0f0f0; -} - -#errorExplanation h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px; - background-color: #c00; - color: #fff; -} - -#errorExplanation p { - color: #333; - margin-bottom: 0; - padding: 5px; -} - -#errorExplanation ul li { - font-size: 12px; - list-style: square; -} - diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb deleted file mode 100644 index cca1d61c68..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_edit.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -<h1>Editing <%= singular_name %></h1> - -<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> - -<% for attribute in attributes -%> - <p> - <%%= f.label :<%= attribute.name %> %><br /> - <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> - </p> -<% end -%> - <p> - <%%= f.submit 'Update' %> - </p> -<%% end %> - -<%%= link_to 'Show', @<%= singular_name %> %> | -<%%= link_to 'Back', <%= plural_name %>_path %>
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb deleted file mode 100644 index 69beb388db..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_index.html.erb +++ /dev/null @@ -1,27 +0,0 @@ -<h1>Listing <%= plural_name %></h1> - -<table> - <tr> -<% for attribute in attributes -%> - <th><%= attribute.column.human_name %></th> -<% end -%> - <th></th> - <th></th> - <th></th> - </tr> - -<%% @<%= plural_name %>.each do |<%= singular_name %>| %> - <tr> -<% for attribute in attributes -%> - <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td> -<% end -%> - <td><%%= link_to 'Show', <%= singular_name %> %></td> - <td><%%= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>) %></td> - <td><%%= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td> - </tr> -<%% end %> -</table> - -<br /> - -<%%= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path %>
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb deleted file mode 100644 index 96c89fc50e..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_new.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -<h1>New <%= singular_name %></h1> - -<%% form_for(@<%= singular_name %>) do |f| %> - <%%= f.error_messages %> - -<% for attribute in attributes -%> - <p> - <%%= f.label :<%= attribute.name %> %><br /> - <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %> - </p> -<% end -%> - <p> - <%%= f.submit 'Create' %> - </p> -<%% end %> - -<%%= link_to 'Back', <%= plural_name %>_path %>
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb b/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb deleted file mode 100644 index adecaf70c6..0000000000 --- a/railties/lib/rails_generator/generators/components/scaffold/templates/view_show.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% for attribute in attributes -%> -<p> - <b><%= attribute.column.human_name %>:</b> - <%%=h @<%= singular_name %>.<%= attribute.name %> %> -</p> - -<% end -%> - -<%%= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>) %> | -<%%= link_to 'Back', <%= plural_name %>_path %>
\ No newline at end of file diff --git a/railties/lib/rails_generator/generators/components/session_migration/USAGE b/railties/lib/rails_generator/generators/components/session_migration/USAGE deleted file mode 100644 index 87117a3cb6..0000000000 --- a/railties/lib/rails_generator/generators/components/session_migration/USAGE +++ /dev/null @@ -1,10 +0,0 @@ -Description: - Creates a migration to add the sessions table used by the Active Record - session store. Pass the migration name, either CamelCased or under_scored, - as an argument. - -Example: - `./script/generate session_migration CreateSessionTable` - - With 4 existing migrations, this creates the AddSessionTable migration - in db/migrate/005_add_session_table.rb diff --git a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb b/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb deleted file mode 100644 index 2e177033a1..0000000000 --- a/railties/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +++ /dev/null @@ -1,18 +0,0 @@ -class SessionMigrationGenerator < Rails::Generator::NamedBase - def initialize(runtime_args, runtime_options = {}) - runtime_args << 'add_session_table' if runtime_args.empty? - super - end - - def manifest - record do |m| - m.migration_template 'migration.rb', 'db/migrate', - :assigns => { :session_table_name => default_session_table_name } - end - end - - protected - def default_session_table_name - ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session' - end -end diff --git a/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb b/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb deleted file mode 100644 index ca220a5f23..0000000000 --- a/railties/lib/rails_generator/generators/components/session_migration/templates/migration.rb +++ /dev/null @@ -1,16 +0,0 @@ -class <%= class_name %> < ActiveRecord::Migration - def self.up - create_table :<%= session_table_name %> do |t| - t.string :session_id, :null => false - t.text :data - t.timestamps - end - - add_index :<%= session_table_name %>, :session_id - add_index :<%= session_table_name %>, :updated_at - end - - def self.down - drop_table :<%= session_table_name %> - end -end diff --git a/railties/lib/rails_generator/lookup.rb b/railties/lib/rails_generator/lookup.rb deleted file mode 100644 index a3525364a2..0000000000 --- a/railties/lib/rails_generator/lookup.rb +++ /dev/null @@ -1,249 +0,0 @@ -require 'pathname' - -require File.dirname(__FILE__) + '/spec' - -class Object - class << self - # Lookup missing generators using const_missing. This allows any - # generator to reference another without having to know its location: - # RubyGems, ~/.rails/generators, and RAILS_ROOT/generators. - def lookup_missing_generator(class_id) - if md = /(.+)Generator$/.match(class_id.to_s) - name = md.captures.first.demodulize.underscore - Rails::Generator::Base.lookup(name).klass - else - const_missing_before_generators(class_id) - end - end - - unless respond_to?(:const_missing_before_generators) - alias_method :const_missing_before_generators, :const_missing - alias_method :const_missing, :lookup_missing_generator - end - end -end - -# User home directory lookup adapted from RubyGems. -def Dir.user_home - if ENV['HOME'] - ENV['HOME'] - elsif ENV['USERPROFILE'] - ENV['USERPROFILE'] - elsif ENV['HOMEDRIVE'] and ENV['HOMEPATH'] - "#{ENV['HOMEDRIVE']}:#{ENV['HOMEPATH']}" - else - File.expand_path '~' - end -end - - -module Rails - module Generator - - # Generator lookup is managed by a list of sources which return specs - # describing where to find and how to create generators. This module - # provides class methods for manipulating the source list and looking up - # generator specs, and an #instance wrapper for quickly instantiating - # generators by name. - # - # A spec is not a generator: it's a description of where to find - # the generator and how to create it. A source is anything that - # yields generators from #each. PathSource and GemGeneratorSource are provided. - module Lookup - def self.included(base) - base.extend(ClassMethods) - base.use_component_sources! - end - - # Convenience method to instantiate another generator. - def instance(generator_name, args, runtime_options = {}) - self.class.instance(generator_name, args, runtime_options) - end - - module ClassMethods - # The list of sources where we look, in order, for generators. - def sources - read_inheritable_attribute(:sources) or use_component_sources! - end - - # Add a source to the end of the list. - def append_sources(*args) - sources.concat(args.flatten) - invalidate_cache! - end - - # Add a source to the beginning of the list. - def prepend_sources(*args) - write_inheritable_array(:sources, args.flatten + sources) - invalidate_cache! - end - - # Reset the source list. - def reset_sources - write_inheritable_attribute(:sources, []) - invalidate_cache! - end - - # Use application generators (app, ?). - def use_application_sources! - reset_sources - sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/applications") - end - - # Use component generators (model, controller, etc). - # 1. Rails application. If RAILS_ROOT is defined we know we're - # generating in the context of a Rails application, so search - # RAILS_ROOT/generators. - # 2. Look in plugins, either for generators/ or rails_generators/ - # directories within each plugin - # 3. User home directory. Search ~/.rails/generators. - # 4. RubyGems. Search for gems named *_generator, and look for - # generators within any RubyGem's - # /rails_generators/<generator_name>_generator.rb file. - # 5. Builtins. Model, controller, mailer, scaffold, and so on. - def use_component_sources! - reset_sources - if defined? ::RAILS_ROOT - sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators") - sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators") - Rails.configuration.plugin_paths.each do |path| - relative_path = Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(::RAILS_ROOT)) - sources << PathSource.new(:"plugins (#{relative_path})", "#{path}/*/**/{,rails_}generators") - end - end - sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators") - if Object.const_defined?(:Gem) - sources << GemGeneratorSource.new - sources << GemPathSource.new - end - sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components") - end - - # Lookup knows how to find generators' Specs from a list of Sources. - # Searches the sources, in order, for the first matching name. - def lookup(generator_name) - @found ||= {} - generator_name = generator_name.to_s.downcase - @found[generator_name] ||= cache.find { |spec| spec.name == generator_name } - unless @found[generator_name] - chars = generator_name.scan(/./).map{|c|"#{c}.*?"} - rx = /^#{chars}$/ - gns = cache.select{|spec| spec.name =~ rx } - @found[generator_name] ||= gns.first if gns.length == 1 - raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1 - end - @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator" - end - - # Convenience method to lookup and instantiate a generator. - def instance(generator_name, args = [], runtime_options = {}) - lookup(generator_name).klass.new(args, full_options(runtime_options)) - end - - private - # Lookup and cache every generator from the source list. - def cache - @cache ||= sources.inject([]) { |cache, source| cache + source.to_a } - end - - # Clear the cache whenever the source list changes. - def invalidate_cache! - @cache = nil - end - end - end - - # Sources enumerate (yield from #each) generator specs which describe - # where to find and how to create generators. Enumerable is mixed in so, - # for example, source.collect will retrieve every generator. - # Sources may be assigned a label to distinguish them. - class Source - include Enumerable - - attr_reader :label - def initialize(label) - @label = label - end - - # The each method must be implemented in subclasses. - # The base implementation raises an error. - def each - raise NotImplementedError - end - - # Return a convenient sorted list of all generator names. - def names - map { |spec| spec.name }.sort - end - end - - - # PathSource looks for generators in a filesystem directory. - class PathSource < Source - attr_reader :path - - def initialize(label, path) - super label - @path = path - end - - # Yield each eligible subdirectory. - def each - Dir["#{path}/[a-z]*"].each do |dir| - if File.directory?(dir) - yield Spec.new(File.basename(dir), dir, label) - end - end - end - end - - class AbstractGemSource < Source - def initialize - super :RubyGems - end - end - - # GemGeneratorSource hits the mines to quarry for generators. The latest versions - # of gems named *_generator are selected. - class GemGeneratorSource < AbstractGemSource - # Yield latest versions of generator gems. - def each - dependency = Gem::Dependency.new(/_generator$/, Gem::Requirement.default) - Gem::cache.search(dependency).inject({}) { |latest, gem| - hem = latest[gem.name] - latest[gem.name] = gem if hem.nil? or gem.version > hem.version - latest - }.values.each { |gem| - yield Spec.new(gem.name.sub(/_generator$/, ''), gem.full_gem_path, label) - } - end - end - - # GemPathSource looks for generators within any RubyGem's /rails_generators/<generator_name>_generator.rb file. - class GemPathSource < AbstractGemSource - # Yield each generator within rails_generator subdirectories. - def each - generator_full_paths.each do |generator| - yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label) - end - end - - private - def generator_full_paths - @generator_full_paths ||= - Gem::cache.inject({}) do |latest, name_gem| - name, gem = name_gem - hem = latest[gem.name] - latest[gem.name] = gem if hem.nil? or gem.version > hem.version - latest - end.values.inject([]) do |mem, gem| - Dir[gem.full_gem_path + '/{rails_,}generators/**/*_generator.rb'].each do |generator| - mem << generator - end - mem - end - end - end - - end -end diff --git a/railties/lib/rails_generator/manifest.rb b/railties/lib/rails_generator/manifest.rb deleted file mode 100644 index 702effa76f..0000000000 --- a/railties/lib/rails_generator/manifest.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Rails - module Generator - - # Manifest captures the actions a generator performs. Instantiate - # a manifest with an optional target object, hammer it with actions, - # then replay or rewind on the object of your choice. - # - # Example: - # manifest = Manifest.new { |m| - # m.make_directory '/foo' - # m.create_file '/foo/bar.txt' - # } - # manifest.replay(creator) - # manifest.rewind(destroyer) - class Manifest - attr_reader :target - - # Take a default action target. Yield self if block given. - def initialize(target = nil) - @target, @actions = target, [] - yield self if block_given? - end - - # Record an action. - def method_missing(action, *args, &block) - @actions << [action, args, block] - end - - # Replay recorded actions. - def replay(target = nil) - send_actions(target || @target, @actions) - end - - # Rewind recorded actions. - def rewind(target = nil) - send_actions(target || @target, @actions.reverse) - end - - # Erase recorded actions. - def erase - @actions = [] - end - - private - def send_actions(target, actions) - actions.each do |method, args, block| - target.send(method, *args, &block) - end - end - end - - end -end diff --git a/railties/lib/rails_generator/options.rb b/railties/lib/rails_generator/options.rb deleted file mode 100644 index 5f6aefa921..0000000000 --- a/railties/lib/rails_generator/options.rb +++ /dev/null @@ -1,150 +0,0 @@ -require 'optparse' - -module Rails - module Generator - module Options - def self.included(base) - base.extend(ClassMethods) - class << base - if respond_to?(:inherited) - alias_method :inherited_without_options, :inherited - end - alias_method :inherited, :inherited_with_options - end - end - - module ClassMethods - def inherited_with_options(sub) - inherited_without_options(sub) if respond_to?(:inherited_without_options) - sub.extend(Rails::Generator::Options::ClassMethods) - end - - def mandatory_options(options = nil) - if options - write_inheritable_attribute(:mandatory_options, options) - else - read_inheritable_attribute(:mandatory_options) or write_inheritable_attribute(:mandatory_options, {}) - end - end - - def default_options(options = nil) - if options - write_inheritable_attribute(:default_options, options) - else - read_inheritable_attribute(:default_options) or write_inheritable_attribute(:default_options, {}) - end - end - - # Merge together our class options. In increasing precedence: - # default_options (class default options) - # runtime_options (provided as argument) - # mandatory_options (class mandatory options) - def full_options(runtime_options = {}) - default_options.merge(runtime_options).merge(mandatory_options) - end - - end - - # Each instance has an options hash that's populated by #parse. - def options - @options ||= {} - end - attr_writer :options - - protected - # Convenient access to class mandatory options. - def mandatory_options - self.class.mandatory_options - end - - # Convenient access to class default options. - def default_options - self.class.default_options - end - - # Merge together our instance options. In increasing precedence: - # default_options (class default options) - # options (instance options) - # runtime_options (provided as argument) - # mandatory_options (class mandatory options) - def full_options(runtime_options = {}) - self.class.full_options(options.merge(runtime_options)) - end - - # Parse arguments into the options hash. Classes may customize - # parsing behavior by overriding these methods: - # #banner Usage: ./script/generate [options] - # #add_options! Options: - # some options.. - # #add_general_options! General Options: - # general options.. - def parse!(args, runtime_options = {}) - self.options = {} - - @option_parser = OptionParser.new do |opt| - opt.banner = banner - add_options!(opt) - add_general_options!(opt) - opt.parse!(args) - end - - return args - ensure - self.options = full_options(runtime_options) - end - - # Raise a usage error. Override usage_message to provide a blurb - # after the option parser summary. - def usage(message = usage_message) - raise UsageError, "#{@option_parser}\n#{message}" - end - - def usage_message - '' - end - - # Override with your own usage banner. - def banner - "Usage: #{$0} [options]" - end - - # Override to add your options to the parser: - # def add_options!(opt) - # opt.on('-v', '--verbose') { |value| options[:verbose] = value } - # end - def add_options!(opt) - end - - # Adds general options like -h and --quiet. Usually don't override. - def add_general_options!(opt) - opt.separator '' - opt.separator 'Rails Info:' - opt.on('-v', '--version', 'Show the Rails version number and quit.') - opt.on('-h', '--help', 'Show this help message and quit.') { |v| options[:help] = v } - - opt.separator '' - opt.separator 'General Options:' - - opt.on('-p', '--pretend', 'Run but do not make any changes.') { |v| options[:pretend] = v } - opt.on('-f', '--force', 'Overwrite files that already exist.') { options[:collision] = :force } - opt.on('-s', '--skip', 'Skip files that already exist.') { options[:collision] = :skip } - opt.on('-q', '--quiet', 'Suppress normal output.') { |v| options[:quiet] = v } - opt.on('-t', '--backtrace', 'Debugging: show backtrace on errors.') { |v| options[:backtrace] = v } - opt.on('-c', '--svn', 'Modify files with subversion. (Note: svn must be in path)') do - options[:svn] = `svn status`.inject({}) do |opt, e| - opt[e.chomp[7..-1]] = true - opt - end - end - opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do - options[:git] = `git status`.inject({:new => {}, :modified => {}}) do |opt, e| - opt[:new][e.chomp[14..-1]] = true if e =~ /new file:/ - opt[:modified][e.chomp[14..-1]] = true if e =~ /modified:/ - opt - end - end - end - - end - end -end diff --git a/railties/lib/rails_generator/scripts.rb b/railties/lib/rails_generator/scripts.rb deleted file mode 100644 index 3763b75dba..0000000000 --- a/railties/lib/rails_generator/scripts.rb +++ /dev/null @@ -1,89 +0,0 @@ -require File.dirname(__FILE__) + '/options' - -module Rails - module Generator - module Scripts - - # Generator scripts handle command-line invocation. Each script - # responds to an invoke! class method which handles option parsing - # and generator invocation. - class Base - include Options - default_options :collision => :ask, :quiet => false - - # Run the generator script. Takes an array of unparsed arguments - # and a hash of parsed arguments, takes the generator as an option - # or first remaining argument, and invokes the requested command. - def run(args = [], runtime_options = {}) - begin - parse!(args.dup, runtime_options) - rescue OptionParser::InvalidOption => e - # Don't cry, script. Generators want what you think is invalid. - end - - # Generator name is the only required option. - unless options[:generator] - usage if args.empty? - options[:generator] ||= args.shift - end - - # Look up generator instance and invoke command on it. - Rails::Generator::Base.instance(options[:generator], args, options).command(options[:command]).invoke! - rescue => e - puts e - puts " #{e.backtrace.join("\n ")}\n" if options[:backtrace] - raise SystemExit - end - - protected - # Override with your own script usage banner. - def banner - "Usage: #{$0} generator [options] [args]" - end - - def usage_message - usage = "\nInstalled Generators\n" - Rails::Generator::Base.sources.inject([]) do |mem, source| - # Using an association list instead of a hash to preserve order, - # for aesthetic reasons more than anything else. - label = source.label.to_s.capitalize - pair = mem.assoc(label) - mem << (pair = [label, []]) if pair.nil? - pair[1] |= source.names - mem - end.each do |label, names| - usage << " #{label}: #{names.join(', ')}\n" unless names.empty? - end - - usage << <<end_blurb - -You can also install additional generators for your own use: - 1. Download, for example, login_generator.zip - 2. Unzip to directory #{Dir.user_home}/.rails/generators/login - to use the generator with all your Rails apps -end_blurb - - if Object.const_defined?(:RAILS_ROOT) - usage << <<end_blurb - or to #{File.expand_path(RAILS_ROOT)}/lib/generators/login - to use with this app only. -end_blurb - end - - usage << <<end_blurb - 3. Run generate with no arguments for usage information - #{$0} login - -Generator gems are also available: - 1. gem search -r generator - 2. gem install login_generator - 3. #{$0} login - -end_blurb - return usage - end - end # Base - - end - end -end diff --git a/railties/lib/rails_generator/scripts/destroy.rb b/railties/lib/rails_generator/scripts/destroy.rb deleted file mode 100644 index a7c2a14751..0000000000 --- a/railties/lib/rails_generator/scripts/destroy.rb +++ /dev/null @@ -1,29 +0,0 @@ -require File.dirname(__FILE__) + '/../scripts' - -module Rails::Generator::Scripts - class Destroy < Base - mandatory_options :command => :destroy - - protected - def usage_message - usage = "\nInstalled Generators\n" - Rails::Generator::Base.sources.each do |source| - label = source.label.to_s.capitalize - names = source.names - usage << " #{label}: #{names.join(', ')}\n" unless names.empty? - end - - usage << <<end_blurb - -script/generate command. For instance, 'script/destroy migration CreatePost' -will delete the appropriate XXX_create_post.rb migration file in db/migrate, -while 'script/destroy scaffold Post' will delete the posts controller and -views, post model and migration, all associated tests, and the map.resources -:posts line in config/routes.rb. - -For instructions on finding new generators, run script/generate. -end_blurb - return usage - end - end -end diff --git a/railties/lib/rails_generator/scripts/generate.rb b/railties/lib/rails_generator/scripts/generate.rb deleted file mode 100644 index 1fe2f54ab3..0000000000 --- a/railties/lib/rails_generator/scripts/generate.rb +++ /dev/null @@ -1,7 +0,0 @@ -require File.dirname(__FILE__) + '/../scripts' - -module Rails::Generator::Scripts - class Generate < Base - mandatory_options :command => :create - end -end diff --git a/railties/lib/rails_generator/scripts/update.rb b/railties/lib/rails_generator/scripts/update.rb deleted file mode 100644 index 53a9faa366..0000000000 --- a/railties/lib/rails_generator/scripts/update.rb +++ /dev/null @@ -1,12 +0,0 @@ -require File.dirname(__FILE__) + '/../scripts' - -module Rails::Generator::Scripts - class Update < Base - mandatory_options :command => :update - - protected - def banner - "Usage: #{$0} [options] scaffold" - end - end -end diff --git a/railties/lib/rails_generator/secret_key_generator.rb b/railties/lib/rails_generator/secret_key_generator.rb deleted file mode 100644 index 7dd495a2f5..0000000000 --- a/railties/lib/rails_generator/secret_key_generator.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'active_support/deprecation' - -module Rails - # A class for creating random secret keys. This class will do its best to create a - # random secret key that's as secure as possible, using whatever methods are - # available on the current platform. For example: - # - # generator = Rails::SecretKeyGenerator("some unique identifier, such as the application name") - # generator.generate_secret # => "f3f1be90053fa851... (some long string)" - # - # This class is *deprecated* in Rails 2.2 in favor of ActiveSupport::SecureRandom. - # It is currently a wrapper around ActiveSupport::SecureRandom. - class SecretKeyGenerator - def initialize(identifier) - end - - # Generate a random secret key with the best possible method available on - # the current platform. - def generate_secret - ActiveSupport::SecureRandom.hex(64) - end - deprecate :generate_secret=>"You should use ActiveSupport::SecureRandom.hex(64)" - end -end diff --git a/railties/lib/rails_generator/simple_logger.rb b/railties/lib/rails_generator/simple_logger.rb deleted file mode 100644 index d750f07b84..0000000000 --- a/railties/lib/rails_generator/simple_logger.rb +++ /dev/null @@ -1,46 +0,0 @@ -module Rails - module Generator - class SimpleLogger # :nodoc: - attr_reader :out - attr_accessor :quiet - - def initialize(out = $stdout) - @out = out - @quiet = false - @level = 0 - end - - def log(status, message, &block) - @out.print("%12s %s%s\n" % [status, ' ' * @level, message]) unless quiet - indent(&block) if block_given? - end - - def indent(&block) - @level += 1 - if block_given? - begin - block.call - ensure - outdent - end - end - end - - def outdent - @level -= 1 - if block_given? - begin - block.call - ensure - indent - end - end - end - - private - def method_missing(method, *args, &block) - log(method.to_s, args.first, &block) - end - end - end -end diff --git a/railties/lib/rails_generator/spec.rb b/railties/lib/rails_generator/spec.rb deleted file mode 100644 index 9d780b7ac5..0000000000 --- a/railties/lib/rails_generator/spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Rails - module Generator - # A spec knows where a generator was found and how to instantiate it. - # Metadata include the generator's name, its base path, and the source - # which yielded it (PathSource, GemPathSource, etc.) - class Spec - attr_reader :name, :path, :source - - def initialize(name, path, source) - @name, @path, @source = name, path, source - end - - # Look up the generator class. Require its class file, find the class - # in ObjectSpace, tag it with this spec, and return. - def klass - unless @klass - require class_file - @klass = lookup_class - @klass.spec = self - end - @klass - end - - def class_file - "#{path}/#{name}_generator.rb" - end - - def class_name - "#{name.camelize}Generator" - end - - private - # Search for the first Class descending from Rails::Generator::Base - # whose name matches the requested class name. - def lookup_class - ObjectSpace.each_object(Class) do |obj| - return obj if obj.ancestors.include?(Rails::Generator::Base) and - obj.name.split('::').last == class_name - end - raise NameError, "Missing #{class_name} class in #{class_file}" - end - end - end -end |