Created
April 7, 2009 06:25
-
-
Save kematzy/91118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From c579d6ab6d827bdff888bf143424353b70cc25ca Mon Sep 17 00:00:00 2001 | |
From: kematzy <kematzy gmail com> | |
Date: Tue, 7 Apr 2009 13:54:23 +0800 | |
Subject: [PATCH] [SASS] Bug fix: Fixing multiple duplicate paths in the Sass::Engine.options[:load_paths] value. | |
After one request the :load_paths value is: | |
:load_paths=>["./test/sass/templates", "./test/sass/more_templates"] | |
However, after a number of consecutive requests the :load_paths value becomes: | |
:load_paths=> | |
["./test/sass/more_templates", | |
"./test/sass/more_templates", | |
"./test/sass/more_templates", | |
"./test/sass/more_templates", | |
"./test/sass/templates", | |
"./test/sass/more_templates", | |
"./test/sass/templates", | |
"./test/sass/templates", | |
"./test/sass/more_templates"] | |
This issue occurs as soon as you do "@import some/linked_file.sass" in a sass file. | |
If you import a larger type projects of sass files, such as Compass for instance, | |
the :load_paths value can increase to a MASSIVELY large array after a large number | |
of consecutive requests. | |
By ensuring the :load_paths value array is made unique, this problem is removed. | |
Hopefully the above is clear enough, and this patch is clear and usable. | |
All tests pass on the latest Edge version. | |
--- | |
lib/sass/engine.rb | 2 +- | |
test/sass/engine_test.rb | 20 ++++++++++++++++++++ | |
test/sass/templates/load_paths.sass | 2 ++ | |
3 files changed, 23 insertions(+), 1 deletions(-) | |
create mode 100644 test/sass/templates/load_paths.sass | |
diff --git a/lib/sass/engine.rb b/lib/sass/engine.rb | |
index 6b538d0..e97d541 100644 | |
--- a/lib/sass/engine.rb | |
+++ b/lib/sass/engine.rb | |
@@ -430,7 +430,7 @@ END | |
end | |
def import_paths | |
- paths = @options[:load_paths] || [] | |
+ paths = @options[:load_paths].uniq || [] | |
paths.unshift(File.dirname(@options[:filename])) if @options[:filename] | |
paths | |
end | |
diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb | |
index ab7d3d2..e3cb287 100755 | |
--- a/test/sass/engine_test.rb | |
+++ b/test/sass/engine_test.rb | |
@@ -3,6 +3,11 @@ require File.dirname(__FILE__) + '/../test_helper' | |
require 'sass/engine' | |
require 'stringio' | |
+# just a quick hack to conveniently access the Sass::Engine options | |
+class Sass::Engine | |
+ def sass_engine_options; @options; end | |
+end | |
+ | |
class SassEngineTest < Test::Unit::TestCase | |
# A map of erroneous Sass documents to the error messages they should produce. | |
# The error messages may be arrays; | |
@@ -167,6 +172,21 @@ SASS | |
renders_correctly "import", { :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"] } | |
end | |
+ def test_multi_load_paths_settings | |
+ ## NB!! sass_engine_options is defined in top of this test document | |
+ expected_options = {:load_paths=>["./test/sass/templates", "./test/sass/more_templates"],:style=>:compact} | |
+ expected_output = "/* load_paths.sass */\n#foo { background-color: #baf; }\n" | |
+ 20.times do | |
+ @res = Sass::Engine.new("@import load_paths.sass", { | |
+ :style => :compact, | |
+ :load_paths => [File.dirname(__FILE__) + "/templates", File.dirname(__FILE__) + "/more_templates"] | |
+ }) | |
+ assert_equal(expected_options, @res.sass_engine_options) # optional, but will quickly bail if wrong | |
+ assert_equal(expected_output, @res.render) # sanity test only | |
+ end | |
+ assert_equal(expected_options, @res.sass_engine_options) # after all the reloads | |
+ end | |
+ | |
def test_units | |
renders_correctly "units" | |
end | |
diff --git a/test/sass/templates/load_paths.sass b/test/sass/templates/load_paths.sass | |
new file mode 100644 | |
index 0000000..1a75cad | |
--- /dev/null | |
+++ b/test/sass/templates/load_paths.sass | |
@@ -0,0 +1,2 @@ | |
+/* load_paths.sass | |
+@import more_partial.sass | |
-- | |
1.6.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment