Sha256: 7139114f279ad8d8d3a08b7f8c0339907f10daf453cdea66b6af855d7f5ca085

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

class WebResourceBundler::CssUrlRewriter
  class << self
    # rewrites a relative path to an absolute path, removing excess "../" and "./"
    # rewrite_relative_path("stylesheets/default/global.css", "../image.gif") => "/stylesheets/image.gif"

    def rewrite_relative_path(source_url, relative_url)
      return relative_url if relative_url.include?('http://')
      File.expand_path(relative_url, File.dirname(source_url))
    end
  
    # rewrite the URL reference paths
    # url(../../../images/active_scaffold/default/add.gif);
    # url(/stylesheets/active_scaffold/default/../../../images/active_scaffold/default/add.gif);
    # url(/stylesheets/active_scaffold/../../images/active_scaffold/default/add.gif);
    # url(/stylesheets/../images/active_scaffold/default/add.gif);
    # url('/images/active_scaffold/default/add.gif');
    def rewrite_content_urls!(filename, content)
      content.gsub!(/url\s*\(['|"]?([^\)'"]+)['|"]?\)/) { "url('#{rewrite_relative_path(filename, $1)}')" }
      content
    end

  end
end 

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
web_resource_bundler-0.0.20 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.19 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.18 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.16 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.15 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.14 lib/web_resource_bundler/content_management/css_url_rewriter.rb
web_resource_bundler-0.0.13 lib/web_resource_bundler/content_management/css_url_rewriter.rb