-
Notifications
You must be signed in to change notification settings - Fork 1
/
c-if.coffee
47 lines (45 loc) · 1.14 KB
/
c-if.coffee
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
{isFunction} = require("./_helpers")
module.exports =
_name: "c-if"
_v: 1
mixins: [
require "./structure"
require "./if"
]
_elLookup:
cIf:
extract:
"": ["true","false","template","else","not"]
cb: (o, {children}) ->
comment = document.createComment("c-if")
if o?
@$nextTick ->
@$if
value: o.true or o.false
anchor: comment
els: children
template: o.template
elseTemplate: o.else
not: o.not or o.false
return el: comment, options: null
test module.exports, {
mixins: [ require("./structure") ]
structure: template(1,"""
<c-if true=isVisible>
<p>test</p>
</c-if>
<c-if true=isVisible template=template else=elseTemplate>
</c-if>
<c-if true=isVisible>
<template><p>test3</p></template>
</c-if>
""")
data: ->
isVisible: false
template: template(1,"<p>test2</p>")
elseTemplate: template(1,"<p>else</p>")
}, (el) ->
it "should work", ->
el.should.have.text "else"
el.isVisible = true
el.should.have.text "testtest2test3"