Skip to content

Instantly share code, notes, and snippets.

@mislav
Created September 17, 2010 22:17
Show Gist options
  • Save mislav/585051 to your computer and use it in GitHub Desktop.
Save mislav/585051 to your computer and use it in GitHub Desktop.
Detect and compensate for Sass / Compass on Heroku
# drop into "initializers" dir
heroku = !!ENV['HEROKU_TYPE']
css_dir = heroku ? 'tmp' : 'public'
location = Rails.root + 'app/styles'
unless Sass::Plugin.template_location_array.any? { |pair| pair.first.to_s == location.to_s }
Sass::Plugin.add_template_location(location, Rails.root + css_dir + 'stylesheets')
end
if heroku
Sass::Plugin.template_location_array.each do |template_location, css_location|
css_location.sub!(%r{/public/stylesheets$}, "/#{css_dir}/stylesheets")
end
# add Rack middleware to serve compiled stylesheets from "tmp/stylesheets"
Rails.configuration.middleware.insert_after 'Sass::Plugin::Rack', 'Rack::Static',
:urls => ['/stylesheets'], :root => "#{Rails.root}/tmp"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment