UNPKG

1.88 kBtext/coffeescriptView Raw
1make_dd = require '../src/view.coffee'
2require 'colors'
3_ = require 'underscore'
4
5util = require 'util'
6clear = ->
7 util.print "\u001b[2J\u001b[0;0H"
8
9class S
10 constructor: (text, color) ->
11 @text = text
12 @color = color
13 @children = []
14
15 addChild: (child) ->
16 @children.push child
17 child.parent = @
18
19 draw: (tab) ->
20 tab = '' unless tab?
21 console.log tab + @text[@color]
22 @children.forEach (child) ->
23 child.draw(tab + ' ')
24
25 setText: (t) ->
26 @text = t
27
28 setColor: (c) ->
29 @color = c
30
31 removeFromParent: () ->
32 @parent.children = _.without @parent.children, @
33 @parent = null
34
35str_dict =
36 string:
37 cons_args: ['text', 'color']
38 cons: (text, color) ->
39 console.log 'cons : ' + text
40 new S(text, color)
41 text: (t) ->
42 console.log 'text : ' + t
43 @setText t
44 color: (c) ->
45 @setColor c
46
47dd = make_dd(str_dict)
48
49template =
50 type: 'string'
51 text: 'hi'
52 color: 'yellow'
53 controller: 'AppCtrl'
54 children: [
55 {
56 type: 'string'
57 text: 'my info'
58 color: 'white'
59 controller: 'MyInfoCtrl'
60 children: [
61 {
62 type: 'string'
63 text: 'name : seo byeong gee'
64 color: 'white'
65 }
66 {
67 type: 'string'
68 text: 'age : 21'
69 color: 'white'
70 }
71 {
72 type: 'string'
73 text: 'company : redduck'
74 color: 'white'
75 }
76 ]
77 }
78 ]
79 repeat:
80 bind: '@item, @i in @list'
81 template:
82 type: 'string'
83 text: '{{@i + " : " + @item}}'
84 color: 'white'
85
86root = null
87
88controllers =
89 AppCtrl: ($scope) ->
90 $scope.list = ['item1', 'item2', 'item3', 'item4', 'item5']
91 setTimeout ->
92 $scope.$apply ->
93 do $scope.list.shift
94 do root.draw
95 , 1000
96
97 setTimeout ->
98 $scope.$apply ->
99 do $scope.list.shift
100 do root.draw
101 , 2000
102 MyInfoCtrl: ($scope) ->
103
104root = dd.make_view template, controllers
105
106do root.draw