Created
September 17, 2010 22:17
-
-
Save mislav/585051 to your computer and use it in GitHub Desktop.
Detect and compensate for Sass / Compass on Heroku
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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