java - Java的SASS实现?

标签 java maven ant jruby sass

我正在寻找 Java 中的 SASS 实现(可以与 JSP/JSF 一起使用)。对于 Python,我找到了 CleverCSS,但对于 Java 则没有。有人听说过这种用于生成 CSS 的工具吗?

最佳答案

使用 ANT:

  1. 下载JRuby完整的jar文件(JRuby Complete jar download page)
  2. 下载最新的 HAML/SASS 代码 (HAML/SASS tarball),并解压。放入“/libs/sass-[VERSION]”
  3. 将以下内容添加到 ant 构建文件中。
  4. 将脚本中的[VERSION]替换为JRuby和SASS的对应版本
  5. 运行ant脚本,编译sass或scss文件!

<path id="JRuby">
    <fileset file="libs/jruby-complete-[VERSION].jar"/> <!-- Location of JRuby jar file -->
</path>  

<target name="compileSCSS">
    <echo message="Compiling scss files..." />
    <property name="filesIn" value="${dir.css}/scss/**/[^_]*.scss" />
    <property name="fileOutDir" value="/${dir.css}/${dir.css.build}" />
    <script language="ruby" classpathref="JRuby">
        <![CDATA[
            require 'libs/sass-[VERSION]/lib/sass'
            require 'sass/exec'

            files = Dir.glob($project.getProperty('filesIn'))
            Dir.mkdir($project.getProperty('fileOutDir')) unless File.exists?($project.getProperty('fileOutDir'))
            files.each do 
                | file |
                puts "     [sass compiler] " + file + " -> " + $project.getProperty('fileOutDir') + "/" + File.basename(file, ".*") + ".css"
                opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
                opts.parse
            end
        ]]>
    </script>
    <echo message="Done compiling scss files!" />
</target>

使用 MAVEN:

Maven 也可以这样做: 使用antrun插件:

<project>
<build>
<plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <id>compileAndMinify</id>
            <phase>compile</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <mkdir dir="${project.build.directory}/compiled" />

                    <echo message="Compiling scss files..."/>
                    <path id="JRuby">
                        <fileset file="${basedir}/jars/jruby-complete-[VERSION].jar"/>
                    </path>
                    <property name="filesIn" value="${project.build.directory}/css/**/[^_]*.scss" />
                    <property name="fileOutDir" value="${project.build.directory}/compiled/css" />
                    <script language="ruby" classpathref="JRuby">
                        <![CDATA[
                            require 'libs/sass-[VERSION]/lib/sass'
                            require 'sass/exec'

                            files = Dir.glob($project.getProperty('filesIn'))
                            Dir.mkdir($project.getProperty('fileOutDir')) unless File.exists?($project.getProperty('fileOutDir'))
                            files.each do 
                                | file |
                                puts "     [sass compiler] " + file + " -> " + $project.getProperty('fileOutDir') + "/" + File.basename(file, ".*") + ".css"
                                opts = Sass::Exec::Sass.new(["--load-path", File.dirname(file), file, File.join($project.getProperty('fileOutDir'), File.basename(file, ".*") + ".css")])
                                opts.parse
                            end
                        ]]>
                    </script>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
</plugins>
</build>
</project>  

关于java - Java的SASS实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1751479/

相关文章:

java - 部署spring war时Tomcat 6错误

java - 登录自定义 ant 任务

svn ant - 名称未定义

java - Ant :找不到类:javac1.8

java - Payara 5 web.xml 中 PGSimpleDataSource 的自定义属性

java - 解析字符串

java - 导致 Shuffle 的 Spark 转换是什么?

java - MIPS,处理数组和列表(将 Java 代码转换为 MIPS)

java - 依赖项问题 - Eclipse Java 项目

java - Hadoop 构建在 Windows 7、Maven 3.1.1、Jdk 1.7.0_45 上失败(Hadoop src 2.2.0)