diff --git a/lib/compass/configuration.rb b/lib/compass/configuration.rb index 04b87232..ecfd8681 100644 --- a/lib/compass/configuration.rb +++ b/lib/compass/configuration.rb @@ -3,25 +3,54 @@ require 'singleton' module Compass class Configuration include Singleton - attr_accessor :project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir + attr_accessor :project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir, :required_libraries + + def initialize + self.required_libraries = [] + end # parses a manifest file which is a ruby script # evaluated in a Manifest instance context def parse(config_file) open(config_file) do |f| - eval(f.read, instance_binding, config_file) + parse_string(f.read, config_file) end end + def parse_string(contents, filename) + eval(contents, binding, filename) + [:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |prop| + value = eval(prop.to_s, binding) rescue nil + self.send("#{prop}=", value) if value + end + end + + def serialize + contents = "" + required_libraries.each do |lib| + contents << %Q{require '#{lib}'\n} + end + contents << "\n" if required_libraries.any? + [:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |prop| + value = send(prop) + contents << %Q(#{prop} = "#{value}"\n) if value + end + contents + end + + # Support for testing. def reset! [:project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |attr| send("#{attr}=", nil) end + self.required_libraries = [] end - def instance_binding - binding + def require(lib) + required_libraries << lib + super end + end module ConfigHelpers @@ -45,6 +74,17 @@ module Compass def configure_sass_plugin! Sass::Plugin.options.merge!(sass_plugin_configuration) end + + def sass_engine_options + load_paths = [] + if configuration.project_path && configuration.sass_dir + load_paths << File.join(configuration.project_path, configuration.sass_dir) + end + Compass::Frameworks::ALL.each do |framework| + load_paths << framework.stylesheets_directory + end + {:load_paths => load_paths} + end end extend ConfigHelpers diff --git a/test/configuration_test.rb b/test/configuration_test.rb new file mode 100644 index 00000000..00fd98dc --- /dev/null +++ b/test/configuration_test.rb @@ -0,0 +1,28 @@ +require File.dirname(__FILE__)+'/test_helper' +require 'compass' + +class ConfigurationTest < Test::Unit::TestCase + def test_parse_and_serialize + contents = <<-CONFIG + require 'compass' + require 'sass' + + css_dir = "css" + sass_dir = "sass" + images_dir = "img" + javascripts_dir = "js" + CONFIG + + Compass.configuration.parse_string(contents, "test_parse") + + assert_equal 'sass', Compass.configuration.sass_dir + assert_equal 'css', Compass.configuration.css_dir + assert_equal 'img', Compass.configuration.images_dir + assert_equal 'js', Compass.configuration.javascripts_dir + + expected_lines = contents.split("\n").map{|l|l.strip} + actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip} + assert_equal expected_lines, actual_lines + end + +end \ No newline at end of file