在Ant build.xml中使用Compass编译SASS [英] Compile SASS with Compass in Ant build.xml

查看:105
本文介绍了在Ant build.xml中使用Compass编译SASS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用JRuby和Compass模块在build.xml中编译SASS(* .scss)文件吗?

Does anyone know how to use JRuby and Compass modules to compile SASS (*.scss) files within build.xml?

我能够使用Sass sass独立安装中的:: Exec模块可以通过以下方式从* .scss编译为* .css:

I'm able to use the Sass::Exec module within sass standalone installation to compile from *.scss to *.css in the following manner:

<!-- Compile SCSS files copied to target folder  -->
<property name="stylesheetFolder" location="myproject/stylesheet"/>
<property name="inputFiles" value="${stylesheetFolder}/[^_]*.scss" />
<echo message="Compiling SCSS files from ${stylesheetFolder}..." />
<script language="ruby" classpath="${env.EP_LIB}/jruby/complete/${jruby-complete.build.jar}">
  <![CDATA[
           require $project.getProperty('env.EP_LIB') + '/sass/sass-3.2.9/lib/sass'
           require 'sass/exec'

           files = Dir.glob($project.getProperty('inputFiles'))
           files.each do |file|
             opts = Sass::Exec::Sass.new(["--style", "compressed", "--load-path", File.dirname(file), file, File.join(File.dirname(file), File.basename(file, ".*") + ".css")])
             opts.parse
           end
  ]]>
</script>
<echo message="Done compiling SCSS source files." />

但是,这并没有给我Compass框架的力量。我以独立方式下载了罗盘gem,我想使用Compass Ruby模块之一将Ant Build.xml中的上述代码替换为以下内容:

However, that doesn't give me the power of the Compass framework. I downloaded compass gem as a standalone and I'd like to use one of the Compass Ruby modules to replace the above code in Ant build.xml with something like:

<script language="ruby" classpath="${env.EP_LIB}/jruby/complete/${jruby-complete.build.jar}">
  <![CDATA[
           require $project.getProperty('env.EP_LIB') + '/compass/compass-0.12.2/lib/compass' 
           require 'compass/exec'

           files = Dir.glob($project.getProperty('inputFiles'))
           files.each do |file| 
             opts = Compass::Exec::Compass.new(["--style", "compressed", "--load-path", File.dirname(file), file, File.join(File.dirname(file), File.basename(file, ".*") + ".css")])
             opts.parse
           end
  ]]>
</script>

有人成功做到了吗?

推荐答案

好,我终于付出了很多心血,并且使用了过时的文档。这是对我们有用的方法:

Ok, I got it finally working with a lot of effort and working with out of date documentation. Here is what worked or us:


  1. 下载 jruby-complete-1.7.4.jar (适用于我的工作版本)(来自 http://jruby.org/files/downloads/1.7.4/

  2. C:\jruby\complete> java -jar jruby-complete-1.7.4.jar -S gem install -i ./compass罗盘

  3. C:\jruby\complete> jar uf jruby-complete-1.7.4.jar -C罗盘。

  4. C:\ \jruby\complete> java -jar jruby-complete-1.7.4.jar -S宝石列表

  5. 成功运行以上cmd后,您的 jruby-complete-1.7.4.jar 将被修改。现在它应该包含捆绑的宝石(包括指南针)。

  1. Download jruby-complete-1.7.4.jar (working version for me) (from http://jruby.org/files/downloads/1.7.4/)
  2. C:\jruby\complete>java -jar jruby-complete-1.7.4.jar -S gem install -i ./compass compass
  3. C:\jruby\complete>jar uf jruby-complete-1.7.4.jar -C compass .
  4. C:\jruby\complete>java -jar jruby-complete-1.7.4.jar -S gem list
  5. After successfully running the cmd above, your jruby-complete-1.7.4.jar will be modified. Now it should contain the bundled gems (including Compass). This works with other gems that you want to bundle and use in your Compass project as well.



compile.rb



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



config.rb

http_path = "/"
css_dir = "."
sass_dir = "."
images_dir = "../images"
javascripts_dir = "../js"

output_style = :compressed
line_comments = false



build.xml




build.xml

    <path id="jruby.classpath">
        <fileset dir="${env.LIB}/jruby/complete">
            <include name="${jruby-complete.build.jar}"></include>  
        </fileset>
    </path>

    <java fork="true" failonerror="true" classpathref="jruby.classpath" classname="org.jruby.Main">
        <arg line="${stylesheetFolder}/compass/compile.rb ${rubyCompleteFolder}/compass/gems compile ${stylesheetFolder}"></arg>
    </java>  

以下是帮助我进行Compass和Ant集成的支持文档:

Here is the supporting documentation that helped me with Compass and Ant integration:

  • 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/

我希望这会有所帮助并为您节省很多时间:)

I hope this helps and saves you lots of time :)

这篇关于在Ant build.xml中使用Compass编译SASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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