-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.go
69 lines (57 loc) · 1.19 KB
/
header.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
61
62
63
64
65
66
67
68
69
package libsass
import (
"strconv"
"sync"
"github.com/wellington/go-libsass/libs"
)
func (ctx *Context) SetHeaders(opts libs.SassOptions) {
// Push the headers into the local array
for _, gh := range globalHeaders {
if !ctx.Headers.Has(gh) {
ctx.Headers.Add(gh)
}
}
// Loop through headers creating ImportEntry
entries := make([]libs.ImportEntry, ctx.Headers.Len())
for i, ent := range ctx.Headers.h {
uniquename := "hdr" + strconv.FormatInt(int64(i), 10)
entries[i] = libs.ImportEntry{
// Each entry requires a unique identifier
// https://github.com/sass/libsass/issues/1292
Path: uniquename,
Source: ent.Content,
SrcMap: "",
}
}
libs.BindHeader(opts, entries)
}
type Header struct {
Content string
}
type Headers struct {
sync.RWMutex
h []Header
}
func (h *Headers) Add(s string) {
h.Lock()
defer h.Unlock()
h.h = append(h.h, Header{
Content: s,
})
}
func (h *Headers) Has(s string) bool {
for _, c := range h.h {
if s == c.Content {
return true
}
}
return false
}
func (h *Headers) Len() int {
return len(h.h)
}
var globalHeaders []string
// RegisterHeader fifo
func RegisterHeader(body string) {
globalHeaders = append(globalHeaders, body)
}