[Configuration] Strip trailing slash and directory separtors from directory and path configuration variables.

Closes GH-77.
This commit is contained in:
Chris Eppstein 2010-01-10 12:26:42 -08:00
parent fd2ab06f60
commit 5078d0a0a9
4 changed files with 48 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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