Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow compass compile to traverse symlinks. Fixes #1379 #1380

Closed
wants to merge 1 commit into from

2 participants

@xzyfer

Sometimes asset pipeline setups require directories to be symlinked from a working directory to a public directory, for example when using mixins defined in bower'd components.

Compass currently doesn't support this because Dir.glob('**') does not traverse symlinks to prevent infinite loops.

Sprokets had a similar issue and solved it by allowing symlink traversal for up to one level sstephenson/sprockets#189. I've ported their patch to compass.

I'm not a ruby developer by trade so I image this could be made more terse.

@chriseppstein

My guess is the sass compiler has a similar issue. I'd really like to standardize on a single implementation for both the sass compiler is quite good now and can replace the compass compiler, IMO.

I'd like to wait to merge this until after 1.0.

@chriseppstein

Compass uses the Sass compiler now. If this bug exists there, we should fix it in Sass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 17, 2013
  1. @xzyfer
This page is out of date. Refresh to see the latest.
View
15 lib/compass/compiler.rb
@@ -33,8 +33,21 @@ def determine_cache_location
end
def sass_files(options = {})
+ @sass_files = []
exclude_partials = options.fetch(:exclude_partials, true)
- @sass_files = self.options[:sass_files] || Dir.glob(separate("#{from}/**/#{'[^_]' if exclude_partials}*.s[ac]ss"))
+ if self.options[:sass_files]
+ @sass_files = self.options[:sass_files]
+ else
+ Dir[separate("#{from}/**/*")].each do |filename|
+ @sass_files.push(filename) unless File.directory?(filename) || /#{'[^_]' if exclude_partials}*.s[ac]ss$/.match(filename) == false
+ if File.symlink?(filename) && File.directory?(filename)
+ Dir[separate("#{filename}/**/#{'[^_]' if exclude_partials}*.s[ac]ss")].each do |inner_filename|
+ @sass_files.push(inner_filename) unless File.directory?(inner_filename)
+ end
+ end
+ end
+ end
+ return @sass_files
end
def relative_stylesheet_name(sass_file)
View
2  test/fixtures/stylesheets/symlinked/foo.sass
@@ -0,0 +1,2 @@
+div
+ color: red
View
0  test/fixtures/stylesheets/symlinked/sub1/sub1-1/sub1-1.sass
No changes.
View
0  test/fixtures/stylesheets/symlinked/sub1/sub1.sass
No changes.
View
1  test/fixtures/stylesheets/symlinked/sub1/sub2
View
0  test/fixtures/stylesheets/symlinked/sub2/sub2.sass
No changes.
View
1  test/fixtures/stylesheets/symlinked/symlinked
View
1  test/fixtures/stylesheets/symlinked/symlinked_foo.sass
View
18 test/units/compiler_test.rb
@@ -2,10 +2,24 @@
require 'fileutils'
class CompilerTest < Test::Unit::TestCase
-
+
it "should strip css from file name and reappend" do
compiler = Compass::Compiler.new(Dir.pwd, 'foo', 'bar', {})
assert_equal 'screen', compiler.stylesheet_name(File.join(Dir.pwd, 'foo', 'screen.css.scss'))
end
-end
+ it "should traverse symlinked directories up to 1 level deep" do
+ compiler = Compass::Compiler.new(Dir.pwd, File.join(fixture_path, 'stylesheets', 'symlinked'), nil, {})
+ assert_equal compiler.sass_files, [
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/foo.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/sub1/sub1-1/sub1-1.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/sub1/sub1.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/sub1/sub2/sub2.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/sub2/sub2.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/symlinked/sub1-1/sub1-1.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/symlinked/sub1.sass"),
+ File.join(Dir.pwd, "test/fixtures/stylesheets/symlinked/symlinked_foo.sass")
+ ]
+ end
+
+end
Something went wrong with that request. Please try again.