lib/thor/actions/templater.rb in wycats-thor-0.11.0 vs lib/thor/actions/templater.rb in wycats-thor-0.11.1
- old
+ new
@@ -6,23 +6,22 @@
#
# This implementation is completely based in Templater actions, created
# 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.
#
# ==== Parameters
# base<Thor::Base>:: A Thor::Base instance
# source<String>:: Relative path to the source of this file
# destination<String>:: Relative path to the destination of this file
- # log_status<Boolean>:: If false, does not log the status. True by default.
- # Templater log status does not accept color.
+ # config<Hash>:: 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
# Returns the contents of the source file as a String. If render is
@@ -54,11 +53,11 @@
# Invokes the action. By default it adds to the file the content rendered,
# 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
end
@@ -99,11 +98,11 @@
# to "dest/bar/baz.rb". If we don't take into account the relative_root
# (in this case, "bar"), it would copy the contents at "source/baz.rb".
#
def source=(source)
if source
- @source = ::File.expand_path(source.to_s, File.join(base.source_root, base.relative_root))
+ @source = ::File.expand_path(base.find_in_source_paths(source.to_s))
end
end
# Sets the absolute destination value from a relative destination value.
# It also stores the given and relative destination. Let's suppose our
@@ -121,11 +120,11 @@
#
def destination=(destination)
if destination
@given_destination = convert_encoded_instructions(destination.to_s)
@destination = ::File.expand_path(@given_destination, base.destination_root)
- @relative_destination = base.relative_to_absolute_root(@destination)
+ @relative_destination = base.relative_to_original_destination_root(@destination)
end
end
# Filenames in the encoded form are converted. If you have a file:
#
@@ -185,10 +184,10 @@
end
# 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
end
end