多个目录中的指南针源 [英] Compass Source in Multiple Directories

查看:82
本文介绍了多个目录中的指南针源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否已成功在多个目录中编译SASS?您可以设置指南针来递归地查看目录吗?

Have you had success compiling SASS in multiple directories? Can you set up compass to recursively watch a directory?

我已经阅读了add_import_path上的文档,但是我真的很喜欢一些示例代码(我相当

I have read the documentation on add_import_path, but I would really appreciate some sample code, as I have (I am fairly certain) never written a line of ruby code.

我问的原因是,我有几个项目共享一些标准的scss。我希望对共享的scss进行更改以将其级联到所有项目。

The reason I ask is that I have several projects that share some standard scss. I would like changes to the shared scss to cascade to all projects.

谢谢。

推荐答案

这是我的解决方案,它支持基于两个Ruby脚本的批处理指南针编译/监视多个独立的SASS项目。

Here is my solution that supports batch compass compile/watch of multiple independent SASS projects, based on two Ruby scripts.

带有Ruby文件的文件夹结构:

Folder structure with the Ruby files:

Root
--compile.rb
--watch.rb
--Module1
----config.rb
----css
----sass
--Module2
----config.rb
----css
----sass
--Module3
----config.rb
----css
----sass

运行 compile.rb watch.rb ,其中几个参数表示包含 config.rb 文件的模块文件夹的路径。

Run compile.rb and watch.rb with several arguments representing the paths to your module folders containing the config.rb files.

即: ruby​​ compile.rb Module1 / Module2 / Module3 /

require 'rubygems'
require 'compass'
require 'compass/exec'

ARGV.each do |arg|
  Compass::Exec::SubCommandUI.new(["compile", arg, "--force"]).run!
end

即: ruby​​ watch.rb Module1 / Module2 / Module3 /

require 'rubygems'
require 'compass'
require 'compass/exec'

threads = []
ARGV.each do |arg|
  threads << Thread.new {
    Compass::Exec::SubCommandUI.new(["watch", arg, "--force"]).run!
  }
  sleep(1)
end
threads.each { |thr| thr.join }

请注意,我们需要为每个指南针手表创建一个单独的线程(因为它们是阻止程序)。 sleep(1)是必需的,因为 Compass :: Exec :: SubCommandUI 实际上不是线程安全的,可能会运行多个监视同一模块,而不是每个模块。如果发生这种情况,请尝试增加 sleep 的值。

Notice that we need to create a separate thread for each compass watch (since they are blocking processes). sleep(1) is necessary because Compass::Exec::SubCommandUI is not actually thread-safe and might run several watches on the same module, instead of one on each. In case that happens, try increasing the sleep value.

创建类似的配置。所有模块中的rb 文件。您可能必须使用 compass init 来获取指南针可以识别的第一个 config.rb

Create a similar config.rb file in all modules. You might have to use compass init to get the a first config.rb that compass recognizes.

http_path = "/"
css_dir = "css"
sass_dir = "sass"

这篇关于多个目录中的指南针源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆