-
Notifications
You must be signed in to change notification settings - Fork 1
/
bem-sugar.styl
67 lines (60 loc) · 1.42 KB
/
bem-sugar.styl
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
// -----------------------------------------------------------------------------
// bem-sugar.styl --- Bem mixins for stylus language
//
// Copyright (c) 2017 Ilya Obuhov
//
// Author: Ilya Obuhov <iobuhov.mail@gmail.com>
// URL: https://github.com/iobuhov/stylus-bem-sugar
e-prefix ?= '__'
m-prefix ?= '--'
m-delimiter ?= '_'
group-store = ()
str()
join('', arguments)
b(name)
.{name}
{block}
group()
caller = called-from[0]
level = length(called-from) + 1
elements = group-store[level]
selector = ()
parent = null
{join(',', elements)}
{block}
group-store[level] = null
m(mod, val=null)
val = val && m-delimiter + val
mod = m-prefix + mod
mod = val ? mod + val : mod
caller = called-from[0]
if caller in ('group')
level = length(called-from)
mod = str('&', mod)
if group-store[level] == null
group-store[level] = mod
else
push(group-store[level], mod)
&{mod}
{block}
e(element)
element = e-prefix + element
caller = called-from[0]
gcaller = called-from[1]
if caller in ('group')
level = length(called-from)
if gcaller in ('e' 'm')
element = str('& ^[0]', element)
else
element = str('^[0]', element)
if group-store[level] == null
group-store[level] = element
else
push(group-store[level], element)
else
if caller in ('e' 'm')
& ^[0]{element}
{block}
else
&{element}
{block}