Java的SASS实现? [英] SASS implementation for Java?

查看:20
本文介绍了Java的SASS实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for SASS implementation in Java (could be used with JSP/JSF). For Python I've found CleverCSS, but there is nothing for Java. Anyone heard something about this sort of tool for generating CSS?

推荐答案

使用 ANT:

  1. 下载 JRuby 完整 jar 文件(JRuby 完整 jar 下载页面)
  2. 下载最新的 HAML/SASS 代码(HAML/SASS tarball),然后提取它.把它放在/libs/sass-[VERSION]"
  3. 将以下内容添加到 ant 构建文件中.
  4. 将脚本中的 [VERSION] 替换为 JRuby 和 SASS 的对应版本
  5. 运行ant脚本,编译sass或scss文件!
  1. Download JRuby complete jar file (JRuby Complete jar download page)
  2. Download the latest HAML/SASS code (HAML/SASS tarball), and extract it. Put it in "/libs/sass-[VERSION]"
  3. Add the following to an ant build file.
  4. Replace [VERSION] in the script to the corresponding versions of JRuby and SASS
  5. Run the ant script, and the sass or scss files will be compiled!

<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 插件:

Maven can also do this: Using the antrun plugin:

<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的SASS实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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