UNPKG

1.81 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 new S(text, color)
40 text: (t) ->
41 @setText t
42 color: (c) ->
43 @setColor c
44
45dd = make_dd(str_dict)
46
47template =
48 type: 'string'
49 text: 'hi'
50 color: 'yellow'
51 controller: 'AppCtrl'
52 children: [
53 {
54 type: 'string'
55 text: 'my info'
56 color: 'white'
57 controller: 'MyInfoCtrl'
58 children: [
59 {
60 type: 'string'
61 text: 'name : seo byeong gee'
62 color: 'white'
63 }
64 {
65 type: 'string'
66 text: 'age : 21'
67 color: 'white'
68 }
69 {
70 type: 'string'
71 text: 'company : redduck'
72 color: 'white'
73 }
74 ]
75 }
76 ]
77 repeat:
78 bind: 'item, i in @list'
79 template:
80 type: 'string'
81 text: '{{@i + " : " + @item}}'
82 color: 'white'
83
84root = null
85
86controllers =
87 AppCtrl: ($scope) ->
88 $scope.list = ['item1', 'item2', 'item3', 'item4', 'item5']
89 setTimeout ->
90 $scope.$apply ->
91 do $scope.list.shift
92 do root.draw
93 , 1000
94
95 setTimeout ->
96 $scope.$apply ->
97 do $scope.list.shift
98 do root.draw
99 , 2000
100 MyInfoCtrl: ($scope) ->
101
102root = dd.make_view template, controllers
103
104do root.draw