如何在ruby代码中使用指南针来编译项目? (不使用系统调用)

如何在我的 ruby代码调用指南针来编译项目而不调用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

这是有效的,但是只有在项目root / path / to / assets中运行irb时才会这样做.

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

注意:我一直在尝试使用irb中Compass.compiler的输出来尝试了解正在发生的事情.

解决方法

注意:这可能不是您想要的答案,因为它涉及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

Compass配置文件

# 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,它将查看文件以进行更改并重新编译更改.我让终端窗口在后台打开,所以我也可以强制重新编译.因人而异.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...