/
compile.go
60 lines (43 loc) · 1004 Bytes
/
compile.go
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
package sass
import (
"bytes"
"path/filepath"
"sync"
"github.com/omeid/slurp"
"github.com/ezoic/gosass"
)
func Compile(c *slurp.C) slurp.Stage {
return func(in <-chan slurp.File, out chan<- slurp.File) {
var wg sync.WaitGroup
defer wg.Wait()
for file := range in {
// Skip underscored files like Ruby sass
if string(filepath.Base(file.Path)[0]) == "_" {
continue
}
wg.Add(1)
go func(file slurp.File) {
defer wg.Done()
ctx := gosass.FileContext{
Options: gosass.Options{
OutputStyle: gosass.COMPRESSED_STYLE,
IncludePaths: make([]string, 0),
},
InputPath: file.Path,
OutputString: "",
ErrorStatus: 0,
ErrorMessage: "",
}
gosass.CompileFile(&ctx)
if ctx.ErrorStatus != 0 {
c.Error("Sass error: ", ctx.ErrorMessage)
return
}
buf := bytes.NewBufferString(ctx.OutputString)
file.Reader = buf
file.FileInfo.SetSize(int64(buf.Len()))
out <- file
}(file)
}
}
}