shuriken 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/coffeescripts/shuriken.coffee +103 -97
- data/lib/shuriken.rb +1 -1
- data/shuriken.gemspec +1 -1
- metadata +2 -2
@@ -1,104 +1,108 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
(->
|
2
|
+
|
3
|
+
# First off, add our dataAttr extensions.
|
4
|
+
if jQuery?
|
5
|
+
(($) ->
|
6
|
+
stringToDataKey: (key) -> "data-$key".replace /_/g, '-'
|
7
|
+
$.fn.dataAttr: (key, value) -> @attr stringToDataKey(key), value
|
8
|
+
$.fn.removeDataAttr: (key) -> @removeAttr stringToDataKey(key)
|
9
|
+
$.fn.hasDataAttr: (key) -> @is "[${stringToDataKey(key)}]"
|
10
|
+
$.metaAttr: (key) -> $("meta[name='$key']").attr "content"
|
11
|
+
)(jQuery)
|
11
12
|
|
12
|
-
Shuriken: {
|
13
|
-
Base: {}
|
14
|
-
Util: {}
|
15
|
-
jsPathPrefix: "/javascripts/"
|
16
|
-
jsPathSuffix: ""
|
17
|
-
namespaces: {}
|
18
|
-
extensions: []
|
19
|
-
}
|
20
13
|
|
21
|
-
Shuriken
|
22
|
-
|
14
|
+
Shuriken: {
|
15
|
+
Base: {}
|
16
|
+
Util: {}
|
17
|
+
jsPathPrefix: "/javascripts/"
|
18
|
+
jsPathSuffix: ""
|
19
|
+
namespaces: {}
|
20
|
+
extensions: []
|
21
|
+
}
|
23
22
|
|
24
|
-
Shuriken.Util.
|
25
|
-
|
23
|
+
Shuriken.Util.underscoreize: (s) ->
|
24
|
+
s.replace(/\./g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase()
|
26
25
|
|
26
|
+
scopedClosure: (closure, scope) ->
|
27
|
+
closure.call scope, scope if $.isFunction closure
|
27
28
|
|
28
|
-
# Base is the prototype for all namespaces.
|
29
|
-
base: Shuriken.Base
|
29
|
+
# Base is the prototype for all namespaces.
|
30
|
+
base: Shuriken.Base
|
30
31
|
|
31
|
-
base.hasChildNamespace: (child) ->
|
32
|
-
|
32
|
+
base.hasChildNamespace: (child) ->
|
33
|
+
@children.push child
|
33
34
|
|
34
|
-
base.toNSName: (children...) ->
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
base.toNSName: (children...) ->
|
36
|
+
parts: children
|
37
|
+
current: @
|
38
|
+
while current.parent?
|
39
|
+
parts.unshift parts
|
40
|
+
current: current.parent
|
41
|
+
parts.join "."
|
41
42
|
|
42
|
-
base.getNS: (namespace) ->
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
base.getNS: (namespace) ->
|
44
|
+
parts: key.split "."
|
45
|
+
currentNS: @
|
46
|
+
for name in parts
|
47
|
+
return unless currentNS[name]?
|
48
|
+
currentNS: currentNS[name]
|
49
|
+
currentNS
|
49
50
|
|
50
|
-
base.getRootNS: ->
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
base.getRootNS: ->
|
52
|
+
current: @
|
53
|
+
current: current.parent while current.parent?
|
54
|
+
current
|
54
55
|
|
55
|
-
base.hasNS: (namespace) ->
|
56
|
-
|
56
|
+
base.hasNS: (namespace) ->
|
57
|
+
@getNS(namespace)?
|
57
58
|
|
58
|
-
base.withNS: (key, initializer) ->
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
59
|
+
base.withNS: (key, initializer) ->
|
60
|
+
parts: key.split "."
|
61
|
+
currentNS: @
|
62
|
+
for name in parts
|
63
|
+
currentNS[name]: makeNS(name, currentNS, @baseNS) if not currentNS[name]?
|
64
|
+
currentNS: currentNS[name]
|
65
|
+
hadSetup: $.isFunction currentNS.setup
|
66
|
+
scopedClosure initializer, currentNS
|
67
|
+
currentNS.setupVia currentNS.setup if not hadSetup and $.isFunction currentNS.setup
|
68
|
+
currentNS
|
68
69
|
|
69
|
-
base.withBase: (closure) ->
|
70
|
-
|
70
|
+
base.withBase: (closure) ->
|
71
|
+
scopedClosure closure, @baseNS
|
72
|
+
|
73
|
+
base.extend: (closure) ->
|
74
|
+
scopedClosure closure, @
|
71
75
|
|
72
|
-
base.isRoot: ->
|
73
|
-
|
76
|
+
base.isRoot: ->
|
77
|
+
not @parent?
|
74
78
|
|
75
|
-
base.log: (args...) ->
|
76
|
-
|
79
|
+
base.log: (args...) ->
|
80
|
+
console.log "[${@toNSName()}]", args...
|
77
81
|
|
78
|
-
base.debug: (args...) ->
|
79
|
-
|
82
|
+
base.debug: (args...) ->
|
83
|
+
console.log "[Debug - ${@toNSName()}]", args...
|
80
84
|
|
81
|
-
base.setupVia: (f) ->
|
82
|
-
|
85
|
+
base.setupVia: (f) ->
|
86
|
+
$(document).ready => scopedClosure(f, @) if @autosetup?
|
83
87
|
|
84
|
-
base.require: (key, callback) ->
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
base.require: (key, callback) ->
|
89
|
+
ns: @getNS key
|
90
|
+
if ns?
|
91
|
+
scopedClosure callback, ns
|
92
|
+
else
|
93
|
+
path: Shuriken.Util.underscoreize "${@toNSName()}.$key"
|
94
|
+
url: "${Shuriken.jsPathPrefix}${path}.js${Shuriken.jsPathSuffix}"
|
95
|
+
script: $ "<script />", {type: "text/javascript", src: url}
|
96
|
+
script.load -> scopedClosure callback, @getNS(key)
|
97
|
+
script.appendTo $ "head"
|
94
98
|
|
95
|
-
base.autosetup: true
|
99
|
+
base.autosetup: true
|
96
100
|
|
97
|
-
# Used as a part of the prototype chain.
|
98
|
-
Shuriken.Namespace: ->
|
99
|
-
Shuriken.Namespace.prototype: Shuriken.Base
|
101
|
+
# Used as a part of the prototype chain.
|
102
|
+
Shuriken.Namespace: ->
|
103
|
+
Shuriken.Namespace.prototype: Shuriken.Base
|
100
104
|
|
101
|
-
makeNS: (name, parent, sharedPrototype) ->
|
105
|
+
makeNS: (name, parent, sharedPrototype) ->
|
102
106
|
sharedPrototype?= new Shuriken.Namespace()
|
103
107
|
namespace: ->
|
104
108
|
@name: name
|
@@ -107,21 +111,23 @@ makeNS: (name, parent, sharedPrototype) ->
|
|
107
111
|
@children: []
|
108
112
|
parent.hasChildNamespace(@) if parent?
|
109
113
|
@
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
Shuriken.defineExtension: (closure) ->
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
114
|
+
namespace.prototype: sharedPrototype
|
115
|
+
new namespace name, parent
|
116
|
+
|
117
|
+
Shuriken.defineExtension: (closure) ->
|
118
|
+
for namespace in Shuriken.namespaces
|
119
|
+
console.log namespace
|
120
|
+
scopedClosure closure, namespace
|
121
|
+
Shuriken.extensions.push closure
|
118
122
|
|
119
|
-
Shuriken.as: (name) ->
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
123
|
+
Shuriken.as: (name) ->
|
124
|
+
ns: makeNS name
|
125
|
+
Shuriken.namespaces[name]: ns
|
126
|
+
Shuriken.root[name]: ns
|
127
|
+
scopedClosure extension, ns for extension in Shuriken.extensions
|
128
|
+
ns
|
125
129
|
|
126
|
-
Shuriken.root: @
|
127
|
-
@['Shuriken']: Shuriken
|
130
|
+
Shuriken.root: @
|
131
|
+
@['Shuriken']: Shuriken
|
132
|
+
|
133
|
+
)()
|
data/lib/shuriken.rb
CHANGED
data/shuriken.gemspec
CHANGED