Extract a project compiler class from the update_project command.

This commit is contained in:
Chris Eppstein 2009-02-08 02:22:10 -08:00
parent 6c4759278e
commit 3adf6a6435
3 changed files with 45 additions and 9 deletions

View File

@ -57,8 +57,6 @@ module Compass
# Compile one Sass file
def compile(sass_filename, css_filename, options)
target_directory = File.dirname(css_filename)
directory target_directory
logger.record :compile, basename(sass_filename)
if File.exists?(css_filename)
logger.record :overwrite, basename(css_filename)

View File

@ -1,4 +1,5 @@
require File.join(File.dirname(__FILE__), 'project_base')
require File.join(Compass.lib_directory, 'compass', 'compiler')
module Compass
module Commands
@ -13,13 +14,10 @@ module Compass
read_project_configuration
default_options = { :style => default_output_style }
compilation_options = default_options.merge(options).merge(:load_paths => sass_load_paths)
Dir.glob(separate("#{project_src_directory}/**/[^_]*.sass")).each do |sass_file|
stylesheet_name = sass_file[("#{project_src_directory}/".length)..-6]
sass_filename = projectize("#{project_src_subdirectory}/#{stylesheet_name}.sass")
css_filename = projectize("#{project_css_subdirectory}/#{stylesheet_name}.css")
compile sass_filename, css_filename, compilation_options
end
Compass::Compiler.new(working_path,
projectize(project_src_subdirectory),
projectize(project_css_subdirectory),
compilation_options).run
end
def default_output_style

40
lib/compass/compiler.rb Normal file
View File

@ -0,0 +1,40 @@
module Compass
class Compiler
include Actions
attr_accessor :working_path, :from, :to, :options
def initialize(working_path, from, to, options)
self.working_path = working_path
self.from, self.to = from, to
self.logger = options.delete(:logger)
self.options = options
end
def sass_files
@sass_files || Dir.glob(separate("#{from}/**/[^_]*.sass"))
end
def stylesheet_name(sass_file)
sass_file[("#{from}/".length)..-6]
end
def css_files
@css_files || sass_files.map{|sass_file| "#{to}/#{stylesheet_name(sass_file)}.css"}
end
def target_directories
css_files.map{|css_file| File.dirname(css_file)}.uniq.sort.sort_by{|d| d.length }
end
def run
target_directories.each do |dir|
directory dir
end
sass_files.zip(css_files).each do |sass_filename, css_filename|
compile sass_filename, css_filename, options
end
end
end
end