-
Notifications
You must be signed in to change notification settings - Fork 2
/
angular-class.coffee
60 lines (42 loc) · 1.21 KB
/
angular-class.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
@IdFly ||= {}
class @IdFly.AngularClass
@factory: () ->
return @_createFactory(() =>
return new this()
)
@classFactory: () ->
console.log('angular-class-coffee: @classFactory is deprecated; use ' +
'@class() instead')
return @class()
@class: () ->
return @_createFactory(() => return (class extends this))
@directive: () ->
return (() =>
object = {}
for key, value of this
if key == '__super__'
continue
object[key] = value
object.controller = @factory()
object.link = ((_scope, element, _attrs, controller) ->
if controller.link
controller.link(element)
)
return object
)
@_createFactory: (resultCallback) ->
imports = this._import || []
factory = () =>
args = Array.prototype.slice.call(arguments)
result = resultCallback()
for name, index in imports
result[@_prepareImportName(name)] = args[index]
if result.initialize != undefined
result.initialize()
return result
return imports.concat([factory])
@_prepareImportName = (name) ->
if name.substr(0, 1) == '$'
name = name.slice(1)
name = '_' + name
return name