From 85706f85ff8470cde1a116a68a5e5eec4ece9109 Mon Sep 17 00:00:00 2001 From: SamuraiJack Date: Sun, 4 Apr 2010 23:01:08 +0400 Subject: [PATCH] - aliasing Class/Module/Role to Joose.* --- Changes | 14 ++++++++++++++ lib/Joose/Namespace/Manager.js | 11 +++++++---- lib/Task/Joose/Core.js | 11 +++++++---- t/050_helpers.t.js | 24 +++++++++++++++++++++++- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Changes b/Changes index 2be2d403..34df5aec 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,17 @@ +3.007 + + [ENHANCEMENTS] + + - Class/Role/Module in the global scope aliased as Joose.Class/Joose.Role/Joose.Module + - Joose no longer overwrites the Class/Role/Module symbols in global scope (should allow Prototype support) + + + [BUG FIXES] + + - fixed bug, when traits weren't applied to the class with already detached meta + (when the meta already had traits) + + 3.006 Mon, Feb 22, 2010 [ENHANCEMENTS] diff --git a/lib/Joose/Namespace/Manager.js b/lib/Joose/Namespace/Manager.js index 0908beee..e0ce0123 100644 --- a/lib/Joose/Namespace/Manager.js +++ b/lib/Joose/Namespace/Manager.js @@ -182,11 +182,14 @@ Joose.Namespace.Manager = new Joose.Managed.Class('Joose.Namespace.Manager', { register : function (helperName, metaClass, func) { var me = this - if (this.meta.hasMethod(helperName)) - this.globalNs.addProperty(helperName, function () { + if (this.meta.hasMethod(helperName)) { + var helper = function () { return me[helperName].apply(me, arguments) - }) - else { + } + + if (!Joose.top[helperName]) Joose.top[helperName] = helper + if (!Joose[helperName]) Joose[helperName] = helper + } else { var methods = {} methods[helperName] = func || this.getDefaultHelperFor(metaClass) diff --git a/lib/Task/Joose/Core.js b/lib/Task/Joose/Core.js index d75cc20e..fa66a079 100644 --- a/lib/Task/Joose/Core.js +++ b/lib/Task/Joose/Core.js @@ -3146,11 +3146,14 @@ Joose.Namespace.Manager = new Joose.Managed.Class('Joose.Namespace.Manager', { register : function (helperName, metaClass, func) { var me = this - if (this.meta.hasMethod(helperName)) - this.globalNs.addProperty(helperName, function () { + if (this.meta.hasMethod(helperName)) { + var helper = function () { return me[helperName].apply(me, arguments) - }) - else { + } + + if (!Joose.top[helperName]) Joose.top[helperName] = helper + if (!Joose[helperName]) Joose[helperName] = helper + } else { var methods = {} methods[helperName] = func || this.getDefaultHelperFor(metaClass) diff --git a/t/050_helpers.t.js b/t/050_helpers.t.js index 5af1d319..be3489f8 100644 --- a/t/050_helpers.t.js +++ b/t/050_helpers.t.js @@ -1,6 +1,6 @@ StartTest(function (t) { - t.plan(66) + t.plan(68) //================================================================================================================================================================================== t.diag("Modules") @@ -426,6 +426,28 @@ StartTest(function (t) { t.ok(TestProto, "Class with meta Joose.Proto.Class was successfully created via 'Class' helper") + //================================================================================================================================================================================== + t.diag("Class helpers and global scope") + + var customSymbol = CustomSymbol = {} + + Class('Test.Meta', { + isa : Joose.Meta.Class + }) + + Joose.Namespace.Manager.my.register('CustomSymbol', Test.Meta) + + + t.ok(customSymbol == CustomSymbol, "Global symbol wasn't overriden") + + Joose.CustomSymbol('TestClass2', { + methods : { + process : function () { return 'res' } + } + }) + + t.ok(TestClass2.meta instanceof Test.Meta, "Helper for CustomSymbol metaclass was aliased to Joose.CustomSymbol") + //================================================================================================================================================================================== t.diag("Modifying helper - should be the last test(!), as it modifies the 'Class'")