2

导轨 3.0.9。

在 Gemfile 中:

gem 'compass-rails' (1.0.1)
gem 'sass' (3.0.19)
...

group :development, :test do
  gem 'guard' (1.0.3)
  gem 'guard-sass' (0.6.0)
  ...
end

在此配置中,错误是:

ERROR: Sass > Syntax error: File to import not found or unreadable: compass.
              Load paths:
                /var/www/inbox/public
                /var/www/inbox/public/images
                /var/www/inbox/public/images/intro
                ...

(通常我可以看到指南针的路径丢失(即...ruby-1.9.3-p194-perf/gems/compass-0.12.1/frameworks/compass/stylesheets存在),所以不知何故指南针没有被加载,我不知道该怎么做才能让它加载。

当我交易guard-sass错误guard-compass是:

ERROR: Rails.root is nil! (RuntimeError)
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/util.rb:370:in `rails_root'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin/rails.rb:11:in `default_options'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin/configuration.rb:33:in `options'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin/compiler.rb:38:in `initialize'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin.rb:63:in `new'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin.rb:63:in `compiler'
/home/jkl/.rvm/gems/ruby-1.9.3-p194-perf/gems/sass-3.1.19/lib/sass/plugin.rb:120:in `options'
...

guard-livereload每当我更新.sass文件时,我都希望它能够正常工作。

请注意,通常指南针可以正常工作。在页面刷新时,将从 SASS 文件生成新的 CSS。

4

2 回答 2

2

This happens because guard-sass hardcodes SASS import paths only to subdirectories of the current directory (see https://github.com/hawx/guard-sass/blob/ac65c06fb0ea237713197730196d30ac47840bbf/lib/guard/sass.rb#L20 in the latest version 0.6.0) thus importing SASS from Compass is impossible (compass paths are not in the load paths of SASS).

The workaround for that is to override the :load_paths setting. Here's how I do it:

  guard 'sass', 
    :input => 'app/assets/stylesheets', 
    :output => 'public/stylesheets', 
    :load_paths => Dir.glob(File.join(Gem.dir, "gems", "compass*", "frameworks/blueprint/stylesheets")) + Dir.glob(File.join(Gem.dir, "gems", "compass*", "frameworks/compass/stylesheets"))

Or just upgrade to version 0.7+, where the above should be no longer necessary.

于 2012-06-01T08:45:23.363 回答
0

I recently installed guard-sass on my Rails 3.0.9 project and encountered the same issue. The answer Pawel provided did not help me. Then, I realized that I don't need to use guard on my development server, I just need to make sure that it is installed on my local machine when I am working on styles and scripts so my Sass will become CSS and then compressed CSS (Jammit).

What I've done is isolate my guard gems in a group in my Gemfile like:

group :guard do
  gem 'rb-fsevent',   :require => false if RUBY_PLATFORM =~ /darwin/i # Installs fsevent if on a Mac
  gem "sass",         "~> 3.2.1"
  gem 'guard-sass',   "~> 1.0.0"
  gem 'guard-jammit'
end

Then I can start up my rails application in a terminal window, and guard in another terminal.

于 2012-09-07T16:30:42.450 回答