From 6efe31a06610fbf8ed8eb4c8884d31ba4ecc0334 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sun, 24 Aug 2008 12:57:49 -0700 Subject: [PATCH] Merb support --- Manifest | 1 + compass.gemspec | 2 ++ lib/compass.rb | 3 +++ lib/compass/merb.rb | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 lib/compass/merb.rb diff --git a/Manifest b/Manifest index dab925f1..8830520a 100644 --- a/Manifest +++ b/Manifest @@ -68,6 +68,7 @@ lib/compass/exec.rb lib/compass/frameworks/blueprint.rb lib/compass/frameworks/compass.rb lib/compass/frameworks.rb +lib/compass/merb.rb lib/compass/validate/COPYRIGHT.html lib/compass/validate/css-validator-javadoc.jar lib/compass/validate/css-validator.jar diff --git a/compass.gemspec b/compass.gemspec index 3f46880e..99eb6525 100644 --- a/compass.gemspec +++ b/compass.gemspec @@ -54,6 +54,7 @@ extra_rdoc_files: - lib/compass/frameworks/blueprint.rb - lib/compass/frameworks/compass.rb - lib/compass/frameworks.rb +- lib/compass/merb.rb - lib/compass/validate/COPYRIGHT.html - lib/compass/validate/css-validator-javadoc.jar - lib/compass/validate/css-validator.jar @@ -138,6 +139,7 @@ files: - lib/compass/frameworks/blueprint.rb - lib/compass/frameworks/compass.rb - lib/compass/frameworks.rb +- lib/compass/merb.rb - lib/compass/validate/COPYRIGHT.html - lib/compass/validate/css-validator-javadoc.jar - lib/compass/validate/css-validator.jar diff --git a/lib/compass.rb b/lib/compass.rb index bd8eac47..285afdc8 100644 --- a/lib/compass.rb +++ b/lib/compass.rb @@ -11,3 +11,6 @@ module Compass end require File.join(File.dirname(__FILE__), 'compass', 'frameworks') +# make sure we're running inside Merb +require File.join(File.dirname(__FILE__), 'compass', 'merb') if defined?(Merb::Plugins) + diff --git a/lib/compass/merb.rb b/lib/compass/merb.rb new file mode 100644 index 00000000..2a721b3b --- /dev/null +++ b/lib/compass/merb.rb @@ -0,0 +1,43 @@ +# To configure Merb to use compass do the following: +# Merb::BootLoader.after_app_loads do +# require 'merb-haml' +# require 'compass' +# end +# +# To use a different sass stylesheets locations as is recommended by compass +# add this configuration to your configuration block: +# +# Merb::Config.use do |c| +# c[:compass] = { +# :stylesheets => 'app/stylesheets', +# :compiled_stylesheets => 'public/stylesheets/compiled' +# } +# end + +Merb::BootLoader.after_app_loads do + #set up sass if haml load didn't do it -- this happens when using a non-default stylesheet location. + unless defined?(Sass::Plugin) + require "sass/plugin" + Sass::Plugin.options = Merb::Config[:sass] if Merb::Config[:sass] + end + + # default the compass configuration if they didn't set it up yet. + Merb::Config[:compass] ||= {} + + # default sass stylesheet location unless configured to something else + Merb::Config[:compass][:stylesheets] ||= Merb.dir_for(:stylesheet) / "sass" + + # default sass css location unless configured to something else + Merb::Config[:compass][:compiled_stylesheets] ||= Merb.dir_for(:stylesheet) + + #define the template hash for the project stylesheets as well as the framework stylesheets. + template_location = { + Merb::Config[:compass][:stylesheets] => Merb::Config[:compass][:compiled_stylesheets] + } + Compass::Frameworks::ALL.each do |framework| + template_location[framework.stylesheets_directory] = File.join(Merb::Config[:compass][:compiled_stylesheets], framework.name) + end + + #configure Sass to know about all these sass locations. + Sass::Plugin.options[:template_location] = template_location +end