-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstyles.coffee
60 lines (57 loc) · 1.48 KB
/
styles.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
48
49
50
51
52
53
54
55
56
57
58
59
60
parseStyleString = (str) ->
result = {}
if str?
for cssprop in str.split(/;(?![^(]*\))/g)
if cssprop?
splitted = cssprop.split /:(.+)/
if splitted.length > 1
result[splitted[0].trim()] = splitted[1].trim()
return result
module.exports =
_name: "styles"
_v: 1
_prio: 700
_mergers: require("./_merger").copy(source: "styles")
mixins: [
require("./style")
require("./combined")
require "./parseElement"
]
connectedCallback: ->
if @_isFirstConnect
@$combined
path: "styles"
value: @styles
parseProp: parseStyleString
normalize: @$style.normalizeObj
cbFactory: (name) ->
el = @$parseElement.byString(name)
return [(val) -> @$style.setNormalized el, val]
test module.exports, {
mixins: [
require("./structure")
require("./props")
]
structure: template(1,"""
<div #ref="someDiv"></div>
""")
data: -> width: "10px"
prop:
style2:
type: String
styles:
this:
computed: -> width: @width
data: -> height: "10px"
prop: "style2"
someDiv:
data: -> height: "20px"
}, (el) ->
it "should work", (done) ->
el.should.have.attr "style", "width: 10px; height: 10px;"
el.someDiv.should.have.attr "style", "height: 20px;"
el.$nextTick ->
el.style2 = "position: absolute"
el.styles.this.height = "20px"
el.should.have.attr "style", "width: 10px; height: 20px; position: absolute;"
done()