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/)
|
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)
|
0.11.alpha.3 (12/05/2010)
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
|
@ -33,19 +33,20 @@ module Compass
|
|||||||
options ||= self.options if self.respond_to?(:options)
|
options ||= self.options if self.respond_to?(:options)
|
||||||
skip_write = options[:dry_run]
|
skip_write = options[:dry_run]
|
||||||
contents = process_erb(contents, options[:erb]) if options[:erb]
|
contents = process_erb(contents, options[:erb]) if options[:erb]
|
||||||
|
extra = options[:extra] || ""
|
||||||
if File.exists?(file_name)
|
if File.exists?(file_name)
|
||||||
existing_contents = IO.read(file_name)
|
existing_contents = IO.read(file_name)
|
||||||
if existing_contents == contents
|
if existing_contents == contents
|
||||||
logger.record :identical, basename(file_name)
|
logger.record :identical, basename(file_name), extra
|
||||||
skip_write = true
|
skip_write = true
|
||||||
elsif options[:force]
|
elsif options[:force]
|
||||||
logger.record :overwrite, basename(file_name)
|
logger.record :overwrite, basename(file_name), extra
|
||||||
else
|
else
|
||||||
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
|
msg = "File #{basename(file_name)} already exists. Run with --force to force overwrite."
|
||||||
raise Compass::FilesystemConflict.new(msg)
|
raise Compass::FilesystemConflict.new(msg)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
logger.record :create, basename(file_name)
|
logger.record :create, basename(file_name), extra
|
||||||
end
|
end
|
||||||
if skip_write
|
if skip_write
|
||||||
FileUtils.touch file_name unless options[:dry_run]
|
FileUtils.touch file_name unless options[:dry_run]
|
||||||
|
@ -14,6 +14,9 @@ module Compass
|
|||||||
Options:
|
Options:
|
||||||
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
|
}.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n")
|
||||||
|
|
||||||
|
opts.on("--time", "Display compilation times.") do
|
||||||
|
self.options[:time] = true
|
||||||
|
end
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -51,6 +54,7 @@ module Compass
|
|||||||
:sass_files => explicit_sass_files,
|
:sass_files => explicit_sass_files,
|
||||||
:dry_run => options[:dry_run])
|
:dry_run => options[:dry_run])
|
||||||
compiler_opts[:quiet] = options[:quiet] if options[:quiet]
|
compiler_opts[:quiet] = options[:quiet] if options[:quiet]
|
||||||
|
compiler_opts[:time] = options[:time] if options[:time]
|
||||||
compiler_opts.merge!(additional_options)
|
compiler_opts.merge!(additional_options)
|
||||||
Compass::Compiler.new(working_path,
|
Compass::Compiler.new(working_path,
|
||||||
Compass.configuration.sass_path,
|
Compass.configuration.sass_path,
|
||||||
|
@ -76,29 +76,49 @@ module Compass
|
|||||||
target_directories.each {|dir| directory dir}
|
target_directories.each {|dir| directory dir}
|
||||||
|
|
||||||
# Compile each sass file.
|
# Compile each sass file.
|
||||||
sass_files.zip(css_files).each do |sass_filename, css_filename|
|
result = timed do
|
||||||
begin
|
sass_files.zip(css_files).each do |sass_filename, css_filename|
|
||||||
compile_if_required sass_filename, css_filename
|
begin
|
||||||
rescue Sass::SyntaxError => e
|
compile_if_required sass_filename, css_filename
|
||||||
handle_exception(sass_filename, css_filename, e)
|
rescue Sass::SyntaxError => e
|
||||||
|
handle_exception(sass_filename, css_filename, e)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if options[:time]
|
||||||
|
puts "Compilation took #{(result.__duration * 1000).round / 1000.0}s"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def compile_if_required(sass_filename, css_filename)
|
def compile_if_required(sass_filename, css_filename)
|
||||||
if should_compile?(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
|
else
|
||||||
logger.record :unchanged, basename(sass_filename) unless options[:quiet]
|
logger.record :unchanged, basename(sass_filename) unless options[:quiet]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Compile one Sass file
|
def timed
|
||||||
def compile(sass_filename, css_filename)
|
start_time = Time.now
|
||||||
css_content = logger.red do
|
res = yield
|
||||||
engine(sass_filename, css_filename).render
|
end_time = Time.now
|
||||||
|
res.instance_variable_set("@__duration", end_time - start_time)
|
||||||
|
def res.__duration
|
||||||
|
@__duration
|
||||||
end
|
end
|
||||||
write_file(css_filename, css_content, options.merge(:force => true))
|
res
|
||||||
|
end
|
||||||
|
|
||||||
|
# Compile one Sass file
|
||||||
|
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
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def should_compile?(sass_filename, css_filename)
|
def should_compile?(sass_filename, css_filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user