shuriken 0.1.4 → 0.2.1
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/Rakefile +2 -2
- data/coffeescripts/shuriken.coffee +71 -72
- data/coffeescripts/shuriken/mixins.coffee +12 -12
- data/coffeescripts/shuriken/mixins/callbacks.coffee +9 -9
- data/javascripts/shuriken.js +34 -42
- data/javascripts/shuriken/mixins.js +5 -9
- data/javascripts/shuriken/mixins/callbacks.js +13 -20
- data/lib/shuriken.rb +1 -1
- data/shuriken.gemspec +2 -2
- data/tests/basic_namespace_tests.coffee +22 -22
- metadata +4 -4
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@ desc "Compiles the javascript from Coffeescript to Javascript"
|
|
23
23
|
task :compile_scripts do
|
24
24
|
Dir["coffeescripts/**/*.coffee"].each do |cs|
|
25
25
|
output = File.dirname(cs).gsub("coffeescripts", "javascripts")
|
26
|
-
system "coffee", "-
|
26
|
+
system "coffee", "--no-wrap", "-o", output, "-c", cs
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -39,7 +39,7 @@ task :test => :compile_scripts do
|
|
39
39
|
f.write template.result
|
40
40
|
end
|
41
41
|
$js_file = nil
|
42
|
-
system "coffee", "-
|
42
|
+
system "coffee", "--no-wrap", "-o", "test-output", "-c", test
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -1,133 +1,132 @@
|
|
1
|
-
(->
|
2
|
-
|
1
|
+
(->
|
2
|
+
|
3
3
|
# First off, add our dataAttr extensions.
|
4
4
|
if jQuery?
|
5
5
|
(($) ->
|
6
|
-
stringToDataKey
|
7
|
-
$.fn.dataAttr
|
8
|
-
$.fn.removeDataAttr
|
9
|
-
$.fn.hasDataAttr
|
10
|
-
$.metaAttr
|
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
11
|
)(jQuery)
|
12
12
|
|
13
13
|
|
14
|
-
Shuriken
|
14
|
+
Shuriken =
|
15
15
|
Base: {}
|
16
16
|
Util: {}
|
17
17
|
jsPathPrefix: "/javascripts/"
|
18
18
|
jsPathSuffix: ""
|
19
19
|
namespaces: {}
|
20
20
|
extensions: []
|
21
|
-
}
|
22
21
|
|
23
|
-
Shuriken.Util.underscoreize
|
22
|
+
Shuriken.Util.underscoreize = (s) ->
|
24
23
|
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()
|
25
24
|
|
26
|
-
scopedClosure
|
25
|
+
scopedClosure = (closure, scope) ->
|
27
26
|
closure.call scope, scope if $.isFunction closure
|
28
|
-
|
27
|
+
|
29
28
|
# Base is the prototype for all namespaces.
|
30
|
-
base
|
29
|
+
base = Shuriken.Base
|
31
30
|
|
32
|
-
base.hasChildNamespace
|
31
|
+
base.hasChildNamespace = (child) ->
|
33
32
|
@children.push child
|
34
|
-
|
35
|
-
base.toNSName
|
36
|
-
parts
|
37
|
-
current
|
33
|
+
|
34
|
+
base.toNSName = (children...) ->
|
35
|
+
parts = children
|
36
|
+
current = @
|
38
37
|
while current?
|
39
38
|
parts.unshift current.name
|
40
|
-
current
|
39
|
+
current = current.parent
|
41
40
|
parts.join "."
|
42
|
-
|
43
|
-
base.getNS
|
44
|
-
parts
|
45
|
-
currentNS
|
41
|
+
|
42
|
+
base.getNS = (namespace) ->
|
43
|
+
parts = namespace.split "."
|
44
|
+
currentNS = @
|
46
45
|
for name in parts
|
47
46
|
return unless currentNS[name]?
|
48
|
-
currentNS
|
47
|
+
currentNS = currentNS[name]
|
49
48
|
currentNS
|
50
|
-
|
51
|
-
base.getRootNS
|
52
|
-
current
|
49
|
+
|
50
|
+
base.getRootNS = ->
|
51
|
+
current = @
|
53
52
|
while current.parent?
|
54
|
-
current
|
53
|
+
current = current.parent
|
55
54
|
current
|
56
55
|
|
57
|
-
base.hasNS
|
56
|
+
base.hasNS = (namespace) ->
|
58
57
|
@getNS(namespace)?
|
59
|
-
|
60
|
-
base.withNS
|
61
|
-
parts
|
62
|
-
currentNS
|
58
|
+
|
59
|
+
base.withNS = (key, initializer) ->
|
60
|
+
parts = key.split "."
|
61
|
+
currentNS = @
|
63
62
|
for name in parts
|
64
|
-
currentNS[name]
|
65
|
-
currentNS
|
66
|
-
hadSetup
|
63
|
+
currentNS[name] = makeNS(name, currentNS, @baseNS) if not currentNS[name]?
|
64
|
+
currentNS = currentNS[name]
|
65
|
+
hadSetup = $.isFunction currentNS.setup
|
67
66
|
scopedClosure initializer, currentNS
|
68
67
|
currentNS.setupVia currentNS.setup if not hadSetup and $.isFunction currentNS.setup
|
69
68
|
currentNS
|
70
69
|
|
71
|
-
base.withBase
|
70
|
+
base.withBase = (closure) ->
|
72
71
|
scopedClosure closure, @baseNS
|
73
|
-
|
74
|
-
base.extend
|
72
|
+
|
73
|
+
base.extend = (closure) ->
|
75
74
|
scopedClosure closure, @
|
76
75
|
|
77
|
-
base.isRoot
|
76
|
+
base.isRoot = ->
|
78
77
|
not @parent?
|
79
|
-
|
80
|
-
base.log
|
81
|
-
console.log "[
|
82
|
-
|
83
|
-
base.debug
|
84
|
-
console.log "[Debug
|
85
|
-
|
86
|
-
base.setupVia
|
78
|
+
|
79
|
+
base.log = (args...) ->
|
80
|
+
console.log "[#{@toNSName()}]", args...
|
81
|
+
|
82
|
+
base.debug = (args...) ->
|
83
|
+
console.log "[Debug: #{@toNSName()}]", args...
|
84
|
+
|
85
|
+
base.setupVia = (f) ->
|
87
86
|
$(document).ready => scopedClosure(f, @) if @autosetup?
|
88
|
-
|
89
|
-
base.require
|
90
|
-
ns
|
87
|
+
|
88
|
+
base.require = (key, callback) ->
|
89
|
+
ns = @getNS key
|
91
90
|
if ns?
|
92
91
|
scopedClosure callback, ns
|
93
92
|
else
|
94
|
-
path
|
95
|
-
url
|
96
|
-
script
|
93
|
+
path = Shuriken.Util.underscoreize "#{@toNSName()}.#{key}"
|
94
|
+
url = "#{Shuriken.jsPathPrefix}#{path}.js#{Shuriken.jsPathSuffix}"
|
95
|
+
script = $ "<script />", type: "text/javascript", src: url
|
97
96
|
script.load -> scopedClosure callback, @getNS(key)
|
98
97
|
script.appendTo $ "head"
|
99
98
|
|
100
|
-
base.autosetup
|
99
|
+
base.autosetup = true
|
101
100
|
|
102
101
|
# Used as a part of the prototype chain.
|
103
|
-
Shuriken.Namespace
|
104
|
-
Shuriken.Namespace.prototype
|
102
|
+
Shuriken.Namespace = ->
|
103
|
+
Shuriken.Namespace.prototype = Shuriken.Base
|
105
104
|
|
106
|
-
makeNS
|
105
|
+
makeNS = (name, parent, sharedPrototype) ->
|
107
106
|
sharedPrototype?= new Shuriken.Namespace()
|
108
|
-
namespace
|
109
|
-
@name
|
110
|
-
@parent
|
111
|
-
@baseNS
|
112
|
-
@children
|
107
|
+
namespace = ->
|
108
|
+
@name = name
|
109
|
+
@parent = parent
|
110
|
+
@baseNS = sharedPrototype
|
111
|
+
@children = []
|
113
112
|
parent.hasChildNamespace(@) if parent?
|
114
113
|
@
|
115
|
-
namespace.prototype
|
114
|
+
namespace.prototype = sharedPrototype
|
116
115
|
new namespace name, parent
|
117
116
|
|
118
|
-
Shuriken.defineExtension
|
117
|
+
Shuriken.defineExtension = (closure) ->
|
119
118
|
for namespace in Shuriken.namespaces
|
120
119
|
scopedClosure closure, namespace
|
121
120
|
Shuriken.extensions.push closure
|
122
121
|
|
123
|
-
Shuriken.as
|
124
|
-
ns
|
125
|
-
Shuriken.namespaces[name]
|
126
|
-
Shuriken.root[name]
|
122
|
+
Shuriken.as = (name) ->
|
123
|
+
ns = makeNS name
|
124
|
+
Shuriken.namespaces[name] = ns
|
125
|
+
Shuriken.root[name] = ns
|
127
126
|
scopedClosure extension, ns for extension in Shuriken.extensions
|
128
127
|
ns
|
129
128
|
|
130
|
-
Shuriken.root
|
131
|
-
@['Shuriken']
|
132
|
-
|
129
|
+
Shuriken.root = @
|
130
|
+
@['Shuriken'] = Shuriken
|
131
|
+
|
133
132
|
)()
|
@@ -1,20 +1,20 @@
|
|
1
1
|
Shuriken.defineExtension (baseNS) ->
|
2
2
|
baseNS.withNS 'Mixins', (ns) ->
|
3
3
|
|
4
|
-
root
|
5
|
-
ns.mixins
|
6
|
-
root.mixins
|
4
|
+
root = @getRootNS()
|
5
|
+
ns.mixins = {}
|
6
|
+
root.mixins = {}
|
7
7
|
|
8
8
|
root.withBase (base) ->
|
9
|
-
base.mixin
|
9
|
+
base.mixin = (mixins) -> ns.mixin @, mixins
|
10
10
|
|
11
|
-
defineMixin
|
12
|
-
@mixins[key]
|
11
|
+
defineMixin = (key, mixin) ->
|
12
|
+
@mixins[key] = mixin
|
13
13
|
|
14
|
-
root.defineMixin
|
15
|
-
ns.define
|
14
|
+
root.defineMixin = defineMixin
|
15
|
+
ns.define = defineMixin
|
16
16
|
|
17
|
-
ns.lookupMixin
|
17
|
+
ns.lookupMixin = (mixin) ->
|
18
18
|
switch typeof mixin
|
19
19
|
when "string"
|
20
20
|
if ns.mixins[mixin]?
|
@@ -26,7 +26,7 @@ Shuriken.defineExtension (baseNS) ->
|
|
26
26
|
else
|
27
27
|
mixin
|
28
28
|
|
29
|
-
ns.invokeMixin
|
29
|
+
ns.invokeMixin = (scope, mixin) ->
|
30
30
|
switch typeof mixin
|
31
31
|
when "string"
|
32
32
|
ns.invokeMixin scope, ns.lookupMixin(mixin)
|
@@ -35,7 +35,7 @@ Shuriken.defineExtension (baseNS) ->
|
|
35
35
|
when "object"
|
36
36
|
$.extend scope, mixin
|
37
37
|
|
38
|
-
ns.mixin
|
39
|
-
mixins
|
38
|
+
ns.mixin = (scope, mixins) ->
|
39
|
+
mixins = [mixins] unless $.isArray mixins
|
40
40
|
ns.invokeMixin scope, ns.lookupMixin(mixin) for mixin in mixins
|
41
41
|
true
|
@@ -1,23 +1,23 @@
|
|
1
1
|
Shuriken.defineExtension (baseNS) ->
|
2
2
|
baseNS.defineMixin 'Callbacks', (mixin) ->
|
3
3
|
|
4
|
-
mixin.callbacks
|
4
|
+
mixin.callbacks = {}
|
5
5
|
|
6
|
-
mixin.defineCallback
|
7
|
-
@["on
|
8
|
-
@["invoke
|
6
|
+
mixin.defineCallback = (key) ->
|
7
|
+
@["on#{key}"] = (callback) -> @hasCallback key, callback
|
8
|
+
@["invoke#{key}"] = (args...) -> @invokeCallbacks key, args...
|
9
9
|
true
|
10
10
|
|
11
|
-
mixin.hasCallback
|
12
|
-
callbacks
|
11
|
+
mixin.hasCallback = (name, callback) ->
|
12
|
+
callbacks = mixin.callbacks[name]?= []
|
13
13
|
callbacks.push callback
|
14
14
|
true
|
15
15
|
|
16
|
-
mixin.callbacksFor
|
17
|
-
existing
|
16
|
+
mixin.callbacksFor = (name) ->
|
17
|
+
existing = mixin.callbacks[name]
|
18
18
|
if existing? then existing else []
|
19
19
|
|
20
|
-
mixin.invokeCallbacks
|
20
|
+
mixin.invokeCallbacks = (name, args...) ->
|
21
21
|
for callback in mixin.callbacksFor(name)
|
22
22
|
return false if callback(args...) is false
|
23
23
|
true
|
data/javascripts/shuriken.js
CHANGED
@@ -1,30 +1,28 @@
|
|
1
|
-
var __slice = Array.prototype.slice, __bind = function(func,
|
2
|
-
return function()
|
3
|
-
return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
|
4
|
-
};
|
1
|
+
var __slice = Array.prototype.slice, __bind = function(func, context) {
|
2
|
+
return function(){ return func.apply(context, arguments); };
|
5
3
|
};
|
6
4
|
(function() {
|
7
5
|
var Shuriken, base, makeNS, scopedClosure;
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
6
|
+
if ((typeof jQuery !== "undefined" && jQuery !== null)) {
|
7
|
+
(function($) {
|
8
|
+
var stringToDataKey;
|
9
|
+
stringToDataKey = function(key) {
|
10
|
+
return ("data-" + (key)).replace(/_/g, '-');
|
11
|
+
};
|
12
|
+
$.fn.dataAttr = function(key, value) {
|
13
|
+
return this.attr(stringToDataKey(key), value);
|
14
|
+
};
|
15
|
+
$.fn.removeDataAttr = function(key) {
|
16
|
+
return this.removeAttr(stringToDataKey(key));
|
17
|
+
};
|
18
|
+
$.fn.hasDataAttr = function(key) {
|
19
|
+
return this.is(("[" + (stringToDataKey(key)) + "]"));
|
20
|
+
};
|
21
|
+
return ($.metaAttr = function(key) {
|
22
|
+
return $(("meta[name='" + (key) + "']")).attr("content");
|
23
|
+
});
|
24
|
+
})(jQuery);
|
25
|
+
};
|
28
26
|
Shuriken = {
|
29
27
|
Base: {},
|
30
28
|
Util: {},
|
@@ -41,15 +39,13 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
|
|
41
39
|
return closure.call(scope, scope);
|
42
40
|
}
|
43
41
|
};
|
44
|
-
// Base is the prototype for all namespaces.
|
45
42
|
base = Shuriken.Base;
|
46
43
|
base.hasChildNamespace = function(child) {
|
47
44
|
return this.children.push(child);
|
48
45
|
};
|
49
46
|
base.toNSName = function() {
|
50
47
|
var children, current, parts;
|
51
|
-
|
52
|
-
children = __slice.call(arguments, 0, _a - 0);
|
48
|
+
children = __slice.call(arguments, 0);
|
53
49
|
parts = children;
|
54
50
|
current = this;
|
55
51
|
while ((typeof current !== "undefined" && current !== null)) {
|
@@ -115,23 +111,21 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
|
|
115
111
|
};
|
116
112
|
base.log = function() {
|
117
113
|
var args;
|
118
|
-
|
119
|
-
args = __slice.call(arguments, 0, _a - 0);
|
114
|
+
args = __slice.call(arguments, 0);
|
120
115
|
return console.log.apply(console, [("[" + (this.toNSName()) + "]")].concat(args));
|
121
116
|
};
|
122
117
|
base.debug = function() {
|
123
118
|
var args;
|
124
|
-
|
125
|
-
|
126
|
-
return console.log.apply(console, [("[Debug - " + (this.toNSName()) + "]")].concat(args));
|
119
|
+
args = __slice.call(arguments, 0);
|
120
|
+
return console.log.apply(console, [("[Debug: " + (this.toNSName()) + "]")].concat(args));
|
127
121
|
};
|
128
122
|
base.setupVia = function(f) {
|
129
123
|
return $(document).ready(__bind(function() {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
124
|
+
var _a;
|
125
|
+
if ((typeof (_a = this.autosetup) !== "undefined" && _a !== null)) {
|
126
|
+
return scopedClosure(f, this);
|
127
|
+
}
|
128
|
+
}, this));
|
135
129
|
};
|
136
130
|
base.require = function(key, callback) {
|
137
131
|
var ns, path, script, url;
|
@@ -139,7 +133,7 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
|
|
139
133
|
if ((typeof ns !== "undefined" && ns !== null)) {
|
140
134
|
return scopedClosure(callback, ns);
|
141
135
|
} else {
|
142
|
-
path = Shuriken.Util.underscoreize(("" + (this.toNSName()) + "." + key));
|
136
|
+
path = Shuriken.Util.underscoreize(("" + (this.toNSName()) + "." + (key)));
|
143
137
|
url = ("" + (Shuriken.jsPathPrefix) + (path) + ".js" + (Shuriken.jsPathSuffix));
|
144
138
|
script = $("<script />", {
|
145
139
|
type: "text/javascript",
|
@@ -152,8 +146,7 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
|
|
152
146
|
}
|
153
147
|
};
|
154
148
|
base.autosetup = true;
|
155
|
-
|
156
|
-
Shuriken.Namespace = function() { };
|
149
|
+
Shuriken.Namespace = function() {};
|
157
150
|
Shuriken.Namespace.prototype = Shuriken.Base;
|
158
151
|
makeNS = function(name, parent, sharedPrototype) {
|
159
152
|
var namespace;
|
@@ -193,6 +186,5 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
|
|
193
186
|
return ns;
|
194
187
|
};
|
195
188
|
Shuriken.root = this;
|
196
|
-
this['Shuriken'] = Shuriken;
|
197
|
-
return this['Shuriken'];
|
189
|
+
return (this['Shuriken'] = Shuriken);
|
198
190
|
})();
|
@@ -5,14 +5,12 @@ Shuriken.defineExtension(function(baseNS) {
|
|
5
5
|
ns.mixins = {};
|
6
6
|
root.mixins = {};
|
7
7
|
root.withBase(function(base) {
|
8
|
-
base.mixin = function(mixins) {
|
8
|
+
return (base.mixin = function(mixins) {
|
9
9
|
return ns.mixin(this, mixins);
|
10
|
-
};
|
11
|
-
return base.mixin;
|
10
|
+
});
|
12
11
|
});
|
13
12
|
defineMixin = function(key, mixin) {
|
14
|
-
this.mixins[key] = mixin;
|
15
|
-
return this.mixins[key];
|
13
|
+
return (this.mixins[key] = mixin);
|
16
14
|
};
|
17
15
|
root.defineMixin = defineMixin;
|
18
16
|
ns.define = defineMixin;
|
@@ -25,7 +23,6 @@ Shuriken.defineExtension(function(baseNS) {
|
|
25
23
|
return root.mixins[mixin];
|
26
24
|
} else {
|
27
25
|
return {};
|
28
|
-
// unknown mixin, return a blank object.
|
29
26
|
}
|
30
27
|
} else {
|
31
28
|
return mixin;
|
@@ -41,7 +38,7 @@ Shuriken.defineExtension(function(baseNS) {
|
|
41
38
|
return $.extend(scope, mixin);
|
42
39
|
}
|
43
40
|
};
|
44
|
-
ns.mixin = function(scope, mixins) {
|
41
|
+
return (ns.mixin = function(scope, mixins) {
|
45
42
|
var _a, _b, _c, mixin;
|
46
43
|
if (!($.isArray(mixins))) {
|
47
44
|
mixins = [mixins];
|
@@ -52,7 +49,6 @@ Shuriken.defineExtension(function(baseNS) {
|
|
52
49
|
ns.invokeMixin(scope, ns.lookupMixin(mixin));
|
53
50
|
}
|
54
51
|
return true;
|
55
|
-
};
|
56
|
-
return ns.mixin;
|
52
|
+
});
|
57
53
|
});
|
58
54
|
});
|
@@ -3,45 +3,38 @@ Shuriken.defineExtension(function(baseNS) {
|
|
3
3
|
return baseNS.defineMixin('Callbacks', function(mixin) {
|
4
4
|
mixin.callbacks = {};
|
5
5
|
mixin.defineCallback = function(key) {
|
6
|
-
this[("on" + key)] = function(callback) {
|
6
|
+
this[("on" + (key))] = function(callback) {
|
7
7
|
return this.hasCallback(key, callback);
|
8
8
|
};
|
9
|
-
this[("invoke" + key)] = function() {
|
9
|
+
this[("invoke" + (key))] = function() {
|
10
10
|
var args;
|
11
|
-
|
12
|
-
args = __slice.call(arguments, 0, _a - 0);
|
11
|
+
args = __slice.call(arguments, 0);
|
13
12
|
return this.invokeCallbacks.apply(this, [key].concat(args));
|
14
13
|
};
|
15
14
|
return true;
|
16
15
|
};
|
17
16
|
mixin.hasCallback = function(name, callback) {
|
18
|
-
var
|
19
|
-
callbacks = mixin.callbacks[name] = (typeof
|
17
|
+
var callbacks;
|
18
|
+
callbacks = mixin.callbacks[name] = (typeof mixin.callbacks[name] !== "undefined" && mixin.callbacks[name] !== null) ? mixin.callbacks[name] : [];
|
20
19
|
callbacks.push(callback);
|
21
20
|
return true;
|
22
21
|
};
|
23
22
|
mixin.callbacksFor = function(name) {
|
24
23
|
var existing;
|
25
24
|
existing = mixin.callbacks[name];
|
26
|
-
|
27
|
-
return existing;
|
28
|
-
} else {
|
29
|
-
return [];
|
30
|
-
}
|
25
|
+
return (typeof existing !== "undefined" && existing !== null) ? existing : [];
|
31
26
|
};
|
32
|
-
mixin.invokeCallbacks = function(name) {
|
33
|
-
var
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
callback = _d[_c];
|
27
|
+
return (mixin.invokeCallbacks = function(name) {
|
28
|
+
var _a, _b, _c, args, callback;
|
29
|
+
args = __slice.call(arguments, 1);
|
30
|
+
_b = mixin.callbacksFor(name);
|
31
|
+
for (_a = 0, _c = _b.length; _a < _c; _a++) {
|
32
|
+
callback = _b[_a];
|
39
33
|
if (callback.apply(this, args) === false) {
|
40
34
|
return false;
|
41
35
|
}
|
42
36
|
}
|
43
37
|
return true;
|
44
|
-
};
|
45
|
-
return mixin.invokeCallbacks;
|
38
|
+
});
|
46
39
|
});
|
47
40
|
});
|
data/lib/shuriken.rb
CHANGED
data/shuriken.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{shuriken}
|
8
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Darcy Laycock"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-21}
|
13
13
|
s.description = %q{Simple Namespace support for JS + Other niceties, packaged as a Barista framework}
|
14
14
|
s.email = %q{sutto@sutto.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,24 +1,24 @@
|
|
1
1
|
jasmine.include '../javascripts/shuriken.js', true
|
2
2
|
|
3
3
|
describe 'Shuriken', ->
|
4
|
-
|
5
|
-
root
|
6
|
-
|
4
|
+
|
5
|
+
root = {}
|
6
|
+
|
7
7
|
beforeEach ->
|
8
|
-
Shuriken.root
|
9
|
-
|
8
|
+
Shuriken.root = root
|
9
|
+
|
10
10
|
afterEach ->
|
11
11
|
delete root
|
12
|
-
root
|
13
|
-
Shuriken.root
|
12
|
+
root = {}
|
13
|
+
Shuriken.root = root
|
14
14
|
|
15
15
|
describe 'creating a namespace', ->
|
16
|
-
|
16
|
+
|
17
17
|
it 'should let you create a base namespace', ->
|
18
18
|
expect(root.MyNamespace).toBeUndefined()
|
19
19
|
Shuriken.as 'MyNamespace'
|
20
20
|
expect(root.MyNamespace).toBeDefined()
|
21
|
-
|
21
|
+
|
22
22
|
it 'should let you define a sub namespace', ->
|
23
23
|
expect(root.MyNamespace).toBeUndefined()
|
24
24
|
Shuriken.as 'MyNamespace'
|
@@ -32,7 +32,7 @@ describe 'Shuriken', ->
|
|
32
32
|
expect(root.MyNamespace.X).toBeDefined()
|
33
33
|
expect(root.MyNamespace.Y).toBeDefined()
|
34
34
|
expect(root.MyNamespace.Y.Z).toBeDefined()
|
35
|
-
|
35
|
+
|
36
36
|
it 'should correctly initialize namespaces as Shuriken.Namespace instances', ->
|
37
37
|
Shuriken.as 'MyNamespace'
|
38
38
|
root.MyNamespace.withNS 'X', ->
|
@@ -41,39 +41,39 @@ describe 'Shuriken', ->
|
|
41
41
|
expect(root.MyNamespace.X instanceof Shuriken.Namespace).toBeTruthy()
|
42
42
|
expect(root.MyNamespace.Y instanceof Shuriken.Namespace).toBeTruthy()
|
43
43
|
expect(root.MyNamespace.Y.Z instanceof Shuriken.Namespace).toBeTruthy()
|
44
|
-
|
44
|
+
|
45
45
|
describe 'inspecting created namespaces', ->
|
46
|
-
|
46
|
+
|
47
47
|
beforeEach ->
|
48
48
|
Shuriken.as 'Doom'
|
49
49
|
root.Doom.withNS 'A.B.C', ->
|
50
50
|
root.Doom.withNS 'D', ->
|
51
|
-
|
51
|
+
|
52
52
|
it 'should return the correct value for the root namespace', ->
|
53
53
|
expect(root.Doom.toNSName()).toEqual 'Doom'
|
54
|
-
|
54
|
+
|
55
55
|
it 'should report the correct value for first level namespace names', ->
|
56
56
|
expect(root.Doom.A.toNSName()).toEqual 'Doom.A'
|
57
57
|
expect(root.Doom.D.toNSName()).toEqual 'Doom.D'
|
58
|
-
|
58
|
+
|
59
59
|
it 'should expect deeper nested namespaces to have the correct name', ->
|
60
60
|
expect(root.Doom.A.B.toNSName()).toEqual 'Doom.A.B'
|
61
61
|
expect(root.Doom.A.B.C.toNSName()).toEqual 'Doom.A.B.C'
|
62
|
-
|
62
|
+
|
63
63
|
it 'should correctly report the value of isRoot', ->
|
64
64
|
expect(root.Doom.isRoot()).toBeTruthy()
|
65
65
|
expect(root.Doom.A.isRoot()).toBeFalsy()
|
66
66
|
expect(root.Doom.A.B.isRoot()).toBeFalsy()
|
67
67
|
expect(root.Doom.A.B.C.isRoot()).toBeFalsy()
|
68
68
|
expect(root.Doom.D.isRoot()).toBeFalsy()
|
69
|
-
|
69
|
+
|
70
70
|
it 'should let you easily get the root namespace', ->
|
71
71
|
expect(root.Doom.getRootNS()).toEqual root.Doom
|
72
72
|
expect(root.Doom.A.getRootNS()).toEqual root.Doom
|
73
73
|
expect(root.Doom.A.B.getRootNS()).toEqual root.Doom
|
74
74
|
expect(root.Doom.A.B.C.getRootNS()).toEqual root.Doom
|
75
75
|
expect(root.Doom.D.getRootNS()).toEqual root.Doom
|
76
|
-
|
76
|
+
|
77
77
|
it 'should let you get a nested child namespace', ->
|
78
78
|
expect(root.Doom.getNS('A')).toEqual root.Doom.A
|
79
79
|
expect(root.Doom.getNS('A.B')).toEqual root.Doom.A.B
|
@@ -87,7 +87,7 @@ describe 'Shuriken', ->
|
|
87
87
|
expect(root.Doom.getNS('Awesome.Nested')).toBeNull()
|
88
88
|
expect(root.Doom.getNS('Awesome.Ouch')).toBeNull()
|
89
89
|
expect(root.Doom.getNS('Awesome.Nested.Rocking')).toBeNull()
|
90
|
-
|
90
|
+
|
91
91
|
it 'should let you inspect the existence of namespaces', ->
|
92
92
|
expect(root.Doom.hasNS('A')).toBeTruthy()
|
93
93
|
expect(root.Doom.hasNS('A.B')).toBeTruthy()
|
@@ -101,9 +101,9 @@ describe 'Shuriken', ->
|
|
101
101
|
expect(root.Doom.hasNS('Awesome.Nested')).toBeFalsy()
|
102
102
|
expect(root.Doom.hasNS('Awesome.Ouch')).toBeFalsy()
|
103
103
|
expect(root.Doom.hasNS('Awesome.Nested.Rocking')).toBeFalsy()
|
104
|
-
|
104
|
+
|
105
105
|
describe 'Shuriken.Util', ->
|
106
|
-
|
106
|
+
|
107
107
|
it 'should let you underscore a string', ->
|
108
108
|
expect(Shuriken.Util.underscoreize('A')).toEqual 'a'
|
109
109
|
expect(Shuriken.Util.underscoreize('A.B')).toEqual 'a/b'
|
@@ -111,4 +111,4 @@ describe 'Shuriken', ->
|
|
111
111
|
expect(Shuriken.Util.underscoreize('NameOf.Doom')).toEqual 'name_of/doom'
|
112
112
|
expect(Shuriken.Util.underscoreize('Rockin.AndRoll.AndDoom')).toEqual 'rockin/and_roll/and_doom'
|
113
113
|
expect(Shuriken.Util.underscoreize('RPXNow')).toEqual 'rpx_now'
|
114
|
-
expect(Shuriken.Util.underscoreize('BHM.Authentication.RPXNow')).toEqual 'bhm/authentication/rpx_now'
|
114
|
+
expect(Shuriken.Util.underscoreize('BHM.Authentication.RPXNow')).toEqual 'bhm/authentication/rpx_now'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shuriken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 2
|
8
9
|
- 1
|
9
|
-
|
10
|
-
version: 0.1.4
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Darcy Laycock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-21 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|