A
A
Anton Misyagin2015-08-27 00:16:35
Ruby on Rails
Anton Misyagin, 2015-08-27 00:16:35

Glitch compass, rails project?

The essence of the problem is described in Configure compass paths? . I struggled with the solution continuously, but it never comes. Began to pick source codes of gems. The challenge is to find out why the compass or compass-core or compass-rails or sprockets gem sets a leading slash in front of the sprite path. As it turned out the compass settings:

Compass.configuration.http_generated_images_path = 'sprites'
Compass.configuration.relative_assets = false

they don't affect anything at all. Here's why. I found that place in the gem where the calculation of the url of the sprite in css comes from:
../gems/compass-1.0.3/lib/compass/sass_extensions/functions/sprites.rb
def sprite_url(map)
    puts("мы здесь были")
    verify_map(map, "sprite-url")
    map.generate
    generated_image_url(identifier("#{map.path}-s#{map.uniqueness_hash}.png"))
  end

../gems/compass-core-1.0.3/lib/compass/core/sass_extensions/functions/urls.rb
module GeneratedImageUrl
    def self.included(base)
      if base.respond_to?(:declare)
        base.declare :generated_image_url, [:path]
        base.declare :generated_image_url, [:path, :cache_buster]
      end
    end
    def generated_image_url(path, cache_buster = bool(false))
      path = path.value # get to the string value of the literal.

      if path =~ %r{^#{Regexp.escape(Compass.configuration.http_generated_images_path)}/(.*)}
        # Treat root relative urls (without a protocol) like normal if they start with
        # the generated_images path.
        path = $1
      elsif absolute_path?(path)
        # Short curcuit if they have provided an absolute url.
        return unquoted_string("url(#{path})")
      end

      # Compute the path to the image, either root relative or stylesheet relative
      # or nil if the http_generated_images_path is not set in the configuration.
      http_generated_images_path = if relative?
        compute_relative_path(Compass.configuration.generated_images_path)
      elsif Compass.configuration.http_generated_images_path
        Compass.configuration.http_generated_images_path
      else
        Compass.configuration.http_root_relative(Compass.configuration.generated_images_dir)
      end

      # Compute the real path to the image on the file stystem if the generated_images_dir is set.
      real_path = if Compass.configuration.generated_images_path
        File.join(Compass.configuration.generated_images_path, path.gsub(/#.*$/,""))
      else
        File.join(Compass.configuration.project_path, path.gsub(/#.*$/,""))
      end

      # prepend the path to the image if there's one
      if http_generated_images_path
        http_generated_images_path = "#{http_generated_images_path}/" unless http_generated_images_path[-1..-1] == "/"
        path = "#{http_generated_images_path}#{path}"
      end

      # Compute the asset host unless in relative mode.
      asset_host = if !relative? && Compass.configuration.asset_host
        Compass.configuration.asset_host.call(path)
      end

      # Compute and append the cache buster if there is one.
      if cache_buster.to_bool
        path, anchor = path.split("#", 2)
        if cache_buster.is_a?(Sass::Script::Value::String)
          path += "#{path["?"] ? "&" : "?"}#{cache_buster.value}"
        else
          path = cache_busted_path(path, real_path)
        end
        path = "#{path}#{"#" if anchor}#{anchor}"
      end

      # prepend the asset host if there is one.
      path = "#{asset_host}#{'/' unless path[0..0] == "/"}#{path}" if asset_host

      clean_url(path)
    end
  end

../gems/gems/compass-rails-2.0.5/lib/compass-rails/patches/4_0.rb
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
    cachebust_generated_images(path)
    asset_url(path)
  end

Did you notice 2 identical functions named generated_image_url?
So, if I change the gem sources so that the compass-core gem function is called (I renamed the generated_image_url function in 2 places), then the settings http_generated_images_path, relative_assets start working and everything works out. Hence the question is: Why the hell are there two of them and the wrong one is called))?
I searched the entire Internet, it looks like there is also an incorrect path to images, but everything is solved there by manipulating the assets-path in the css file:
background-image: asset-path (some/some/path). And my compass generates these statements and I don’t see them in sass files, I just include two lines:
@import "sprites/theme/icons/*.png"
@include all-icons-sprites

therefore, it is necessary that this path be correct, being born somewhere in the depths of the compass. Help a little, I'm tired of stomping around in one place ..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Misyagin, 2015-09-07
@sunnmas

../gems/gems/compass-rails-2.0.5/lib/compass-rails/patches/4_0.rb

//def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
//    cachebust_generated_images(path)
//    asset_url(path)
//  end

and I will do the compilation of resources locally, the main thing now is to prescribe everything with versions in the gem file so that you do not accidentally switch to another version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question