Add a --time option to the compile and watch commands.
This commit is contained in:
parent
249544ce68
commit
ab71230b94
@ -14,6 +14,13 @@ The Documentation for the [latest stable release](http://compass-style.org/docs/
|
||||
|
||||
The Documentation for the [latest preview release](http://beta.compass-style.org/)
|
||||
|
||||
0.11.alpha.4 (12/08/2010)
|
||||
-------------------------
|
||||
|
||||
* Add a `--time` option to the compile and watch commands. This will print out
|
||||
the time spent compiling each sass file and a total at the end.
|
||||
|
||||
|
||||
0.11.alpha.3 (12/05/2010)
|
||||
-------------------------
|
||||
|
||||
|
@ -33,19 +33,20 @@ module Compass
|
||||
options ||= self.options if self.respond_to?(:options)
|
||||
skip_write = options[:dry_run]
|
||||
contents = process_erb(contents, options[:erb]) if options[:erb]
|
||||
extra = options[:extra] || ""
|
||||
if File.exists?(file_name)
|
||||
existing_contents = IO.read(file_name)
|
||||
if existing_contents == contents
|
||||
logger.record :identical, basename(file_name)
|
||||
logger.record :identical, basename(file_name), extra
|
||||
skip_write = true
|
||||
elsif options[:force]
|
||||
logger.record :overwrite, basename(file_name)
|
||||
logger.record :overwrite, basename(file_name), extra
|
||||
else
|
||||
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
|
||||
raise Compass::FilesystemConflict.new(msg)
|
||||
end
|
||||
else
|
||||
logger.record :create, basename(file_name)
|
||||
logger.record :create, basename(file_name), extra
|
||||
end
|
||||
if skip_write
|
||||
FileUtils.touch file_name unless options[:dry_run]
|
||||
|
@ -14,6 +14,9 @@ module Compass
|
||||
Options:
|
||||
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
|
||||
|
||||
opts.on("--time", "Display compilation times.") do
|
||||
self.options[:time] = true
|
||||
end
|
||||
super
|
||||
end
|
||||
end
|
||||
@ -51,6 +54,7 @@ module Compass
|
||||
:sass_files => explicit_sass_files,
|
||||
:dry_run => options[:dry_run])
|
||||
compiler_opts[:quiet] = options[:quiet] if options[:quiet]
|
||||
compiler_opts[:time] = options[:time] if options[:time]
|
||||
compiler_opts.merge!(additional_options)
|
||||
Compass::Compiler.new(working_path,
|
||||
Compass.configuration.sass_path,
|
||||
|
@ -76,6 +76,7 @@ module Compass
|
||||
target_directories.each {|dir| directory dir}
|
||||
|
||||
# Compile each sass file.
|
||||
result = timed do
|
||||
sass_files.zip(css_files).each do |sass_filename, css_filename|
|
||||
begin
|
||||
compile_if_required sass_filename, css_filename
|
||||
@ -84,21 +85,40 @@ module Compass
|
||||
end
|
||||
end
|
||||
end
|
||||
if options[:time]
|
||||
puts "Compilation took #{(result.__duration * 1000).round / 1000.0}s"
|
||||
end
|
||||
end
|
||||
|
||||
def compile_if_required(sass_filename, css_filename)
|
||||
if should_compile?(sass_filename, css_filename)
|
||||
compile sass_filename, css_filename
|
||||
compile sass_filename, css_filename, :time => options[:time]
|
||||
else
|
||||
logger.record :unchanged, basename(sass_filename) unless options[:quiet]
|
||||
end
|
||||
end
|
||||
|
||||
def timed
|
||||
start_time = Time.now
|
||||
res = yield
|
||||
end_time = Time.now
|
||||
res.instance_variable_set("@__duration", end_time - start_time)
|
||||
def res.__duration
|
||||
@__duration
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
# Compile one Sass file
|
||||
def compile(sass_filename, css_filename)
|
||||
def compile(sass_filename, css_filename, additional_options = {})
|
||||
start_time = end_time = nil
|
||||
css_content = logger.red do
|
||||
timed do
|
||||
engine(sass_filename, css_filename).render
|
||||
end
|
||||
write_file(css_filename, css_content, options.merge(:force => true))
|
||||
end
|
||||
duration = additional_options[:time] ? "(#{(css_content.__duration * 1000).round / 1000.0}s)" : ""
|
||||
write_file(css_filename, css_content, options.merge(:force => true, :extra => duration))
|
||||
end
|
||||
|
||||
def should_compile?(sass_filename, css_filename)
|
||||
|
Loading…
Reference in New Issue
Block a user