35

我已经搜索和搜索,我只能看到将指南针与 rails 3.1 一起使用只是像这样编辑 Gemfile:

gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'
gem 'sass-rails', "~> 3.1.0.rc"

是的,我明白这一点,但接下来呢?我看到的每个教程都这么说,使用那个特定的叉子。但是我仍然无法将指南针与 rails 3.1 一起使用。

我这样做了:

$ compass init rails . --syntax sass
  directory ./app/stylesheets/ 
  create ./config/compass.rb 
  create ./app/stylesheets/screen.sass 
  create ./app/stylesheets/print.sass 
  create ./app/stylesheets/ie.sass

由于 3.1 现在使用资产,我只是将所有这些文件转移到 3.1。另外,我正在使用 compass-960 插件,那么我在哪里需要它?我尝试使用 require 960 和 require html5-boilerplate 添加一个 compass.rb ,但我仍然不断收到错误:

Error compiling asset application.css:
NoMethodError: undefined method `Error' for Compass:Module
  (in /Users/eumir/rails_apps/kiseki/app/assets/stylesheets/screen.sass)

NoMethodError (undefined method `Error' for Compass:Module
(in /Users/eumir/rails_apps/kiseki/app/assets/stylesheets/screen.sass)):

我试着做指南针编译,它给了我这个:

$ compass compile 无需编译。如果你试图开始一个新项目,你已经离开了目录参数。运行“compass -h”以获得帮助。

正如我所说,我已经编辑了我的 compass.rb,所以我仍然对如何处理这个问题感到困惑。有什么帮助吗?

4

4 回答 4

33

更新:似乎有更好的方法!
资料来源:http ://spin.atomicobject.com/2011/07/12/sass-sprockets-compass-with-rails-3-1/

更新 2(2011 年 12 月 2 日):Compass 的创建者 Chris Eppstein 发布了有关如何将 Compass 与 Rails 3.1 集成的 Github Gist:https ://gist.github.com/1184843

我现在更喜欢这种方法而不是我的方法,因为我注意到在使用 livereload 时编译时速度有了很大的提高。


我的方法:(
我现在认为它已被弃用,但在某些情况下它可能有用,所以在这里供参考:)

首先,在您的 Gemfile 中,添加:

gem "compass", "~> 0.12.alpha.0"

并且不要忘记执行

bundle update

然后,在 config/application.rb 中:

config.generators.stylesheet_engine = :sass

将 application.css.scss 重命名为 application.css.sass,或者创建它,并将其内容替换为:

@import compass
@import _blueprint

(如果您想将新的 Rails 3.1 清单代码保留在样式表的开头,则必须将每行开头的 '/* */' 注释替换为 sass-syntax 版本的 '//')

现在,为了测试 compass 和 blueprint mixins 是否工作,将一些代码添加到同一个文件 application.css.sass 中:

@import compass
@import _blueprint
body
  background: black
  +linear-gradient(color-stops(white, black))
  +column(5)

运行你的 Rails 服务器

bundle exec rails server

在浏览器中加载您的应用程序,然后访问http://localhost:3000/assets/application.css

如果一切顺利,您应该会看到编译后的代码。

资源:

http://blog.pixarea.com/2011/07/using-compass-blueprint-semantic-and-sass-syntax-in-rails-3-1/

于 2011-07-15T21:17:27.690 回答
6

最新版本的 Compass v0.12 已弃用其他答案中的解决方案,该版本需要适配器才能与 rails 应用程序一起使用。Compass 作者 Chris Eppstein 已将安装说明放在 github 上:
https

://github.com/compass/compass-rails 此适配器支持 rails 2.3 及更高版本

于 2012-01-31T20:25:25.313 回答
1

来自 compass 用户组的 Peter Gumeson 向我指出了解决此问题的方法:

https://groups.google.com/forum/#!msg/compass-users/mU5HBt8TCIg/2Rt7iSESTSAJ

这是他的信息:

嗨,帮派。这个 github 问题可能会有所帮助。 https://github.com/sporkd/compass-html5-boilerplate/issues/19

我现在几乎在边缘运行所有东西。所以我的 gemfile 看起来像这样:

gem 'rails',     :git => 'git://github.com/rails/rails.git'
gem 'sass-rails', '~> 3.1.0.rc2'
gem 'haml', :git => 'git://github.com/nex3/haml.git'
gem 'haml-rails'
gem "compass", :git => "git://github.com/chriseppstein/compass.git", :tag => "0.12.alpha.0"
gem 'compass-html5', :git => 'git://github.com/sporkd/compass-html5.git'

我现在正在研究轨道发电机,所以应该不会太远。但这至少应该让你继续前进。

彼得

*改变了choonkeat所说的分支

于 2011-07-30T05:45:40.100 回答
0

您可以下载 compass 目录,将其转储到vendor/assets/stylesheets您的目录结构中vendor/assets/stylesheets/compass然后从您的主应用程序样式表中包含所需的 compass mixins@include compass/reset;

于 2011-07-07T23:38:03.907 回答