1

我一直在研究 Compass,我看的越多,感觉就越像应该编写 CSS 的方式。作为一个测试用例,我想在我的一个 CakePHP 项目中使用它。不幸的是,我在初始配置时遇到了一些问题。具体来说,将资源放在正确的位置并在编译的 CSS 中正确引用。

我正在我的目录中创建一个:stand_alone项目。/app嗯,这就是我想做的。指南针似乎不喜欢那样。在创建项目时,我已经告诉它将 css、图像和 js 放在哪里,实际上,这些资源确实放在了正确的目录中。不幸的是,因为我没有在 webroot 中创建目录,所以在编译时资源被错误地引用。

我正在app/使用以下命令在我的 CakePHP 目录中创建 Compass 项目:

$ compass -f blueprint --sass-dir sass --css-dir webroot/css/ --images-dir webroot/img/ --javascripts-dir webroot/js/ --output-style compact .

但是,编译后的 CSS 希望将蓝图的showgrid.png图像引用为:

url('/webroot/img/grid.png?1264969358')

我想这是一个非常可预测的结果,但我不知道如何让编译后的 CSS 引用正确的/img/grid.png?whatever路径。这甚至可能吗?我是否被迫直接在我的 webroot 中创建我的 Compass 项目?

谢谢。

更新

我的config.rb文件内容:

# Require any additional compass plugins here.
project_type = :stand_alone
# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "webroot/css"
sass_dir = "sass"
images_dir = "webroot/img"
http_images_path = "/img"
javascripts_dir = "webroot/js"
output_style = :compact
4

2 回答 2

1

运行 Compass v0.10 并使用以下配置:

# Require any additional compass plugins here.
# Set this to the root of your project when deployed:
http_path = "/"
sass_dir = "sass"
css_dir = "webroot/css"
images_dir = "webroot/images"
javascripts_dir = "webroot/js"
http_stylesheets_dir = "css"
http_javascripts_dir = 'js'
http_images_dir = 'images'
# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

提供预期的结果。

Compass v0.10 即将发布,您可以通过以下方式安装它:

(sudo) gem install compass --pre

要使用此配置创建项目:

  1. 创建项目目录
  2. 将配置保存到config.rb项目目录中。
  3. 从您的项目目录中运行命令:compass install blueprint
于 2010-02-02T04:16:43.673 回答
1

Rails 和其他框架在公共 webroot 之外的项目根目录中拥有 sass 文件和配置。一个独立的项目也应该以这种方式正常工作。

image_url()你在引用图像时使用for 吗?

在您的compass.config文件中,您可以设置http_images_path它是否与您的目录路径不同。有关更多详细信息,请参阅 wiki 中的配置页面

于 2010-02-02T00:30:16.953 回答