From d2a3046526736bf6e58d6960bcb19f61a9af5763 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Mon, 2 Feb 2009 18:43:17 -0800 Subject: [PATCH] Make the Configuration class a singleton + added some access helpers to the Compass module. --- lib/compass/configuration.rb | 31 ++++++++++++++++++++++++++- lib/compass/installers/stand_alone.rb | 13 ++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/compass/configuration.rb b/lib/compass/configuration.rb index f7a59f29..bcc60db4 100644 --- a/lib/compass/configuration.rb +++ b/lib/compass/configuration.rb @@ -1,6 +1,9 @@ +require 'singleton' + module Compass class Configuration - attr_accessor :css_dir, :sass_dir, :images_dir, :javascripts_dir + include Singleton + attr_accessor :project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir # parses a manifest file which is a ruby script # evaluated in a Manifest instance context @@ -14,4 +17,30 @@ module Compass binding end end + + module ConfigHelpers + def configuration + if block_given? + yield Configuration.instance + end + Configuration.instance + end + + def sass_plugin_configuration + proj_sass_path = File.join(configuration.project_path, configuration.sass_dir) + proj_css_path = File.join(configuration.project_path, configuration.css_dir) + locations = {proj_sass_path => proj_css_path} + Compass::Frameworks::ALL.each do |framework| + locations[framework.stylesheets_directory] = proj_css_path + end + {:template_location => locations} + end + + def configure_sass_plugin! + Sass::Plugin.options.merge!(sass_plugin_configuration) + end + end + + extend ConfigHelpers + end diff --git a/lib/compass/installers/stand_alone.rb b/lib/compass/installers/stand_alone.rb index 5d643464..094b0230 100644 --- a/lib/compass/installers/stand_alone.rb +++ b/lib/compass/installers/stand_alone.rb @@ -4,11 +4,10 @@ module Compass class StandAloneInstaller < Base def configure - @config = Compass::Configuration.new if File.exists?(config_file) - @config.parse(config_file) + Compass.configuration.parse(config_file) elsif File.exists?(old_config_file) - @config.parse(old_config_file) + Compass.configuration.parse(old_config_file) end super end @@ -22,19 +21,19 @@ module Compass end def default_css_dir - @config.css_dir || "stylesheets" + Compass.configuration.css_dir || "stylesheets" end def default_sass_dir - @config.sass_dir ||"src" + Compass.configuration.sass_dir ||"src" end def default_images_dir - @config.images_dir || "images" + Compass.configuration.images_dir || "images" end def default_javascripts_dir - @config.javascripts_dir || "javascripts" + Compass.configuration.javascripts_dir || "javascripts" end # Read the configuration file for this project