Skip to content

Instantly share code, notes, and snippets.

@datenimperator
Created September 28, 2011 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save datenimperator/1247187 to your computer and use it in GitHub Desktop.
Save datenimperator/1247187 to your computer and use it in GitHub Desktop.
# Compass configuration from inside a rails3 engine
require 'compass'
require 'compass/app_integration/rails'
configuration = StringIO.new(<<-CONFIG)
project_type = :rails
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
CONFIG
Compass.reset_configuration!
Compass.add_configuration(configuration, __FILE__)
Compass.configuration.project_path = Rails.root.to_s
Compass.discover_extensions!
Compass.configure_sass_plugin!
if Rails.env.development?
Compass.configuration.on_stylesheet_saved {|filepath| Rails.logger.debug("Compass saved #{filepath}") }
Compass.configuration.on_stylesheet_error {|filepath, message| Rails.logger.error("Compass has error in #{filepath}: #{message}") }
end
Compass.handle_configuration_change!
# Separately, this is how the engine adds its sass templates to the
# `surrounding` Rails.application
class Engine < Rails::Engine
initializer "Add to Sass load path", :after=>"compass.initialize_rails" do
# root is initialized elsewhere and contains a PathName pointing to the engine's root directory
Sass::Plugin.add_template_location(root.join('app', 'stylesheets'), Rails.root.join('public', 'stylesheets', 'engine'))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment