Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing tests.

  • Loading branch information...
commit 3b025dfb0c0c99d05891fd2b2ff35d9940d05e2f 1 parent ece3b6c
@guitsaru guitsaru authored committed
View
4 Rakefile
@@ -23,7 +23,7 @@ desc "Compiles the javascript from Coffeescript to Javascript"
task :compile_scripts do
Dir["coffeescripts/**/*.coffee"].each do |cs|
output = File.dirname(cs).gsub("coffeescripts", "javascripts")
- system "coffee", "-c", "--no-wrap", cs, "-o", output
+ system "coffee", "--no-wrap", "-o", output, "-c", cs
end
end
@@ -39,7 +39,7 @@ task :test => :compile_scripts do
f.write template.result
end
$js_file = nil
- system "coffee", "-c", "--no-wrap", test, "-o", "test-output"
+ system "coffee", "--no-wrap", "-o", "test-output", "-c", test
end
end
View
4 coffeescripts/shuriken.coffee
@@ -36,7 +36,7 @@
current = @
while current?
parts.unshift current.name
- current: current.parent
+ current = current.parent
parts.join "."
base.getNS = (namespace) ->
@@ -44,7 +44,7 @@
currentNS = @
for name in parts
return unless currentNS[name]?
- currentNS: currentNS[name]
+ currentNS = currentNS[name]
currentNS
base.getRootNS = ->
View
80 javascripts/shuriken.js
@@ -1,30 +1,28 @@
-var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
- return function() {
- return func.apply(obj || {}, args ? args.concat(__slice.call(arguments, 0)) : arguments);
- };
+var __slice = Array.prototype.slice, __bind = function(func, context) {
+ return function(){ return func.apply(context, arguments); };
};
(function() {
var Shuriken, base, makeNS, scopedClosure;
- // First off, add our dataAttr extensions.
- (typeof jQuery !== "undefined" && jQuery !== null) ? (function($) {
- var stringToDataKey;
- stringToDataKey = function(key) {
- return ("data-" + key).replace(/_/g, '-');
- };
- $.fn.dataAttr = function(key, value) {
- return this.attr(stringToDataKey(key), value);
- };
- $.fn.removeDataAttr = function(key) {
- return this.removeAttr(stringToDataKey(key));
- };
- $.fn.hasDataAttr = function(key) {
- return this.is(("[" + (stringToDataKey(key)) + "]"));
- };
- $.metaAttr = function(key) {
- return $(("meta[name='" + key + "']")).attr("content");
- };
- return $.metaAttr;
- })(jQuery) : null;
+ if ((typeof jQuery !== "undefined" && jQuery !== null)) {
+ (function($) {
+ var stringToDataKey;
+ stringToDataKey = function(key) {
+ return "data-$key".replace(/_/g, '-');
+ };
+ $.fn.dataAttr = function(key, value) {
+ return this.attr(stringToDataKey(key), value);
+ };
+ $.fn.removeDataAttr = function(key) {
+ return this.removeAttr(stringToDataKey(key));
+ };
+ $.fn.hasDataAttr = function(key) {
+ return this.is("[${stringToDataKey(key)}]");
+ };
+ return ($.metaAttr = function(key) {
+ return $("meta[name='$key']").attr("content");
+ });
+ })(jQuery);
+ };
Shuriken = {
Base: {},
Util: {},
@@ -41,15 +39,13 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
return closure.call(scope, scope);
}
};
- // Base is the prototype for all namespaces.
base = Shuriken.Base;
base.hasChildNamespace = function(child) {
return this.children.push(child);
};
base.toNSName = function() {
var children, current, parts;
- var _a = arguments.length, _b = _a >= 1;
- children = __slice.call(arguments, 0, _a - 0);
+ children = __slice.call(arguments, 0);
parts = children;
current = this;
while ((typeof current !== "undefined" && current !== null)) {
@@ -115,23 +111,21 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
};
base.log = function() {
var args;
- var _a = arguments.length, _b = _a >= 1;
- args = __slice.call(arguments, 0, _a - 0);
- return console.log.apply(console, [("[" + (this.toNSName()) + "]")].concat(args));
+ args = __slice.call(arguments, 0);
+ return console.log.apply(console, ["[${@toNSName()}]"].concat(args));
};
base.debug = function() {
var args;
- var _a = arguments.length, _b = _a >= 1;
- args = __slice.call(arguments, 0, _a - 0);
- return console.log.apply(console, [("[Debug - " + (this.toNSName()) + "]")].concat(args));
+ args = __slice.call(arguments, 0);
+ return console.log.apply(console, ["[Debug - ${@toNSName()}]"].concat(args));
};
base.setupVia = function(f) {
return $(document).ready(__bind(function() {
- var _a;
- if ((typeof (_a = this.autosetup) !== "undefined" && _a !== null)) {
- return scopedClosure(f, this);
- }
- }, this));
+ var _a;
+ if ((typeof (_a = this.autosetup) !== "undefined" && _a !== null)) {
+ return scopedClosure(f, this);
+ }
+ }, this));
};
base.require = function(key, callback) {
var ns, path, script, url;
@@ -139,8 +133,8 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
if ((typeof ns !== "undefined" && ns !== null)) {
return scopedClosure(callback, ns);
} else {
- path = Shuriken.Util.underscoreize(("" + (this.toNSName()) + "." + key));
- url = ("" + (Shuriken.jsPathPrefix) + (path) + ".js" + (Shuriken.jsPathSuffix));
+ path = Shuriken.Util.underscoreize("${@toNSName()}.$key");
+ url = "${Shuriken.jsPathPrefix}${path}.js${Shuriken.jsPathSuffix}";
script = $("<script />", {
type: "text/javascript",
src: url
@@ -152,8 +146,7 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
}
};
base.autosetup = true;
- // Used as a part of the prototype chain.
- Shuriken.Namespace = function() { };
+ Shuriken.Namespace = function() {};
Shuriken.Namespace.prototype = Shuriken.Base;
makeNS = function(name, parent, sharedPrototype) {
var namespace;
@@ -193,6 +186,5 @@ var __slice = Array.prototype.slice, __bind = function(func, obj, args) {
return ns;
};
Shuriken.root = this;
- this['Shuriken'] = Shuriken;
- return this['Shuriken'];
+ return (this['Shuriken'] = Shuriken);
})();
View
14 javascripts/shuriken/mixins.js
@@ -5,14 +5,12 @@ Shuriken.defineExtension(function(baseNS) {
ns.mixins = {};
root.mixins = {};
root.withBase(function(base) {
- base.mixin = function(mixins) {
+ return (base.mixin = function(mixins) {
return ns.mixin(this, mixins);
- };
- return base.mixin;
+ });
});
defineMixin = function(key, mixin) {
- this.mixins[key] = mixin;
- return this.mixins[key];
+ return (this.mixins[key] = mixin);
};
root.defineMixin = defineMixin;
ns.define = defineMixin;
@@ -25,7 +23,6 @@ Shuriken.defineExtension(function(baseNS) {
return root.mixins[mixin];
} else {
return {};
- // unknown mixin, return a blank object.
}
} else {
return mixin;
@@ -41,7 +38,7 @@ Shuriken.defineExtension(function(baseNS) {
return $.extend(scope, mixin);
}
};
- ns.mixin = function(scope, mixins) {
+ return (ns.mixin = function(scope, mixins) {
var _a, _b, _c, mixin;
if (!($.isArray(mixins))) {
mixins = [mixins];
@@ -52,7 +49,6 @@ Shuriken.defineExtension(function(baseNS) {
ns.invokeMixin(scope, ns.lookupMixin(mixin));
}
return true;
- };
- return ns.mixin;
+ });
});
});
View
33 javascripts/shuriken/mixins/callbacks.js
@@ -3,45 +3,38 @@ Shuriken.defineExtension(function(baseNS) {
return baseNS.defineMixin('Callbacks', function(mixin) {
mixin.callbacks = {};
mixin.defineCallback = function(key) {
- this[("on" + key)] = function(callback) {
+ this["on$key"] = function(callback) {
return this.hasCallback(key, callback);
};
- this[("invoke" + key)] = function() {
+ this["invoke$key"] = function() {
var args;
- var _a = arguments.length, _b = _a >= 1;
- args = __slice.call(arguments, 0, _a - 0);
+ args = __slice.call(arguments, 0);
return this.invokeCallbacks.apply(this, [key].concat(args));
};
return true;
};
mixin.hasCallback = function(name, callback) {
- var _a, callbacks;
- callbacks = mixin.callbacks[name] = (typeof (_a = mixin.callbacks[name]) !== "undefined" && _a !== null) ? mixin.callbacks[name] : [];
+ var callbacks;
+ callbacks = mixin.callbacks[name] = (typeof mixin.callbacks[name] !== "undefined" && mixin.callbacks[name] !== null) ? mixin.callbacks[name] : [];
callbacks.push(callback);
return true;
};
mixin.callbacksFor = function(name) {
var existing;
existing = mixin.callbacks[name];
- if ((typeof existing !== "undefined" && existing !== null)) {
- return existing;
- } else {
- return [];
- }
+ return (typeof existing !== "undefined" && existing !== null) ? existing : [];
};
- mixin.invokeCallbacks = function(name) {
- var _c, _d, _e, args, callback;
- var _a = arguments.length, _b = _a >= 2;
- args = __slice.call(arguments, 1, _a - 0);
- _d = mixin.callbacksFor(name);
- for (_c = 0, _e = _d.length; _c < _e; _c++) {
- callback = _d[_c];
+ return (mixin.invokeCallbacks = function(name) {
+ var _a, _b, _c, args, callback;
+ args = __slice.call(arguments, 1);
+ _b = mixin.callbacksFor(name);
+ for (_a = 0, _c = _b.length; _a < _c; _a++) {
+ callback = _b[_a];
if (callback.apply(this, args) === false) {
return false;
}
}
return true;
- };
- return mixin.invokeCallbacks;
+ });
});
});
View
44 tests/basic_namespace_tests.coffee
@@ -1,24 +1,24 @@
jasmine.include '../javascripts/shuriken.js', true
describe 'Shuriken', ->
-
- root: {}
-
+
+ root = {}
+
beforeEach ->
- Shuriken.root: root
-
+ Shuriken.root = root
+
afterEach ->
delete root
- root: {}
- Shuriken.root: root
+ root = {}
+ Shuriken.root = root
describe 'creating a namespace', ->
-
+
it 'should let you create a base namespace', ->
expect(root.MyNamespace).toBeUndefined()
Shuriken.as 'MyNamespace'
expect(root.MyNamespace).toBeDefined()
-
+
it 'should let you define a sub namespace', ->
expect(root.MyNamespace).toBeUndefined()
Shuriken.as 'MyNamespace'
@@ -32,7 +32,7 @@ describe 'Shuriken', ->
expect(root.MyNamespace.X).toBeDefined()
expect(root.MyNamespace.Y).toBeDefined()
expect(root.MyNamespace.Y.Z).toBeDefined()
-
+
it 'should correctly initialize namespaces as Shuriken.Namespace instances', ->
Shuriken.as 'MyNamespace'
root.MyNamespace.withNS 'X', ->
@@ -41,39 +41,39 @@ describe 'Shuriken', ->
expect(root.MyNamespace.X instanceof Shuriken.Namespace).toBeTruthy()
expect(root.MyNamespace.Y instanceof Shuriken.Namespace).toBeTruthy()
expect(root.MyNamespace.Y.Z instanceof Shuriken.Namespace).toBeTruthy()
-
+
describe 'inspecting created namespaces', ->
-
+
beforeEach ->
Shuriken.as 'Doom'
root.Doom.withNS 'A.B.C', ->
root.Doom.withNS 'D', ->
-
+
it 'should return the correct value for the root namespace', ->
expect(root.Doom.toNSName()).toEqual 'Doom'
-
+
it 'should report the correct value for first level namespace names', ->
expect(root.Doom.A.toNSName()).toEqual 'Doom.A'
expect(root.Doom.D.toNSName()).toEqual 'Doom.D'
-
+
it 'should expect deeper nested namespaces to have the correct name', ->
expect(root.Doom.A.B.toNSName()).toEqual 'Doom.A.B'
expect(root.Doom.A.B.C.toNSName()).toEqual 'Doom.A.B.C'
-
+
it 'should correctly report the value of isRoot', ->
expect(root.Doom.isRoot()).toBeTruthy()
expect(root.Doom.A.isRoot()).toBeFalsy()
expect(root.Doom.A.B.isRoot()).toBeFalsy()
expect(root.Doom.A.B.C.isRoot()).toBeFalsy()
expect(root.Doom.D.isRoot()).toBeFalsy()
-
+
it 'should let you easily get the root namespace', ->
expect(root.Doom.getRootNS()).toEqual root.Doom
expect(root.Doom.A.getRootNS()).toEqual root.Doom
expect(root.Doom.A.B.getRootNS()).toEqual root.Doom
expect(root.Doom.A.B.C.getRootNS()).toEqual root.Doom
expect(root.Doom.D.getRootNS()).toEqual root.Doom
-
+
it 'should let you get a nested child namespace', ->
expect(root.Doom.getNS('A')).toEqual root.Doom.A
expect(root.Doom.getNS('A.B')).toEqual root.Doom.A.B
@@ -87,7 +87,7 @@ describe 'Shuriken', ->
expect(root.Doom.getNS('Awesome.Nested')).toBeNull()
expect(root.Doom.getNS('Awesome.Ouch')).toBeNull()
expect(root.Doom.getNS('Awesome.Nested.Rocking')).toBeNull()
-
+
it 'should let you inspect the existence of namespaces', ->
expect(root.Doom.hasNS('A')).toBeTruthy()
expect(root.Doom.hasNS('A.B')).toBeTruthy()
@@ -101,9 +101,9 @@ describe 'Shuriken', ->
expect(root.Doom.hasNS('Awesome.Nested')).toBeFalsy()
expect(root.Doom.hasNS('Awesome.Ouch')).toBeFalsy()
expect(root.Doom.hasNS('Awesome.Nested.Rocking')).toBeFalsy()
-
+
describe 'Shuriken.Util', ->
-
+
it 'should let you underscore a string', ->
expect(Shuriken.Util.underscoreize('A')).toEqual 'a'
expect(Shuriken.Util.underscoreize('A.B')).toEqual 'a/b'
@@ -111,4 +111,4 @@ describe 'Shuriken', ->
expect(Shuriken.Util.underscoreize('NameOf.Doom')).toEqual 'name_of/doom'
expect(Shuriken.Util.underscoreize('Rockin.AndRoll.AndDoom')).toEqual 'rockin/and_roll/and_doom'
expect(Shuriken.Util.underscoreize('RPXNow')).toEqual 'rpx_now'
- expect(Shuriken.Util.underscoreize('BHM.Authentication.RPXNow')).toEqual 'bhm/authentication/rpx_now'
+ expect(Shuriken.Util.underscoreize('BHM.Authentication.RPXNow')).toEqual 'bhm/authentication/rpx_now'
Please sign in to comment.
Something went wrong with that request. Please try again.