4

如何在我的 ruby​​ 代码中调用 compass 来编译项目而不调用 shell 命令?

我尝试从Using Compass from Ruby (not shell)中调整解决方案,但没有成功。我的项目结构看起来像

assets/scss               (location of uncompiled project files)
assets/css                (location for compiled css)
assets/compass/config.cfg (the compass config file)

我尝试过这样的事情

fixed_options = {
  :project_path => '/path/to/assets,
  :sass_path => 'scss',
  :css_path => 'css'
}
Compass.add_project_configuration '/path/to/assets/compass/config.rb'
Compass.add_configuration fixed_options, 'custom'
Compass.compiler.run

这有效,但只有当我irb在项目根目录中运行时才这样做/path/to/assets

似乎任何设置都可以根据需要fixed_options覆盖选项config.rb(或者它们被合并,或者有两组选项:我很难说),但是:project_path似乎没有做任何事情,因为指南针似乎只关心关于我运行的目录irb

注意:我一直在尝试使用 in 的输出Compass.compilerirb尝试了解正在发生的事情。

4

1 回答 1

3

注意:这可能不是您想要的答案,因为它涉及 shell,但它可能是您想要的答案,因为它涉及从 shell 运行一次命令然后在资产发生更改时重新编译它们。也许这对你来说就足够了。

我运行指南针的方式是使用Guard文件。

这是我的 Gemfile 的相关部分(我使用的是 OSX):

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem "sass"  # sassy CSS
  gem "coffee-script" # destroy javascript!
  gem "guard" # file watcher with rules
  gem "guard-coffeescript" # regen coffee
  gem "guard-sass", :require => false # auto generate sass
  gem "rb-fsevent"
  gem "growl" # notifications for OSX
end

指南针配置文件:

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "public/css"
sass_dir = "views/stylesheets"
images_dir = "public/images"
javascripts_dir = "public/js"
project_type = :stand_alone
output_style = :compact
line_comments = false
preferred_syntax = "scss"

在 ./Guardfile

# This will generate stuff:

guard 'coffeescript', :input => "coffee", :output => 'app/public/js'

guard 'sass', :input => 'app/views/stylesheets', :output => 'app/public/css', :compass => true, :style => "compressed", :shallow => true

然后我guard start在终端中运行,它会监视文件的更改并在更改时重新编译。我让终端窗口在后台打开,这样我也可以强制重新编译。YMMV。

于 2012-12-30T10:52:14.337 回答