加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 02:20:01 所属栏目:百科 来源:网络整理
导读:如何在我的 ruby代码中调用指南针来编译项目而不调用shell命令? 我尝试从Using Compass from Ruby (not shell)调整解决方案,但没有成功.我的项目结构看起来像 assets/scss (location of uncompiled project files)assets/css (location for compiled css)as
如何在我的 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,它将查看文件以进行更改并重新编译更改.我让终端窗口在后台打开,所以我也可以强制重新编译.因人而异.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读