lib/compass-sass.rb in capucine-0.1.7 vs lib/compass-sass.rb in capucine-0.2.0
- old
+ new
@@ -1,110 +1,108 @@
module Capucine
class CompassSass
+ attr_accessor :tmp_config
- def self.update_plugins gems
+ 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 self.update_config
- settings = Capucine.settings
- template_file = File.join settings.gem_content_dir, 'templates', 'compass_config.erb'
- output_file = File.join settings.working_dir, '.compass.rb'
+ def update_config
+ require 'tempfile'
+ require 'digest/md5'
- settings.config['compass_plugins_list'] = []
+ 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 = settings.config['compass_plugins']
+ plugins = @cap.settings.conf['compass_plugins']
if plugins.size > 0
plugins.each do |p|
p = p.split('|')
- settings.config['compass_plugins_list'].push p[0]
+ @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
- config_ = settings.config
- result = Capucine::Tools.render_template template_file, config_
+ result = @cap.tools.render_template template_file, @cap.settings.conf
- f = File.open(output_file, 'w')
+ f = File.open(@tmp_config, 'w')
f.write(result)
f.close
self.update_plugins plugins_gems
+
+ return tmp.path
end
- # def self.load_my_functions
- # rb_files = Dir.glob "#{Capucine.settings.working_dir}/#{Capucine.settings.config['compass_compass_files_dir']}/**/**.rb"
- #
- # rb_files.each do |file|
- # require "#{file}"
- # end
- #
- # end
+ def import_css
- def self.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']
- s = Capucine.settings
- import_dir = File.join s.working_dir, s.config['sass_import_css_dir']
- output_dir= File.join s.working_dir, s.config['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 = s.config['sass_import_formats'].split
+ 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)
- Capucine::Tools.archive_file import_dir
+ @cap.tools.archive_file import_dir
end
- def self.run_once
- self.update_config
- # self.load_my_functions
- self.import_css if Capucine.settings.config['sass_import_css']
- config = File.join Capucine.settings.working_dir, '.compass.rb'
- command = "compass compile --quiet --config \"#{config}\" \"#{Capucine.settings.working_dir}\""
- system(command)
- puts "[compass] - Compiled"
+ 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 self.export_path
- # require 'compass'
- # require 'rubygems'
- # path_compass = Gem.loaded_specs['compass'].full_gem_path
- # ENV['PATH'] = "#{path_compass}:#{Capucine.settings.gem_dir}:#{ENV['PATH']}"
- # end
+ def run_watch
+ conf = self.update_config
+ self.import_css if @cap.settings.conf['sass_import_css']
- def self.proc_watch
- self.update_config
- config_file = File.join Capucine.settings.working_dir, '.compass.rb'
- compass_args = ['watch', '--config', config_file, Capucine.settings.working_dir]
- proc_watch = Thread.new {
- self.exec_compass compass_args
- }
- return proc_watch
- end
+ compass_args = ['watch', '--config', conf, @cap.settings.working_dir]
+ compass_args = compass_args.join(' ')
- def self.exec_compass compass_args
- require 'compass'
- require 'compass/exec'
- Compass::Exec::SubCommandUI.new(compass_args).run!
+ proc_watch = Thread.new { self.exec_compass compass_args }
+ return proc_watch
end
end
end