在Ant build.xml中使用Compass编译SASS
有谁知道如何使用JRuby和Compass模块在build.xml中编译SASS(* .scss)文件?
我可以在sass独立安装中使用Sass :: Exec模块,以下列方式从* .scss编译为* .css:
但是,这并没有给我Compass框架的强大function。 我下载了指南针gem独立,我想使用其中一个Compass Ruby模块用以下内容替换Ant build.xml中的上述代码:
有人做过这个吗?
好吧,我最终付出了很多努力并使用了过时的文档。 这是有用的还是我们:
将gem捆绑成可执行的jar
- 下载
jruby-complete-1.7.4.jar
(我的工作版)(来自http://jruby.org/files/downloads/1.7.4/ ) -
C:\jruby\complete>
java -jar jruby-complete-1.7.4.jar -S gem install -i ./compass compass
-
C:\jruby\complete>
jar uf jruby-complete-1.7.4.jar -C compass .
-
C:\jruby\complete>
java -jar jruby-complete-1.7.4.jar -S gem list
- 成功运行上面的cmd后,您的
jruby-complete-1.7.4.jar
将被修改。 现在它应该包含捆绑的gem(包括指南针)。 这适用于您要在Compass项目中捆绑和使用的其他gem。
compile.rb
Dir.entries(ARGV[0]).each do |lib| $LOAD_PATH.unshift "#{ARGV[0]}/#{lib}/lib" end require 'rubygems' require 'compass' require 'compass/exec' command_line_class = Compass::Exec::SubCommandUI.new([ARGV[1], ARGV[2], "-q"]).run!
config.rb
http_path = "/" css_dir = "." sass_dir = "." images_dir = "../images" javascripts_dir = "../js" output_style = :compressed line_comments = false
build.xml文件
以下是帮助我完成Compass和Ant集成的支持文档:
- http://www.verious.com/tutorial/tutorial-using-compass-and-sass-in-a-java-project/
- http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar/
我希望这有助于节省你很多时间:)
这是我的解决方案,通过在java项目中搜索多个config.rb文件,支持在一个java fork中批量编译多个不同的SASS项目(基于以下答案: https : //stackoverflow.com/a/21051968/6440953 ):
对于表示不同sass项目路径(包含config.rb文件)的每个参数,运行compile命令:
compile.rb
require 'rubygems' require 'compass' require 'compass/exec' ARGV.each do |arg| Compass::Exec::SubCommandUI.new(["compile", arg, "--force"]).run! end
在所有SASS项目路径中创建类似的config.rb文件:
config.rb
http_path = "/" css_dir = "." sass_dir = "." images_dir = "../images" javascripts_dir = "../js" output_style = :compressed line_comments = false
设置ruby-complete jar的路径,里面装有指南针gem(参见https://stackoverflow.com/a/21051968/6440953 )。
搜索Java项目中的所有config.rb文件,并将其路径连接到属性。 将此属性作为参数行发送到执行SASS编译的java fork。
build.xml文件