题
我一直在研究指南针,看的越多,感觉就越像应该写出CSS的方式。作为测试案例,我想在我的CakePHP项目之一中使用它。不幸的是,我在初始配置方面遇到了一些麻烦。具体而言,将资源放在正确的位置并在编译的CSS中正确引用。
我正在创建一个 :stand_alone
我的项目 /app
目录。好吧,那就是我 想 去做。指南针似乎不像那样。在创建项目时,我告诉它在哪里放置CSS,图像和JS以及这些资源确实可以将其变成适当的目录。不幸的是,由于我没有在Webroot中创建目录,因此编译时会错误地引用资源。
我正在我的cakephp中创建指南针项目 app/
带有此命令的目录:
$ 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参考正确的CSS /img/grid.png?whatever
小路。那甚至可能吗?我是否被迫直接在我的Webroot中创建我的指南针项目?
谢谢。
更新
我的内容 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
解决方案
运行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
使用此配置创建一个项目:
- 创建项目目录
- 将配置保存到
config.rb
在项目目录中。 - 从您的项目目录中运行命令:
compass install blueprint
其他提示
Rails和其他框架在公共Webroot之外的项目根中具有SASS文件和配置。一个独立的项目也应该以这种方式工作。
你正在用吗 image_url()
当您引用图像时?
在你的 compass.config
文件您可以设置 http_images_path
如果与您的目录路径不同。看到 配置页面 在Wiki中以获取更多详细信息。
不隶属于 StackOverflow