Skip to content

Instantly share code, notes, and snippets.

@krisbulman
Created October 26, 2012 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisbulman/4d16fdbe950ecbe582de to your computer and use it in GitHub Desktop.
Save krisbulman/4d16fdbe950ecbe582de to your computer and use it in GitHub Desktop.
compass/#989

This is a debugging session for problem: Compass/compass#989

Using this sample project: https://github.com/krisbulman/compass-image-url-example

####Summary of problem####

Since this commit in Sass, relative paths to files are not output on a second compile in all versions of compass (stable and dev), when path functions such as image-url() and font-url() are used within mixins.

####Debugging session using debugger####

1.defaults.rb - direct output of debugger session of default_images_path on first compile

  $ compass clean
  $ compass compile
  step through debugger and print vars

2.defaults.rb - direct output of debugger session of default_images_path on second compile after non code change of _mixins.scss

  $ compass compile
  step through debugger and print vars

3.defaults.rb.diff - a diff of the two debugger sessions

####Points worth noting:####

  1. The final stylesheet recompiles when it shouldn't, a compile can be triggered just by modifying 1 space in _mixins.scss
  2. This function (line 224 of urls.rb) fails to return true because options[:css_filename] is nil in the second compile, so the relative path is not added to filenames.
  def compute_relative_path(path)
    if (target_css_file = options[:css_filename])
      Pathname.new(path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
    end
  end
## WORKING FIRST COMPILE
# lib/compass/configuration/defaults.rb:60
if (pp = top_level.project_path) && (dir = top_level.images_dir)
(rdb:1) n
# lib/compass/configuration/defaults.rb:61
Compass.projectize(dir, pp)
(rdb:1) n
(eval):4
(rdb:1) n
(eval):7
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:224
if (target_css_file = options[:css_filename])
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:225
Pathname.new(path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
(rdb:1) p path
"/Users/krisbulman/code/compass-image-url-example/images"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:106
real_path = if Compass.configuration.images_dir
(rdb:1) p path
"grid-col-numbers.png"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:107
File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path)
(rdb:1) p path
"grid-col-numbers.png"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:111
if http_images_path
(rdb:1) p http_images_path
"../images"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:112
http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
(rdb:1) p http_images_path
"../images"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:113
path = "#{http_images_path}#{path}"
(rdb:1) p path
"grid-col-numbers.png"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:117
asset_host = if !relative? && Compass.configuration.asset_host
(rdb:1) p http_images_path
"../images/"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:122
if cache_buster.to_bool
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:123
if cache_buster.is_a?(Sass::Script::String)
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:126
path = cache_busted_path(path, real_path)
(rdb:1) p path
"../images/grid-col-numbers.png"
## BROKEN SECOND COMPILE AFTER CHANGE IN MIXINS
# lib/compass/configuration/defaults.rb:60
if (pp = top_level.project_path) && (dir = top_level.images_dir)
(rdb:1) n
# lib/compass/configuration/defaults.rb:61
Compass.projectize(dir, pp)
(rdb:1) n
(eval):4
(rdb:1) n
(eval):7
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:224
if (target_css_file = options[:css_filename])
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:106
real_path = if Compass.configuration.images_dir
(rdb:1) p path
"grid-col-numbers.png"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:107
File.join(Compass.configuration.project_path, Compass.configuration.images_dir, path)
(rdb:1) p path
"grid-col-numbers.png"
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:111
if http_images_path
(rdb:1) p http_images_path
nil
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:117
asset_host = if !relative? && Compass.configuration.asset_host
(rdb:1) p http_images_path
nil
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:122
if cache_buster.to_bool
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:123
if cache_buster.is_a?(Sass::Script::String)
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:126
path = cache_busted_path(path, real_path)
(rdb:1) p path
"grid-col-numbers.png"
# DIFF OF TWO COMPILES
--- 52f73c krisbulman 5 minutes ago 3.diff.defaults.rb
+++ c08070 krisbulman 5 minutes ago 3.diff.defaults.rb
@@ -13,11 +13,6 @@
# lib/compass/sass_extensions/functions/urls.rb:224
if (target_css_file = options[:css_filename])
(rdb:1) n
-# lib/compass/sass_extensions/functions/urls.rb:225
-Pathname.new(path).relative_path_from(Pathname.new(File.dirname(target_css_file))).to_s
-(rdb:1) p path
-"/Users/krisbulman/code/compass-image-url-example/images"
-(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:106
real_path = if Compass.configuration.images_dir
(rdb:1) p path
@@ -31,22 +26,12 @@
# lib/compass/sass_extensions/functions/urls.rb:111
if http_images_path
(rdb:1) p http_images_path
-"../images"
+nil
(rdb:1) n
-# lib/compass/sass_extensions/functions/urls.rb:112
-http_images_path = "#{http_images_path}/" unless http_images_path[-1..-1] == "/"
-(rdb:1) p http_images_path
-"../images"
-(rdb:1) n
-# lib/compass/sass_extensions/functions/urls.rb:113
-path = "#{http_images_path}#{path}"
-(rdb:1) p path
-"grid-col-numbers.png"
-(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:117
asset_host = if !relative? && Compass.configuration.asset_host
(rdb:1) p http_images_path
-"../images/"
+nil
(rdb:1) n
# lib/compass/sass_extensions/functions/urls.rb:122
if cache_buster.to_bool
@@ -57,4 +42,4 @@
# lib/compass/sass_extensions/functions/urls.rb:126
path = cache_busted_path(path, real_path)
(rdb:1) p path
-"../images/grid-col-numbers.png"
+"grid-col-numbers.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment