/
model.coffee
49 lines (32 loc) · 1.03 KB
/
model.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
module "Binding.Model"
BM = Pathology.Namespace.new("BindingModel")
BM.Model = AS.Model.extend ({delegate, include, def, defs}) ->
@field 'field1'
@field 'field2'
test "paints styles", ->
context = AS.View.new()
content = $("<div>")
model = BM.Model.new()
binding = AS.Binding.Model.new context, model, content
model.field1.set("rgb(34, 34, 34)")
binding.css
"background-color": ["field1"]
binding.paint()
equal content.css("background-color"), "rgb(34, 34, 34)"
model.field1.set("rgb(0, 0, 0)")
equal content.css("background-color"), "rgb(0, 0, 0)"
test "paints attributes", ->
context = AS.View.new()
content = $("<div>")
model = BM.Model.new()
binding = AS.Binding.Model.new context, model, content
binding.attr
"data-property":
fn: (model) -> model.property or "mock-value"
field: ["field1"]
binding.paint()
equal content.data().property, "mock-value"
binding.attr
"data-property2": ["field2"]
model.field2.set("value2")
equal content.attr('data-property2'), "value2"