module Capucine class CompassSass attr_accessor :tmp_config def initialize(capucine) @cap = capucine end def run_once self.update_config self.import_css if @cap.settings.conf['sass_import_css'] command = "compile --quiet --config \"#{@tmp_config}\" \"#{@cap.settings.working_dir}\"" self.exec_compass(command) puts "[compass] - Compiled" end def update_plugins gems return if not gems gems.each do |plugin| begin require "#{plugin}" rescue LoadError system("gem install #{plugin} --no-ri --no-rdoc") end end end def update_config require 'tempfile' require 'digest/md5' template_file = File.join @cap.settings.content_dir, 'templates', 'compass_config.erb' md5 = Digest::MD5.hexdigest(@cap.settings.working_dir.to_s) tmp = Tempfile.new('capucine_'+md5) @tmp_config = tmp.path @cap.settings.conf['compass_plugins_list'] = [] plugins_gems = [] plugins = @cap.settings.conf['compass_plugins'] if plugins.size > 0 plugins.each do |p| p = p.split('|') @cap.settings.conf['compass_plugins_list'].push p[0] if p[1] plugins_gems.push p[1] else plugins_gems.push p[0] end end end result = @cap.tools.render_template template_file, @cap.settings.conf f = File.open(@tmp_config, 'w') f.write(result) f.close self.update_plugins plugins_gems return tmp.path end def import_css import_dir = File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_css_dir'] output_dir= File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_output_dir'] Dir.mkdir(import_dir) if not File.directory?(import_dir) Dir.mkdir(output_dir) if not File.directory?(output_dir) formats = @cap.settings.conf['sass_import_formats'].split from_format = formats[0] to_format = formats[2] command = "sass-convert -R --from #{from_format} --to #{to_format} \"#{import_dir}\" \"#{output_dir}\"" system(command) @cap.tools.archive_file import_dir end def exec_compass compass_args, system = true if not system require 'compass' require 'compass/exec' return Compass::Exec::SubCommandUI.new(compass_args).run! else return system("compass #{compass_args}") end end def run_watch conf = self.update_config self.import_css if @cap.settings.conf['sass_import_css'] compass_args = ['watch', '--config', conf, @cap.settings.working_dir] compass_args = compass_args.join(' ') proc_watch = Thread.new { self.exec_compass compass_args } return proc_watch end end end