提交 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
......
......@@ -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
......
......@@ -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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册