require 'sass/plugin/configuration' module Sass::Plugin::Configuration def default_options @default_options ||= { :css_location => './public/stylesheets', :always_update => false, :always_check => true, :full_exception => true, :cache_location => File.join(Spider.paths[:tmp], 'sass', '.sass_cache') }.freeze end end require 'sass/plugin' require 'sass' module Spider class SassCompiler def initialize(base_path) @base_path = base_path end def compile(src, dest) use_compass = false if Spider.conf.get('css.sass.use_compass') begin require 'compass' use_compass = true rescue LoadError => exc Spider.logger.debug(exc) Spider.logger.debug("Compass not found. Please install 'compass' gem") end end if use_compass work_dir = FileUtils.mkdir_p(File.join(Spider.paths[:tmp], 'sass')) src_dir = File.dirname(src) src_dir = src_dir # dest_dir = File.dirname(dest) options = { :project_path => @base_path, :css_dir => 'css', :sass_dir => 'sass', # :fonts_path => src_dir, # :images_path => src_dir, :fonts_dir => 'fonts', :images_dir => 'img', :javascripts_dir => 'js', :relative_assets => true, :line_comments => Spider.runmode == 'devel' ? true : false, :sass => Compass.sass_engine_options.merge({ :cache_location => File.join(work_dir, '.sass_cache') }), :css_filename => dest } config = Compass::Configuration::Data.new(:spider, options) Compass.add_project_configuration(config) compiler = Compass::Compiler.new(work_dir, File.dirname(src), File.dirname(dest), options) compiler.compile(src, dest) else engine = Sass::Engine.for_file(src, {}) output = engine.render File.open(dest, 'w') do |f| f.write "/* This file is autogenerated; do not edit directly (edit #{src} instead) */\n\n" f.write output end end end end end