diff --git a/lib/compass/configuration.rb b/lib/compass/configuration.rb index ac4aaf7f..c6ca3e6a 100644 --- a/lib/compass/configuration.rb +++ b/lib/compass/configuration.rb @@ -41,6 +41,6 @@ module Compass end end -['adapters', 'comments', 'defaults', 'helpers', 'inheritance', 'serialization', 'data'].each do |lib| +['adapters', 'comments', 'defaults', 'helpers', 'inheritance', 'serialization', 'paths', 'data'].each do |lib| require "compass/configuration/#{lib}" end diff --git a/lib/compass/configuration/data.rb b/lib/compass/configuration/data.rb index 6b0db638..abdb82ff 100644 --- a/lib/compass/configuration/data.rb +++ b/lib/compass/configuration/data.rb @@ -22,10 +22,13 @@ module Compass include Compass::Configuration::Inheritance include Compass::Configuration::Serialization include Compass::Configuration::Adapters + extend Compass::Configuration::Paths inherited_accessor *ATTRIBUTES inherited_accessor :required_libraries #XXX we should make this array add up cumulatively. + strip_trailing_separator *ATTRIBUTES.select{|a| a.to_s =~ /dir|path/} + def initialize(name, attr_hash = nil) raise "I need a name!" unless name @name = name diff --git a/lib/compass/configuration/paths.rb b/lib/compass/configuration/paths.rb new file mode 100644 index 00000000..01d9cd92 --- /dev/null +++ b/lib/compass/configuration/paths.rb @@ -0,0 +1,19 @@ +module Compass::Configuration::Paths + + TRAILING_SEPARATOR = %r{.(/|#{Regexp.escape(File::SEPARATOR)})$} + + def strip_trailing_separator(*attributes) + attributes.each do |attr| + alias_method "#{attr}_with_trailing_separator".to_sym, attr + class_eval %Q{ + def #{attr} # def css_dir + path = #{attr}_with_trailing_separator # path = css_dir_with_trailing_separator + if path =~ TRAILING_SEPARATOR # if path =~ TRAILING_SEPARATOR + path = path[0..-($1.length+1)] # path = path[0..-($1.length+1)] + end # end + path # path + end # end + } + end + end +end diff --git a/test/configuration_test.rb b/test/configuration_test.rb index c53a625b..d13c528e 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -120,4 +120,29 @@ EXPECTED assert_equal expected_serialization, Compass.configuration.serialize end + def test_strip_trailing_directory_separators + contents = StringIO.new(<<-CONFIG) + css_dir = "css/" + sass_dir = "sass/" + images_dir = "images/" + javascripts_dir = "js/" + fonts_dir = "fonts/" + extensions_dir = "extensions/" + css_path = "css/" + sass_path = "sass/" + images_path = "images/" + javascripts_path = "js/" + fonts_path = "fonts/" + extensions_path = "extensions/" + CONFIG + + Compass.add_configuration(contents, "test_strip_trailing_directory_separators") + + assert_equal "css", Compass.configuration.css_dir + assert_equal "sass", Compass.configuration.sass_dir + assert_equal "images", Compass.configuration.images_dir + assert_equal "js", Compass.configuration.javascripts_dir + assert_equal "fonts", Compass.configuration.fonts_dir + assert_equal "extensions", Compass.configuration.extensions_dir + end end