我正在寻找Java中的SASS实现(可与JSP / JSF一起使用)。 对于Python,我已经找到了CleverCSS,但是对于Java没有类似工具生成CSS。 有没有人听说过这种用于生成CSS的工具?
我正在寻找Java中的SASS实现(可与JSP / JSF一起使用)。 对于Python,我已经找到了CleverCSS,但是对于Java没有类似工具生成CSS。 有没有人听说过这种用于生成CSS的工具?
使用ANT:
<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>
require 'libs/sass-[VERSION]/lib/sass'
作为相对路径无法工作,我不得不使用手头的属性来提供绝对路径。所以我使用了 require $project.getProperty('project.root') + '/sass/sass-3.2.9/lib/sass'
。 - L. Holandabuild.xml:171: org.jruby.exceptions.RaiseException: odd number of args for Hash
(我的build.xml的第171行是<script>
标签的开始) - L. Holanda<configuration>
和<execution>
标签的结尾缺少/
字符。我尝试编辑答案,但编辑必须至少为6个字符,所以这是我能做到的最好的。 - MikeZUSS是一种很好的替代LESS和SASS的选择。它与LESS相似。与LESS和SASS不同的是,处理ZUSS文件不需要JavaScript解释器。
声明:我是ZUSS的开发者。我之所以开发它,仅仅是因为我找不到一个简洁的Java解决方案。
有一个项目:http://code.google.com/p/jsass/(不过还处于早期阶段)。
如果你对Less感兴趣,这里有一个可用的Java版本:http://www.asual.com/lesscss/
看起来终于有了一个(可能是在提出这个问题后一段时间开发的)
考虑到SASS必须转换为CSS才能使用,使用分发Ruby SASS的sass2css有什么问题吗?
我知道我来晚了,但这是我在一个使用Ant构建的Java项目中使用SASS的方法:
http://workingonthecoolstuff.blogspot.com/2011/02/using-sass-in-ant-build.html总结一下,我在安装了Ruby和Sass的机器上进行构建,所以只需要使用Ant的“apply”任务调用sass命令/应用程序,并使用包括所有SCSS/SASS文件的文件集。