From b4ef958de6b16294094de28d00ba25fe2f48accc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 15 Jul 2009 20:16:37 +0200 Subject: Change false to :verbose => false as in new Thor version. --- railties/lib/generators/actions.rb | 37 ++++++------ railties/lib/generators/migration.rb | 4 +- railties/lib/generators/rails/app/app_generator.rb | 12 ++-- .../generators/rails/plugin/plugin_generator.rb | 4 +- .../lib/vendor/thor-0.11.1/lib/thor/actions.rb | 70 ++++++++++------------ .../thor-0.11.1/lib/thor/actions/copy_file.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/create_file.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/directory.rb | 31 +++++----- .../lib/thor/actions/empty_directory.rb | 10 ++-- .../lib/vendor/thor-0.11.1/lib/thor/actions/get.rb | 10 ++-- .../lib/thor/actions/inject_into_file.rb | 24 ++++---- .../thor-0.11.1/lib/thor/actions/template.rb | 10 ++-- .../thor-0.11.1/lib/thor/actions/templater.rb | 13 ++-- railties/test/generators/actions_test.rb | 29 ++++++--- railties/test/generators/app_generator_test.rb | 3 +- railties/test/generators/generators_test_helper.rb | 1 + .../test/generators/scaffold_generator_test.rb | 6 -- 17 files changed, 140 insertions(+), 144 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/actions.rb b/railties/lib/generators/actions.rb index 34c78aaad8..81db0b7c37 100644 --- a/railties/lib/generators/actions.rb +++ b/railties/lib/generators/actions.rb @@ -16,12 +16,13 @@ module Rails # # apply "recipes/jquery.rb" # - def apply(path, log_status=true) + def apply(path) path = find_in_source_paths(path) unless path =~ /^http\:\/\// - log :apply, path, log_status + log :apply, path + shell.padding += 1 instance_eval(open(path).read) - log :applied, path, log_status + shell.padding -= 1 end # Install a plugin. You must provide either a Subversion url or Git url. @@ -38,11 +39,11 @@ module Rails if options[:git] && options[:submodule] in_root do - run "git submodule add #{options[:git]} vendor/plugins/#{name}", false + run "git submodule add #{options[:git]} vendor/plugins/#{name}", :verbose => false end elsif options[:git] || options[:svn] in_root do - run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", false + run_ruby_script "script/plugin install #{options[:svn] || options[:git]}", :verbose => false end else log "! no git or svn provided for #{name}. Skipping..." @@ -57,7 +58,7 @@ module Rails # gem "rspec", :env => :test # gem "technoweenie-restful-authentication", :lib => "restful-authentication", :source => "http://gems.github.com/" # - def gem(name, options = {}) + def gem(name, options={}) log :gem, name env = options.delete(:env) @@ -82,10 +83,10 @@ module Rails in_root do if options[:env].nil? - inject_into_file 'config/environment.rb', "\n #{data}", { :after => sentinel }, false + inject_into_file 'config/environment.rb', "\n #{data}", :after => sentinel, :verbose => false else Array.wrap(options[:env]).each do|env| - append_file "config/environments/#{env}.rb", "\n#{data}", false + append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false end end end @@ -99,7 +100,7 @@ module Rails # git :add => "this.file that.rb" # git :add => "onefile.rb", :rm => "badfile.cxx" # - def git(command = {}) + def git(command={}) in_root do if command.is_a?(Symbol) run "git #{command}" @@ -125,7 +126,7 @@ module Rails # def vendor(filename, data=nil, &block) log :vendor, filename - create_file("vendor/#{filename}", data, false, &block) + create_file("vendor/#{filename}", data, :verbose => false, &block) end # Create a new file in the lib/ directory. Code can be specified @@ -141,7 +142,7 @@ module Rails # def lib(filename, data=nil, &block) log :lib, filename - create_file("lib/#{filename}", data, false, &block) + create_file("lib/#{filename}", data, :verbose => false, &block) end # Create a new Rakefile with the provided code (either in a block or a string). @@ -164,7 +165,7 @@ module Rails # def rakefile(filename, data=nil, &block) log :rakefile, filename - create_file("lib/tasks/#{filename}", data, false, &block) + create_file("lib/tasks/#{filename}", data, :verbose => false, &block) end # Create a new initializer with the provided code (either in a block or a string). @@ -185,7 +186,7 @@ module Rails # def initializer(filename, data=nil, &block) log :initializer, filename - create_file("config/initializers/#{filename}", data, false, &block) + create_file("config/initializers/#{filename}", data, :verbose => false, &block) end # Generate something using a generator from Rails or a plugin. @@ -200,7 +201,7 @@ module Rails log :generate, what argument = args.map {|arg| arg.to_s }.flatten.join(" ") - in_root { run_ruby_script("script/generate #{what} #{argument}", false) } + in_root { run_ruby_script("script/generate #{what} #{argument}", :verbose => false) } end # Runs the supplied rake task @@ -215,7 +216,7 @@ module Rails log :rake, command env = options[:env] || 'development' sudo = options[:sudo] && RUBY_PLATFORM !~ /mswin|mingw/ ? 'sudo ' : '' - in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", false) } + in_root { run("#{sudo}#{extify(:rake)} #{command} RAILS_ENV=#{env}", :verbose => false) } end # Just run the capify command in root @@ -226,7 +227,7 @@ module Rails # def capify! log :capify, "" - in_root { run("#{extify(:capify)} .", false) } + in_root { run("#{extify(:capify)} .", :verbose => false) } end # Add Rails to /vendor/rails @@ -237,7 +238,7 @@ module Rails # def freeze!(args = {}) log :vendor, "rails" - in_root { run("#{extify(:rake)} rails:freeze:edge", false) } + in_root { run("#{extify(:rake)} rails:freeze:edge", :verbose => false) } end # Make an entry in Rails routing file conifg/routes.rb @@ -251,7 +252,7 @@ module Rails sentinel = "ActionController::Routing::Routes.draw do |map|" in_root do - inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel }, false + inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false } end end diff --git a/railties/lib/generators/migration.rb b/railties/lib/generators/migration.rb index 7014e6deda..0a9151ecdf 100644 --- a/railties/lib/generators/migration.rb +++ b/railties/lib/generators/migration.rb @@ -22,7 +22,7 @@ module Rails # # migration_template "migration.rb", "db/migrate/add_foo_to_bar.rb" # - def migration_template(source, destination=nil, log_status=true) + def migration_template(source, destination=nil, config={}) destination = File.expand_path(destination || source, self.destination_root) migration_dir = File.dirname(destination) @@ -37,7 +37,7 @@ module Rails destination = File.join(migration_dir, "#{@migration_number}_#{@migration_file_name}.rb") end - template(source, destination, log_status) + template(source, destination, config) end protected diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb index 88a52c60b0..eaeb49903a 100644 --- a/railties/lib/generators/rails/app/app_generator.rb +++ b/railties/lib/generators/rails/app/app_generator.rb @@ -100,13 +100,13 @@ module Rails::Generators inside "log" do %w( server production development test ).each do |file| create_file "#{file}.log" - chmod "#{file}.log", 0666, false + chmod "#{file}.log", 0666, :verbose => false end end end def create_public_files - directory "public", "public", false # Non-recursive. Do small steps, so anyone can overwrite it. + directory "public", "public", :recursive => false # Do small steps, so anyone can overwrite it. end def create_dispatch_files @@ -114,13 +114,13 @@ module Rails::Generators copy_file "dispatchers/config.ru", "config.ru" template "dispatchers/dispatch.rb", "public/dispatch.rb" - chmod "public/dispatch.rb", 0755, false + chmod "public/dispatch.rb", 0755, :verbose => false template "dispatchers/dispatch.rb", "public/dispatch.cgi" - chmod "public/dispatch.cgi", 0755, false + chmod "public/dispatch.cgi", 0755, :verbose => false template "dispatchers/dispatch.fcgi", "public/dispatch.fcgi" - chmod "public/dispatch.fcgi", 0755, false + chmod "public/dispatch.fcgi", 0755, :verbose => false end def create_public_image_files @@ -138,7 +138,7 @@ module Rails::Generators def create_script_files directory "script" - chmod "script", 0755, false + chmod "script", 0755, :verbose => false end def create_test_files diff --git a/railties/lib/generators/rails/plugin/plugin_generator.rb b/railties/lib/generators/rails/plugin/plugin_generator.rb index a7417f28c2..dcdc125867 100644 --- a/railties/lib/generators/rails/plugin/plugin_generator.rb +++ b/railties/lib/generators/rails/plugin/plugin_generator.rb @@ -8,11 +8,11 @@ module Rails check_class_collision def create_root_files - directory '.', plugin_dir, false # non-recursive + directory '.', plugin_dir, :recursive => false end def create_lib_files - directory 'lib', plugin_dir('lib'), false # non-recursive + directory 'lib', plugin_dir('lib'), :recursive => false end def create_tasks_files diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb index 83d082382c..939339088a 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions.rb @@ -164,8 +164,8 @@ class Thor # Same as inside, but log status and use padding. # - def inside_with_padding(dir='', log_status=true, &block) - say_status :inside, dir, log_status + def inside_with_padding(dir='', config={}, &block) + say_status :inside, dir, config.fetch(:verbose, true) shell.padding += 1 inside(dir, &block) shell.padding -= 1 @@ -182,17 +182,16 @@ class Thor # ==== Parameters # mode:: the file mode # path:: the name of the file to change mode - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # chmod "script/*", 0755 # - def chmod(path, mode, log_status=true) + def chmod(path, mode, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :chmod, relative_to_original_destination_root(path), log_status + say_status :chmod, relative_to_original_destination_root(path), config.fetch(:verbose, true) FileUtils.chmod_R(mode, path) unless options[:pretend] end @@ -200,8 +199,7 @@ class Thor # # ==== Parameters # command:: the command to be executed. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # @@ -209,9 +207,10 @@ class Thor # run('ln -s ~/edge rails') # end # - def run(command, log_status=true) + def run(command, config={}) return unless behavior == :invoke - say_status :run, "\"#{command}\" from #{relative_to_original_destination_root(destination_root, false)}", log_status + description = "#{command.inspect} from #{relative_to_original_destination_root(destination_root, false)}" + say_status :run, description, config.fetch(:verbose, true) `#{command}` unless options[:pretend] end @@ -219,12 +218,11 @@ class Thor # # ==== Parameters # command:: the command to be executed. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # - def run_ruby_script(command, log_status=true) + def run_ruby_script(command, config={}) return unless behavior == :invoke - say_status File.basename(Thor::Util.ruby_command), command, log_status + say_status File.basename(Thor::Util.ruby_command), command, config.fetch(:verbose, true) `#{Thor::Util.ruby_command} #{command}` unless options[:pretend] end @@ -234,9 +232,8 @@ class Thor # ==== Parameters # task:: the task to be invoked # args:: arguments to the task - # options:: a hash with options used on invocation - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # options:: give :verbose => false to not log the status. Other options + # are given as parameter to Thor. # # ==== Examples # @@ -247,35 +244,33 @@ class Thor # #=> thor list --all --substring=rails # def thor(task, *args) - log_status = args.last.is_a?(Symbol) || [true, false].include?(args.last) ? args.pop : true - options = args.last.is_a?(Hash) ? args.pop : {} + config = args.last.is_a?(Hash) ? args.pop : {} + verbose = config.key?(:verbose) ? config.delete(:verbose) : true args.unshift task - args.push Thor::Options.to_switches(options) + args.push Thor::Options.to_switches(config) command = args.join(' ').strip - say_status :thor, command, log_status - run "thor #{command}", false + say_status :thor, command, verbose + run "thor #{command}", :verbose => false end # Removes a file at the given location. # # ==== Parameters # path:: path of the file to be changed - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # remove_file 'README' # remove_file 'app/controllers/application_controller.rb' # - def remove_file(path, log_status=true) + def remove_file(path, config={}) return unless behavior == :invoke path = File.expand_path(path, destination_root) - color = log_status.is_a?(Symbol) ? log_status : :red - say_status :remove, relative_to_original_destination_root(path), log_status + say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true) ::FileUtils.rm_rf(path) if !options[:pretend] && File.exists?(path) end @@ -285,8 +280,7 @@ class Thor # path:: path of the file to be changed # flag:: the regexp or string to be replaced # replacement:: the replacement, can be also given as a block - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # @@ -298,10 +292,10 @@ class Thor # def gsub_file(path, flag, *args, &block) return unless behavior == :invoke - log_status = args.last.is_a?(Symbol) || [ true, false ].include?(args.last) ? args.pop : true + config = args.last.is_a?(Hash) ? args.pop : {} path = File.expand_path(path, destination_root) - say_status :gsub, relative_to_original_destination_root(path), log_status + say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = File.read(path) @@ -315,17 +309,16 @@ class Thor # ==== Parameters # path:: path of the file to be changed # data:: the data to append to the file, can be also given as a block. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # append_file 'config/environments/test.rb', 'config.gem "rspec"' # - def append_file(path, data=nil, log_status=true, &block) + def append_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :append, relative_to_original_destination_root(path), log_status + say_status :append, relative_to_original_destination_root(path), config.fetch(:verbose, true) File.open(path, 'ab') { |file| file.write(data || block.call) } unless options[:pretend] end @@ -334,17 +327,16 @@ class Thor # ==== Parameters # path:: path of the file to be changed # data:: the data to prepend to the file, can be also given as a block. - # log_status:: if false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status. # # ==== Example # # prepend_file 'config/environments/test.rb', 'config.gem "rspec"' # - def prepend_file(path, data=nil, log_status=true, &block) + def prepend_file(path, data=nil, config={}, &block) return unless behavior == :invoke path = File.expand_path(path, destination_root) - say_status :prepend, relative_to_original_destination_root(path), log_status + say_status :prepend, relative_to_original_destination_root(path), config.fetch(:verbose, true) unless options[:pretend] content = data || block.call diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb index b9d2e9e0a7..bfbc38a367 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/copy_file.rb @@ -7,9 +7,9 @@ class Thor # the destination is not given it's assumed to be equal to the source. # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -17,8 +17,8 @@ class Thor # # copy_file "doc/README" # - def copy_file(source, destination=nil, log_status=true) - action CopyFile.new(self, source, destination || source, log_status) + def copy_file(source, destination=nil, config={}) + action CopyFile.new(self, source, destination || source, config) end class CopyFile < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb index 2f3732247e..72bf34c0a3 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/create_file.rb @@ -9,7 +9,7 @@ class Thor # ==== Parameters # destination:: the relative path to the destination root. # data:: the data to append to the file. - # log_status:: if false, does not log the status. True by default. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -20,8 +20,8 @@ class Thor # # create_file "config/apach.conf", "your apache config" # - def create_file(destination, data=nil, log_status=true, &block) - action CreateFile.new(self, destination, block || data.to_s, log_status) + def create_file(destination, data=nil, config={}, &block) + action CreateFile.new(self, destination, block || data.to_s, config) end alias :add_file :create_file @@ -31,8 +31,8 @@ class Thor class CreateFile < Templater #:nodoc: attr_reader :data - def initialize(base, destination, data, log_status) - super(base, nil, destination, log_status) + def initialize(base, destination, data, config={}) + super(base, nil, destination, config) @data = data end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb index 134f13d1b7..2c6d2bc59b 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/directory.rb @@ -30,30 +30,27 @@ class Thor # blog.rb # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # recursive:: if the directory must be copied recursively, true by default - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. + # If :recursive => false, does not look for paths recursively. # # ==== Examples # # directory "doc" - # directory "doc", "docs", false + # directory "doc", "docs", :recursive => false # - def directory(source, destination=nil, recursive=true, log_status=true) - action Directory.new(self, source, destination || source, recursive, log_status) + def directory(source, destination=nil, config={}) + action Directory.new(self, source, destination || source, config) end class Directory < Templater #:nodoc: - attr_reader :recursive - - def initialize(base, source, destination=nil, recursive=true, log_status=true) - @recursive = recursive - super(base, source, destination, log_status) + def initialize(base, source, destination=nil, config={}) + super(base, source, destination, { :recursive => true }.merge(config)) end def invoke! - base.empty_directory given_destination, @log_status + base.empty_directory given_destination, config execute! end @@ -64,7 +61,7 @@ class Thor protected def execute! - lookup = recursive ? File.join(source, '**') : source + lookup = config[:recursive] ? File.join(source, '**') : source lookup = File.join(lookup, '{*,.[a-z]*}') Dir[lookup].each do |file_source| @@ -73,11 +70,11 @@ class Thor case file_source when /\.empty_directory$/ - base.empty_directory(File.dirname(file_destination), @log_status) + base.empty_directory(File.dirname(file_destination), config) when /\.tt$/ - base.template(file_source, file_destination[0..-4], @log_status) + base.template(file_source, file_destination[0..-4], config) else - base.copy_file(file_source, file_destination, @log_status) + base.copy_file(file_source, file_destination, config) end end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb index 3f29d52362..04f9817212 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/empty_directory.rb @@ -6,21 +6,21 @@ class Thor # Creates an empty directory. # # ==== Parameters - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # # empty_directory "doc" # - def empty_directory(destination, log_status=true) - action EmptyDirectory.new(self, nil, destination, log_status) + def empty_directory(destination, config={}) + action EmptyDirectory.new(self, nil, destination, config) end class EmptyDirectory < Templater #:nodoc: def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(destination) end end diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb index a0d12b8370..bd8deb8194 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/get.rb @@ -9,9 +9,9 @@ class Thor # the url is yielded and used as location. # # ==== Parameters - # source:: the address of the given content - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the address of the given content. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -21,8 +21,8 @@ class Thor # content.split("\n").first # end # - def get(source, destination=nil, log_status=true, &block) - action Get.new(self, source, block || destination, log_status) + def get(source, destination=nil, config={}, &block) + action Get.new(self, source, block || destination, config) end class Get < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb index c91bd96098..6bd0100a12 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/inject_into_file.rb @@ -9,9 +9,8 @@ class Thor # ==== Parameters # destination:: Relative path to the destination root # data:: Data to add to the file. Can be given as a block. - # flag:: Flag of where to add the changes. - # log_status:: If false, does not log the status. True by default. - # If a symbol is given, uses it as the output color. + # config:: give :verbose => false to not log the status and the flag + # for injection (:after or :before). # # ==== Examples # @@ -24,28 +23,29 @@ class Thor # def inject_into_file(destination, *args, &block) if block_given? - data, flag = block, args.shift + data, config = block, args.shift else - data, flag = args.shift, args.shift + data, config = args.shift, args.shift end log_status = args.empty? || args.pop - action InjectIntoFile.new(self, destination, data, flag, log_status) + action InjectIntoFile.new(self, destination, data, config) end class InjectIntoFile #:nodoc: - attr_reader :base, :destination, :relative_destination, :flag, :replacement + attr_reader :base, :destination, :relative_destination, :flag, :replacement, :config - def initialize(base, destination, data, flag, log_status=true) - @base, @log_status = base, log_status - behavior, @flag = flag.keys.first, flag.values.first + def initialize(base, destination, data, config) + @base, @config = base, { :verbose => true }.merge(config) self.destination = destination data = data.call if data.is_a?(Proc) - @replacement = if behavior == :after + @replacement = if @config.key?(:after) + @flag = @config.delete(:after) @flag + data else + @flag = @config.delete(:before) data + @flag end end @@ -75,7 +75,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status) - base.shell.say_status status, relative_destination, @log_status + base.shell.say_status status, relative_destination, config[:verbose] end # Adds the content to the file. diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb index 6b2e50b8c5..95e2412514 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/template.rb @@ -9,9 +9,9 @@ class Thor # to be equal to the source removing .tt from the filename. # # ==== Parameters - # source:: the relative path to the source root - # destination:: the relative path to the destination root - # log_status:: if false, does not log the status. True by default. + # source:: the relative path to the source root. + # destination:: the relative path to the destination root. + # config:: give :verbose => false to not log the status. # # ==== Examples # @@ -19,9 +19,9 @@ class Thor # # template "doc/README" # - def template(source, destination=nil, log_status=true) + def template(source, destination=nil, config={}) destination ||= source.gsub(/.tt$/, '') - action Template.new(self, source, destination, log_status) + action Template.new(self, source, destination, config) end class Template < Templater #:nodoc: diff --git a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb index b4b7bae3af..455178c6e8 100644 --- a/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb +++ b/railties/lib/vendor/thor-0.11.1/lib/thor/actions/templater.rb @@ -8,7 +8,7 @@ class Thor # by Jonas Nicklas and Michael S. Klishin under MIT LICENSE. # class Templater #:nodoc: - attr_reader :base, :source, :destination, :given_destination, :relative_destination + attr_reader :base, :source, :destination, :given_destination, :relative_destination, :config # Initializes given the source and destination. # @@ -16,11 +16,10 @@ class Thor # base:: A Thor::Base instance # source:: Relative path to the source of this file # destination:: Relative path to the destination of this file - # log_status:: If false, does not log the status. True by default. - # Templater log status does not accept color. + # config:: give :verbose => false to not log the status. # - def initialize(base, source, destination, log_status=true) - @base, @log_status = base, log_status + def initialize(base, source, destination, config={}) + @base, @config = base, { :verbose => true }.merge(config) self.source = source self.destination = destination end @@ -56,7 +55,7 @@ class Thor # but you can modify in the subclass. # def invoke! - invoke_with_options!(base.options) do + invoke_with_options!(base.options.merge(config)) do ::FileUtils.mkdir_p(::File.dirname(destination)) ::File.open(destination, 'w'){ |f| f.write render } end @@ -187,7 +186,7 @@ class Thor # Shortcut to say_status shell method. # def say_status(status, color) - base.shell.say_status status, relative_destination, color if @log_status + base.shell.say_status status, relative_destination, color if config[:verbose] end end diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index e8b10522b9..9a8d8075a1 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -20,6 +20,17 @@ class ActionsTest < GeneratorsTestCase assert_equal generator.instance_variable_get("@foo"), "FOO" end + def test_apply_uses_padding_in_the_applied_template + template = <<-TEMPLATE + say_status :cool, :padding + TEMPLATE + template.instance_eval "def read; self; end" + + generator.expects(:open).with("http://gist.github.com/103208.txt").returns(template) + content = action(:apply, "http://gist.github.com/103208.txt") + assert_match /cool padding/, content + end + def test_create_file_should_write_data_to_file_path action :create_file, 'lib/test_file.rb', 'heres test data' assert_file 'lib/test_file.rb', 'heres test data' @@ -31,17 +42,17 @@ class ActionsTest < GeneratorsTestCase end def test_plugin_with_git_option_should_run_plugin_install - generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@git_plugin_uri}", :verbose => false) action :plugin, 'restful-authentication', :git => @git_plugin_uri end def test_plugin_with_svn_option_should_run_plugin_install - generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", false) + generator.expects(:run_ruby_script).once.with("script/plugin install #{@svn_plugin_uri}", :verbose => false) action :plugin, 'restful-authentication', :svn => @svn_plugin_uri end def test_plugin_with_git_option_and_submodule_should_use_git_scm - generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", false) + generator.expects(:run).with("git submodule add #{@git_plugin_uri} vendor/plugins/rest_auth", :verbose => false) action :plugin, 'rest_auth', :git => @git_plugin_uri, :submodule => true end @@ -135,32 +146,32 @@ class ActionsTest < GeneratorsTestCase end def test_generate_should_run_script_generate_with_argument_and_options - generator.expects(:run_ruby_script).once.with('script/generate model MyModel', false) + generator.expects(:run_ruby_script).once.with('script/generate model MyModel', :verbose => false) action :generate, 'model', 'MyModel' end def test_rake_should_run_rake_command_with_development_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', false) + generator.expects(:run).once.with('rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear' end def test_rake_with_env_option_should_run_rake_command_in_env - generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', false) + generator.expects(:run).once.with('rake log:clear RAILS_ENV=production', :verbose => false) action :rake, 'log:clear', :env => 'production' end def test_rake_with_sudo_option_should_run_rake_command_with_sudo - generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', false) + generator.expects(:run).once.with('sudo rake log:clear RAILS_ENV=development', :verbose => false) action :rake, 'log:clear', :sudo => true end def test_capify_should_run_the_capify_command - generator.expects(:run).once.with('capify .', false) + generator.expects(:run).once.with('capify .', :verbose => false) action :capify! end def test_freeze_should_freeze_rails_edge - generator.expects(:run).once.with('rake rails:freeze:edge', false) + generator.expects(:run).once.with('rake rails:freeze:edge', :verbose => false) action :freeze! end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index c78b7d2f25..c794a2ade6 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -125,7 +125,8 @@ class AppGeneratorTest < GeneratorsTestCase end def test_rails_is_frozen - generator(:freeze => true, :database => "sqlite3").expects(:run).with("rake rails:freeze:edge", false) + generator(:freeze => true, :database => "sqlite3").expects(:run). + with("rake rails:freeze:edge", :verbose => false) silence(:stdout){ generator.invoke } assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/ end diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index c9b9c33a4e..011bd518f8 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -13,6 +13,7 @@ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" require 'generators' CURRENT_PATH = File.expand_path(Dir.pwd) +Rails::Generators.no_color! class GeneratorsTestCase < Test::Unit::TestCase include FileUtils diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 9560cf7ba7..05eadd3460 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -117,12 +117,6 @@ class ScaffoldGeneratorTest < GeneratorsTestCase assert_file "public/stylesheets/scaffold.css" end - def test_invoke_output - output = run_generator - assert_match /invoke.{4} active_record/, output - assert_match /create.{4} app\/models\/product_line\.rb/, output - end - protected def run_generator(config={}) -- cgit v1.2.3