I am generally confused about Rails 3.2, Sprockets, and Compass.
-
At the top of this article, it says
*= require directives
, are no longer needed using Sass-Rails, just use@import
instead. The Sass-Rails Github talks about a little about glob@import
feature, but doesn't talk at all about@import
being the new*= require
. Which one or combo 🙁
do I use? -
Having
coderay.css.sass
invendor/assets/stylesheets
and using@import
inapplication.css.sass
will importmy_coderay.css.sass
?
I don't know because I'm using Compass Mixins inmy_coderay.css.sass
(thus putting a@import "compass/css3"
at the top of that file) and I'm getting an error:
"File to import not found or unreadable: compass" -
In this article it talks about configuring Rail's Sass engine to know about the assets path. But I thought Sass-Rails already teaches
@import
where asset path is?Also when I try to include the 31 branch of compass…
gem 'compass', :git => 'git://github.com/chriseppstein/compass.git', :branch => 'rails31'
I get errors…
Using compass (0.12.0.alpha.0.22e2458) from git://github.com/chriseppstein/compass.git (at rails31) /Users/george.norris/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:365:in `initialize': No such file or directory – /Users/george.norris/.rvm/gems/ruby-1.9.2-p180/bundler/gems/gems/compass-0.12.0.alpha.0.22e2458/bin/compass (Errno::ENOENT) -
And finally, if I take
coderay.css.sass
out of vendor/assets and put it in app/assets I don't get the above error. But I getting it's spitting out errors in public/application.css.css (.css.css ???)Syntax error: File to import not found or unreadable: base.
Load paths:
Compass::SpriteImporter
/Users/geonorr/Sites/quasar/public/stylesheets/sass
/Users/geonorr/Sites/quasar/app/assets/stylesheets
/Users/geonorr/.rvm/gems/ruby-1.9.2-p180/gems/compass-0.11.5/frameworks/blueprint/stylesheets
/Users/geonorr/.rvm/gems/ruby-1.9.2-p180/gems/compass-0.11.5/frameworks/compass/stylesheets
on line 3 of /Users/geonorr/Sites/quasar/app/
I am using Rails (3.1.0), Sass (3.1.7), Sass-Rails (3.1.0), Compass (0.11.5)
Thanks for the response. Feel like I am getting closer…
Including Compass Master Branch and getting this error:
gem 'compass', :git => 'git://github.com/chriseppstein/compass', :branch => 'master'
Using compass (0.12.alpha.0.d03d529) from git://github.com/chriseppstein/compass (at master) /Users/gnee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:365:in initialize': No such file or directory - /Users/gnee/.rvm/gems/ruby-1.9.2-p180/bundler/gems/gems/compass-0.12.alpha.0.d03d529/bin/compass (Errno::ENOENT)
open'
from /Users/gnee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:365:in
from /Users/gnee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:365:in shebang'
app_script_text'
from /Users/gnee/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:456:in
Best Answer
*= require comments can be seen as a hacky workaround from the perspective of Sass, because Sass has a dedicated language feature for that: the @import directive. @import tells Sprockets what to do. When you are migrating from a Rails 3.0 project, leave all @import statements as they are. At the moment, the only gotcha is "globbing": How to tell Rails/Sprockets to regard also other Sass files than application.css.s(ac)ss.
Here is the latest Compass installation guide for Rails 3.1. It also tackles the globbing problem.
As it is said in the Rails Guide,
app/assets
,lib/assets
orvendor/assets
directories in your app as well as in your gems/engines are included inRails.application.config.assets.paths
. I verified that +opacity(.5) from the compass/css3 library works as expected if you install compass properly. Which leads us to the next point:The
rails31
branch is merged intomaster
now and version 0.12.alpha has been released that should support Rails 3.1. However, this is version is not yet without bugs. So I recommend to rely on the newest master revision:gem 'compass', git: 'git://github.com/chriseppstein/compass', branch: 'master'
The only bug I am encountering at the moment is a "undefined method nil.[]" Exception when trying to compile statements that create sprites. See this issue. A workaround for that is to set
sass_options = {quite: true}
in yourconfig/compass.rb
Further note: I do not have Sass in my Gemfile any more. I think you can remove that dependency when relying on
sass-rails
.