Skip to content

Instantly share code, notes, and snippets.

@mjtko
Created November 6, 2011 20:13
Show Gist options
  • Save mjtko/1343402 to your computer and use it in GitHub Desktop.
Save mjtko/1343402 to your computer and use it in GitHub Desktop.
Initializer to monkey patch in https://github.com/rails/sass-rails/pull/70 before it's accepted upstream
require 'sass/rails/importer'
if defined?(Sass::Rails::VERSION) && Sass::Rails::VERSION[0..3] >= '3.1.'
Rails.logger.warn ' == MONKEY == Patching sass-rails: https://github.com/rails/sass-rails/pull/70'
Rails.logger.warn " == MONKEY == Please remove #{__FILE__} once Sass::Rails upstream has pulled in the fix"
# monkey patch to incorporate https://github.com/rails/sass-rails/pull/70
module Sass
module Rails
class Importer
def resolve(name, base_pathname = nil)
name = Pathname.new(name)
if base_pathname && base_pathname.to_s.size > 0
root = context.pathname.dirname
name = base_pathname.relative_path_from(root).join(name)
end
partial_name = name.dirname.join("_#{name.basename}")
@resolver.resolve(name) || @resolver.resolve(partial_name)
end
end
end
end
end
@mjtko
Copy link
Author

mjtko commented Nov 6, 2011

This monkey patch initializer made available to work round issues such as: thoughtbot/bourbon#26 (comment)

Stick it in #{Rails.root}/config/initializers and your SASS relative path import woes should disappear!

Enjoy. :)

@mjtko
Copy link
Author

mjtko commented Nov 10, 2011

Updated so as not to fall over when Sass::Rails doesn't exist - such as when the app is operating under the production environment!

@mjtko
Copy link
Author

mjtko commented Jan 24, 2012

Updated == '3.1.' to >= '3.1.' as this is still borked in Rails 3.2.0. :-/

@Zaidos
Copy link

Zaidos commented Feb 1, 2012

Was able to get this working in Rails 3.2.1

@mohangk
Copy link

mohangk commented Feb 12, 2012

Hi

Thanks for this monkey-patch.

I have an issue getting it to work when I user the rake task "assets:precompile". This seems to be an issue due to some changes introduced in Rails 3.1.1. Is there someway or somewhere else I can include this monkey patch to ensure that it is called when running the precompile task ?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment