mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Modified rake tasks to use new app generator structure and updated Thor version.
This commit is contained in:
parent
b03034a686
commit
d6a590a710
40 changed files with 92 additions and 87 deletions
|
@ -16,13 +16,14 @@ module Rails
|
|||
#
|
||||
# apply "recipes/jquery.rb"
|
||||
#
|
||||
def apply(path)
|
||||
def apply(path, options={})
|
||||
verbose = options.fetch(:verbose, true)
|
||||
path = find_in_source_paths(path) unless path =~ /^http\:\/\//
|
||||
|
||||
log :apply, path
|
||||
shell.padding += 1
|
||||
log :apply, path, verbose
|
||||
shell.padding += 1 if verbose
|
||||
instance_eval(open(path).read)
|
||||
shell.padding -= 1
|
||||
shell.padding -= 1 if verbose
|
||||
end
|
||||
|
||||
# Install a plugin. You must provide either a Subversion url or Git url.
|
||||
|
|
|
@ -66,7 +66,6 @@ module Rails::Generators
|
|||
empty_directory "config"
|
||||
|
||||
inside "config" do
|
||||
copy_file "boot.rb"
|
||||
copy_file "routes.rb"
|
||||
template "environment.rb"
|
||||
|
||||
|
@ -76,6 +75,10 @@ module Rails::Generators
|
|||
end
|
||||
end
|
||||
|
||||
def create_boot_file
|
||||
copy_file "config/boot.rb"
|
||||
end
|
||||
|
||||
def create_activerecord_files
|
||||
return if options[:skip_activerecord]
|
||||
template "config/databases/#{options[:database]}.yml", "config/database.yml"
|
||||
|
|
|
@ -3,7 +3,7 @@ module Rails
|
|||
class MetalGenerator < NamedBase
|
||||
check_class_collision
|
||||
|
||||
def create_file
|
||||
def create_metal_file
|
||||
template "metal.rb", "app/metal/#{file_name}.rb"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,13 +21,13 @@ module Rails
|
|||
end
|
||||
|
||||
hook_for :generator do |instance, generator|
|
||||
instance.inside_with_padding instance.send(:plugin_dir) do
|
||||
instance.inside instance.send(:plugin_dir), :verbose => true do
|
||||
instance.invoke generator, [ instance.name ], :namespace => false
|
||||
end
|
||||
end
|
||||
|
||||
hook_for :test_framework do |instance, test_framework|
|
||||
instance.inside_with_padding instance.send(:plugin_dir) do
|
||||
instance.inside instance.send(:plugin_dir), :verbose => true do
|
||||
instance.invoke test_framework
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,49 +78,46 @@ namespace :rails do
|
|||
end
|
||||
|
||||
desc "Update both configs, scripts and public/javascripts from Rails"
|
||||
task :update => [ "update:scripts", "update:javascripts", "update:configs", "update:application_controller" ]
|
||||
task :update => [ "update:configs", "update:javascripts", "update:scripts", "update:application_controller" ]
|
||||
|
||||
desc "Applies the template supplied by LOCATION=/path/to/template"
|
||||
task :template do
|
||||
require 'rails_generator/generators/applications/app/template_runner'
|
||||
template = ENV["LOCATION"]
|
||||
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
|
||||
Rails::TemplateRunner.new(template)
|
||||
|
||||
require 'generators'
|
||||
generator = Rails::Generators::Base.new [], {}, :destination_root => RAILS_ROOT
|
||||
generator.apply template, :verbose => false
|
||||
end
|
||||
|
||||
namespace :update do
|
||||
desc "Add new scripts to the application script/ directory"
|
||||
task :scripts do
|
||||
local_base = "script"
|
||||
edge_base = "#{File.dirname(__FILE__)}/../../bin"
|
||||
def invoke_from_app_generator(method)
|
||||
require 'generators'
|
||||
require 'generators/rails/app/app_generator'
|
||||
|
||||
local = Dir["#{local_base}/**/*"].reject { |path| File.directory?(path) }
|
||||
edge = Dir["#{edge_base}/**/*"].reject { |path| File.directory?(path) }
|
||||
|
||||
edge.each do |script|
|
||||
base_name = script[(edge_base.length+1)..-1]
|
||||
next if base_name == "rails"
|
||||
next if local.detect { |path| base_name == path[(local_base.length+1)..-1] }
|
||||
if !File.directory?("#{local_base}/#{File.dirname(base_name)}")
|
||||
mkdir_p "#{local_base}/#{File.dirname(base_name)}"
|
||||
end
|
||||
install script, "#{local_base}/#{base_name}", :mode => 0755
|
||||
end
|
||||
end
|
||||
|
||||
desc "Update your javascripts from your current rails install"
|
||||
task :javascripts do
|
||||
require 'railties_path'
|
||||
project_dir = RAILS_ROOT + '/public/javascripts/'
|
||||
scripts = Dir[RAILTIES_PATH + '/html/javascripts/*.js']
|
||||
scripts.reject!{|s| File.basename(s) == 'application.js'} if File.exist?(project_dir + 'application.js')
|
||||
FileUtils.cp(scripts, project_dir)
|
||||
generator = Rails::Generators::AppGenerator.new ["rails"], { :with_dispatchers => true },
|
||||
:destination_root => RAILS_ROOT
|
||||
generator.invoke(method)
|
||||
end
|
||||
|
||||
desc "Update config/boot.rb from your current rails install"
|
||||
task :configs do
|
||||
require 'railties_path'
|
||||
FileUtils.cp(RAILTIES_PATH + '/environments/boot.rb', RAILS_ROOT + '/config/boot.rb')
|
||||
invoke_from_app_generator :create_boot_file
|
||||
end
|
||||
|
||||
desc "Update Prototype javascripts from your current rails install"
|
||||
task :javascripts do
|
||||
invoke_from_app_generator :create_prototype_files
|
||||
end
|
||||
|
||||
desc "Generate dispatcher files in RAILS_ROOT/public"
|
||||
task :generate_dispatchers do
|
||||
invoke_from_app_generator :create_dispatch_files
|
||||
end
|
||||
|
||||
desc "Add new scripts to the application script/ directory"
|
||||
task :scripts do
|
||||
invoke_from_app_generator :create_script_files
|
||||
end
|
||||
|
||||
desc "Rename application.rb to application_controller.rb"
|
||||
|
@ -132,14 +129,5 @@ namespace :rails do
|
|||
puts "#{old_style} has been renamed to #{new_style}, update your SCM as necessary"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Generate dispatcher files in RAILS_ROOT/public"
|
||||
task :generate_dispatchers do
|
||||
require 'railties_path'
|
||||
FileUtils.cp(RAILTIES_PATH + '/dispatches/config.ru', RAILS_ROOT + '/config.ru')
|
||||
FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.fcgi', RAILS_ROOT + '/public/dispatch.fcgi')
|
||||
FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.rb')
|
||||
FileUtils.cp(RAILTIES_PATH + '/dispatches/dispatch.rb', RAILS_ROOT + '/public/dispatch.cgi')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -136,21 +136,20 @@ class Thor
|
|||
#
|
||||
# ==== Parameters
|
||||
# dir<String>:: the directory to move to.
|
||||
# config<Hash>:: give :verbose => true to log and use padding.
|
||||
#
|
||||
def inside(dir='', &block)
|
||||
def inside(dir='', config={}, &block)
|
||||
verbose = config.fetch(:verbose, false)
|
||||
|
||||
say_status :inside, dir, verbose
|
||||
shell.padding += 1 if verbose
|
||||
@destination_stack.push File.expand_path(dir, destination_root)
|
||||
|
||||
FileUtils.mkdir_p(destination_root) unless File.exist?(destination_root)
|
||||
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
||||
@destination_stack.pop
|
||||
end
|
||||
|
||||
# Same as inside, but log status and use padding.
|
||||
#
|
||||
def inside_with_padding(dir='', config={}, &block)
|
||||
say_status :inside, dir, config.fetch(:verbose, true)
|
||||
shell.padding += 1
|
||||
inside(dir, &block)
|
||||
shell.padding -= 1
|
||||
@destination_stack.pop
|
||||
shell.padding -= 1 if verbose
|
||||
end
|
||||
|
||||
# Goes to the root and execute the given block.
|
||||
|
@ -173,8 +172,7 @@ class Thor
|
|||
#
|
||||
def run(command, config={})
|
||||
return unless behavior == :invoke
|
||||
description = "#{command.inspect} from #{relative_to_original_destination_root(destination_root, false)}"
|
||||
say_status :run, description, config.fetch(:verbose, true)
|
||||
say_status :run, command, config.fetch(:verbose, true)
|
||||
`#{command}` unless options[:pretend]
|
||||
end
|
||||
|
||||
|
@ -196,7 +194,7 @@ class Thor
|
|||
# ==== Parameters
|
||||
# task<String>:: the task to be invoked
|
||||
# args<Array>:: arguments to the task
|
||||
# options<Hash>:: give :verbose => false to not log the status. Other options
|
||||
# config<Hash>:: give :verbose => false to not log the status. Other options
|
||||
# are given as parameter to Thor.
|
||||
#
|
||||
# ==== Examples
|
|
@ -87,7 +87,7 @@ class Thor::Group
|
|||
if klass
|
||||
say_status :invoke, #{name.inspect}, #{verbose.inspect}
|
||||
block = self.class.invocation_blocks[#{name.inspect}]
|
||||
invoke_with_padding klass, task, &block
|
||||
_invoke_for_class_method klass, task, &block
|
||||
else
|
||||
say_status :error, %(#{name.inspect} [not found]), :red
|
||||
end
|
||||
|
@ -150,7 +150,7 @@ class Thor::Group
|
|||
if klass
|
||||
say_status :invoke, value, #{verbose.inspect}
|
||||
block = self.class.invocation_blocks[#{name.inspect}]
|
||||
invoke_with_padding klass, task, &block
|
||||
_invoke_for_class_method klass, task, &block
|
||||
else
|
||||
say_status :error, %(\#{value} [not found]), :red
|
||||
end
|
||||
|
@ -237,4 +237,26 @@ class Thor::Group
|
|||
end
|
||||
|
||||
include Thor::Base
|
||||
|
||||
protected
|
||||
|
||||
# Shortcut to invoke with padding and block handling. Use internally by
|
||||
# invoke and invoke_from_option class methods.
|
||||
#
|
||||
def _invoke_for_class_method(klass, task=nil, *args, &block)
|
||||
shell.padding += 1
|
||||
|
||||
result = if block_given?
|
||||
if block.arity == 2
|
||||
block.call(self, klass)
|
||||
else
|
||||
block.call(self, klass, task)
|
||||
end
|
||||
else
|
||||
invoke klass, task, *args
|
||||
end
|
||||
|
||||
shell.padding -= 1
|
||||
result
|
||||
end
|
||||
end
|
|
@ -130,26 +130,6 @@ class Thor
|
|||
end
|
||||
end
|
||||
|
||||
# Shortcut for invoke with padding and status handling. Used internally by
|
||||
# class options invoke and invoke_from_option.
|
||||
#
|
||||
def invoke_with_padding(klass, task=nil, *args, &block)
|
||||
shell.padding += 1
|
||||
|
||||
result = if block_given?
|
||||
if block.arity == 2
|
||||
block.call(self, klass)
|
||||
else
|
||||
block.call(self, klass, task)
|
||||
end
|
||||
else
|
||||
invoke klass, task, *args
|
||||
end
|
||||
|
||||
shell.padding -= 1
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Configuration values that are shared between invocations.
|
4
railties/lib/vendor/thor.rb
vendored
4
railties/lib/vendor/thor.rb
vendored
|
@ -1,9 +1,9 @@
|
|||
begin
|
||||
# Prefer gems to the bundled libs.
|
||||
require 'rubygems'
|
||||
gem 'thor', '>= 0.11.1'
|
||||
gem 'thor', '>= 0.11.2'
|
||||
rescue Gem::LoadError
|
||||
$:.unshift "#{File.dirname(__FILE__)}/thor-0.11.1/lib"
|
||||
$:.unshift "#{File.dirname(__FILE__)}/thor-0.11.2/lib"
|
||||
end
|
||||
|
||||
require 'thor'
|
||||
|
|
|
@ -31,6 +31,19 @@ class ActionsTest < GeneratorsTestCase
|
|||
assert_match /cool padding/, content
|
||||
end
|
||||
|
||||
def test_apply_does_not_log_status_if_required
|
||||
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", :verbose => false)
|
||||
|
||||
assert_match /cool padding/, content
|
||||
assert_no_match /apply http/, 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'
|
||||
|
|
Loading…
Reference in a new issue