Factored out a logger for the command line to tell the user what is happening.

This commit is contained in:
Chris Eppstein 2009-02-01 14:17:07 -08:00
parent e8d249fa38
commit 845fa14e71
3 changed files with 39 additions and 1 deletions

View File

@ -25,7 +25,10 @@ module Compass
def base_directory def base_directory
File.expand_path(File.join(File.dirname(__FILE__), '..')) File.expand_path(File.join(File.dirname(__FILE__), '..'))
end end
module_function :base_directory def lib_directory
File.expand_path(File.join(File.dirname(__FILE__)))
end
module_function :base_directory, :lib_directory
end end
require File.join(File.dirname(__FILE__), 'compass', 'frameworks') require File.join(File.dirname(__FILE__), 'compass', 'frameworks')

View File

@ -1,6 +1,7 @@
require 'optparse' require 'optparse'
require 'rubygems' require 'rubygems'
require 'haml' require 'haml'
require File.join(Compass.lib_directory, 'compass', 'logger')
module Compass module Compass
module Exec module Exec

34
lib/compass/logger.rb Normal file
View File

@ -0,0 +1,34 @@
module Compass
class Logger
DEFAULT_ACTIONS = [:directory, :exists, :remove, :create, :overwrite]
attr_accessor :actions, :options
def initialize(*actions)
self.options = actions.last.is_a?(Hash) ? actions.pop : {}
@actions = DEFAULT_ACTIONS.dup
@actions += actions
end
# Record an action that has occurred
def record(action, *arguments)
log "#{action_padding(action)}#{action} #{arguments.join(' ')}"
end
# Emit a log message
def log(msg)
puts msg
end
# add padding to the left of an action that was performed.
def action_padding(action)
' ' * [(max_action_length - action.to_s.length), 0].max
end
# the maximum length of all the actions known to the logger.
def max_action_length
@max_action_length ||= actions.inject(0){|memo, a| [memo, a.to_s.length].max}
end
end
end