-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsass.gradle
86 lines (69 loc) · 3.09 KB
/
sass.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import javax.script.ScriptEngineManager
task compileSass {
ext.inputDir = project.file('src/main/sass')
ext.outputDir = new File(project.buildDir, 'sass')
ext.cacheLocation = new File(project.buildDir, 'sass-cache')
// see http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html#output_style for options
ext.outputStyle = "expanded"
doLast {
def driverScript = '''
require 'rubygems'
require 'sass'
Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
load_paths << $srcDir.path
end
#module Sass::Script::Functions
# def getDomain(string)
# Sass::Script::String.new("aas");
# end
# declare :getDomain, :args => [:string]
#end
$mappings.each do |src, dst|
if $outputStyle == "compressed"
puts "using compressed stylesheets"
engine = Sass::Engine.for_file(src, {:cache_location => $cacheLocation, :style => :compressed})
elsif $outputStyle == "expanded"
puts "using expanded stylesheets"
engine = Sass::Engine.for_file(src, {:cache_location => $cacheLocation, :style => :expanded})
else
puts "using nested stylesheets"
engine = Sass::Engine.for_file(src, {:cache_location => $cacheLocation, :style => :nested})
end
#engine = Sass::Engine.for_file(src, {:cache_location => $cacheLocation, :style => style})
css = engine.render
File.open(dst, 'w') {|f| f.write(css) }
puts "#{src} -> #{dst}"
end
'''
def mappings = new TreeMap()
inputDir.traverse(preDir: {if (it.isHidden()) return FileVisitResult.SKIP_SUBTREE}) { inputFile ->
if (inputFile.isFile() && (inputFile.name.endsWith('.sass') || inputFile.name.endsWith('.scss'))) {
def outputFile = new File(outputDir, relativePath(inputDir, inputFile) + '.css')
outputFile.parentFile.mkdirs()
mappings.put(inputFile.path, outputFile.path)
}
}
def engine = new ScriptEngineManager().getEngineByName("jruby")
engine.put("cacheLocation", cacheLocation.path)
engine.put("mappings", mappings)
engine.put("srcDir",inputDir)
engine.put("outputStyle",outputStyle)
engine.eval(driverScript)
}
}
String relativePath(File root, File descendant) {
def rootPath = root.absolutePath
def descendantPath = descendant.absolutePath
assert descendantPath.startsWith(rootPath)
return descendantPath.substring(rootPath.length() + 1)
}
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'org.jruby', name: 'jruby-complete', version: '1.6.7.2'
classpath group: 'me.n4u.sass', name: 'sass-gems', version: '3.2.1'
}
}