提交 28657e4f 编写于 作者: J José Valim 提交者: Jeremy Kemper

Update vendored thor and ensure that content is completely modified before...

Update vendored thor and ensure that content is completely modified before checking file collisions.
Signed-off-by: NJeremy Kemper <jeremy@bitsweat.net>
上级 74be7003
......@@ -9,7 +9,7 @@
require 'active_support/core_ext/string/inflections'
# TODO: Do not always push on vendored thor
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.0/lib")
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/vendor/thor-0.12.1/lib")
require 'rails/generators/base'
require 'rails/generators/named_base'
......
......@@ -123,10 +123,10 @@ def create_prototype_files
end
def create_script_files
directory "script" do |file|
prepend_file file, "#{shebang}\n", :verbose => false
chmod file, 0755, :verbose => false
directory "script" do |content|
"#{shebang}\n" + content
end
chmod "script", 0755, :verbose => false
end
def create_test_files
......
......@@ -17,7 +17,7 @@
* thor help now show information about any class/task. All those calls are
possible:
thor help describe
thor help describe:amazing
......@@ -47,7 +47,7 @@
are in the 'standard' group. Running 'thor -T' will only show the standard
tasks - adding --all will show all tasks. You can also filter on a specific
group using the --group option: thor -T --group advanced
== 0.9.6, released 2008-09-13
* Generic improvements
......
......@@ -7,7 +7,7 @@ Example:
class App < Thor # [1]
map "-L" => :list # [2]
desc "install APP_NAME", "install one of the available apps" # [3]
method_options :force => :boolean, :alias => :string # [4]
def install(name)
......@@ -17,7 +17,7 @@ Example:
end
# other code
end
desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
def list(search="")
# list everything
......@@ -126,13 +126,13 @@ invoked only once. For example:
invoke :two
invoke :three
end
desc "two", "Prints 2, 3"
def two
puts 2
invoke :three
end
desc "three", "Prints 3"
def three
puts 3
......@@ -155,15 +155,15 @@ Thor::Group as this:
class Counter < Thor::Group
desc "Prints 1, 2, 3"
def one
puts 1
end
def two
puts 2
end
def three
puts 3
end
......@@ -184,15 +184,15 @@ Besides, Thor::Group can parse arguments and options as Thor tasks:
# number will be available as attr_accessor
argument :number, :type => :numeric, :desc => "The number to start counting"
desc "Prints the 'number' given upto 'number+2'"
def one
puts number + 0
end
def two
puts number + 1
end
def three
puts number + 2
end
......
......@@ -56,7 +56,7 @@ class Default < Thor
s.test_files.exclude 'spec/sandbox/**/*'
end
Jeweler::RubyforgeTasks.new
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
......
......@@ -114,7 +114,7 @@ def source_paths
@source_paths ||= self.class.source_paths_for_search
end
# Receives a file or directory and search for it in the source paths.
# Receives a file or directory and search for it in the source paths.
#
def find_in_source_paths(file)
relative_root = relative_to_original_destination_root(destination_root, false)
......@@ -222,7 +222,7 @@ def run_ruby_script(command, config={})
run "#{command}", config.merge(:with => Thor::Util.ruby_command)
end
# Run a thor command. A hash of options can be given and it's converted to
# Run a thor command. A hash of options can be given and it's converted to
# switches.
#
# ==== Parameters
......
......@@ -79,11 +79,9 @@ def execute!
next if dirname == given_destination
base.empty_directory(dirname, config)
when /\.tt$/
destination = base.template(file_source, file_destination[0..-4], config)
@block.call(destination) if @block
destination = base.template(file_source, file_destination[0..-4], config, &@block)
else
destination = base.copy_file(file_source, file_destination, config)
@block.call(destination) if @block
destination = base.copy_file(file_source, file_destination, config, &@block)
end
end
end
......
......@@ -18,12 +18,14 @@ module Actions
#
# copy_file "doc/README"
#
def copy_file(source, destination=nil, config={})
def copy_file(source, destination=nil, config={}, &block)
destination ||= source
source = File.expand_path(find_in_source_paths(source.to_s))
create_file destination, nil, config do
File.read(source)
content = File.read(source)
content = block.call(content) if block
content
end
end
......@@ -72,13 +74,15 @@ def get(source, destination=nil, config={}, &block)
#
# template "doc/README"
#
def template(source, destination=nil, config={})
def template(source, destination=nil, config={}, &block)
destination ||= source
source = File.expand_path(find_in_source_paths(source.to_s))
context = instance_eval('binding')
create_file destination, nil, config do
ERB.new(::File.read(source), nil, '-').result(context)
content = ERB.new(::File.read(source), nil, '-').result(context)
content = block.call(content) if block
content
end
end
......
......@@ -11,7 +11,7 @@ module Actions
# data<String>:: Data to add to the file. Can be given as a block.
# config<Hash>:: give :verbose => false to not log the status and the flag
# for injection (:after or :before).
#
#
# ==== Examples
#
# inject_into_file "config/environment.rb", "config.gem :thor", :after => "Rails::Initializer.run do |config|\n"
......
......@@ -132,7 +132,7 @@ def invoke_from_option(*names, &block)
names.each do |name|
unless class_options.key?(name)
raise ArgumentError, "You have to define the option #{name.inspect} " <<
raise ArgumentError, "You have to define the option #{name.inspect} " <<
"before setting invoke_from_option."
end
......
......@@ -36,7 +36,7 @@ def initialize(name, description=nil, required=nil, type=nil, default=nil, banne
# string (--foo=value) or booleans (just --foo).
#
# By default all options are optional, unless :required is given.
#
#
def self.parse(key, value)
if key.is_a?(Array)
name, *aliases = key
......
......@@ -36,7 +36,7 @@ def method_missing(meth, *args)
def install(name)
initialize_thorfiles
# If a directory name is provided as the argument, look for a 'main.thor'
# If a directory name is provided as the argument, look for a 'main.thor'
# task in said directory.
begin
if File.directory?(File.expand_path(name))
......
......@@ -143,7 +143,7 @@ def file_collision(destination)
answer = ask %[Overwrite #{destination}? (enter "h" for help) #{options}]
case answer
when is?(:yes), is?(:force)
when is?(:yes), is?(:force), ""
return true
when is?(:no), is?(:skip)
return false
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册