-
Notifications
You must be signed in to change notification settings - Fork 40
/
mixin_invocation.go
72 lines (54 loc) · 1.4 KB
/
mixin_invocation.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
70
71
72
package gcss
import "io"
// mixinInvocation represents a mixin invocation.
type mixinInvocation struct {
elementBase
name string
paramValues []string
}
// WriteTo writes the selector to the writer.
func (mi *mixinInvocation) WriteTo(w io.Writer) (int64, error) {
return 0, nil
}
// decsParams returns the mixin's declarations and params.
func (mi *mixinInvocation) decsParams() ([]*declaration, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.decs, params
}
// selsParams returns the mixin's selectors and params.
func (mi *mixinInvocation) selsParams() ([]*selector, map[string]string) {
md, ok := mi.Context().mixins[mi.name]
if !ok {
return nil, nil
}
params := make(map[string]string)
l := len(mi.paramValues)
for i, name := range md.paramNames {
if i < l {
params[name] = mi.paramValues[i]
}
}
return md.sels, params
}
// newMixinInvocation creates and returns a mixin invocation.
func newMixinInvocation(ln *line, parent element) (*mixinInvocation, error) {
name, paramValues, err := mixinNP(ln, false)
if err != nil {
return nil, err
}
return &mixinInvocation{
elementBase: newElementBase(ln, parent),
name: name,
paramValues: paramValues,
}, nil
}