diff options
author | Jon Reid | 2012-06-20 15:05:26 -0700 |
---|---|---|
committer | Jon Reid | 2012-06-20 15:05:26 -0700 |
commit | 6e6c146f6e59c3942076b5d2f46b2962cc709926 (patch) | |
tree | aa6becc1e97aecbe6fb43aa33770def3c3de227d /node_modules/montage/core/deserializer.js | |
parent | f887a74a7d03a2008a2c43d455a2b3e9223028af (diff) | |
parent | c9852665eadc1acb9c1c881d207c4bd9ef88805f (diff) | |
download | ninja-6e6c146f6e59c3942076b5d2f46b2962cc709926.tar.gz |
Merge remote-tracking branch 'ninja-internal/master' into timeline-local
Diffstat (limited to 'node_modules/montage/core/deserializer.js')
-rwxr-xr-x | node_modules/montage/core/deserializer.js | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/node_modules/montage/core/deserializer.js b/node_modules/montage/core/deserializer.js index 86cdc560..424a2bc9 100755 --- a/node_modules/montage/core/deserializer.js +++ b/node_modules/montage/core/deserializer.js | |||
@@ -31,7 +31,7 @@ try { | |||
31 | @class module:montage/core/deserializer.Deserializer | 31 | @class module:montage/core/deserializer.Deserializer |
32 | @extends module:montage/core/core.Montage | 32 | @extends module:montage/core/core.Montage |
33 | */ | 33 | */ |
34 | var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deserializer.Deserializer# */ { | 34 | var Deserializer = exports.Deserializer = Montage.create(Montage, /** @lends module:montage/core/deserializer.Deserializer# */ { |
35 | _MONTAGE_ID_ATTRIBUTE: {value: "data-montage-id"}, | 35 | _MONTAGE_ID_ATTRIBUTE: {value: "data-montage-id"}, |
36 | 36 | ||
37 | _objects: {value: null}, | 37 | _objects: {value: null}, |
@@ -533,7 +533,7 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri | |||
533 | var serialization = this._serialization, | 533 | var serialization = this._serialization, |
534 | moduleIds = this._requiredModuleIds = [], | 534 | moduleIds = this._requiredModuleIds = [], |
535 | modules = this._modules, | 535 | modules = this._modules, |
536 | desc, moduleId, name, objectLocation; | 536 | desc, moduleId; |
537 | 537 | ||
538 | for (var label in serialization) { | 538 | for (var label in serialization) { |
539 | desc = serialization[label]; | 539 | desc = serialization[label]; |
@@ -542,16 +542,8 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri | |||
542 | if ("module" in desc) { | 542 | if ("module" in desc) { |
543 | moduleId = desc.module; | 543 | moduleId = desc.module; |
544 | } else if ("prototype" in desc || "object" in desc) { | 544 | } else if ("prototype" in desc || "object" in desc) { |
545 | name = desc.prototype || desc.object | 545 | Deserializer.parseForModuleAndName(desc.prototype || desc.object, desc); |
546 | objectLocation = name.split("["); | 546 | moduleId = desc.module; |
547 | moduleId = objectLocation[0]; | ||
548 | desc.module = moduleId; | ||
549 | if (objectLocation.length == 2) { | ||
550 | desc.name = objectLocation[1].slice(0, -1); | ||
551 | } else { | ||
552 | this._findObjectNameRegExp.test(moduleId); | ||
553 | desc.name = RegExp.$1.replace(this._toCamelCaseRegExp, this._replaceToCamelCase); | ||
554 | } | ||
555 | } | 547 | } |
556 | 548 | ||
557 | if (moduleId && !modules[moduleId] && moduleIds.indexOf(moduleId) == -1) { | 549 | if (moduleId && !modules[moduleId] && moduleIds.indexOf(moduleId) == -1) { |
@@ -559,6 +551,34 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri | |||
559 | } | 551 | } |
560 | } | 552 | } |
561 | }}, | 553 | }}, |
554 | |||
555 | /** | ||
556 | Sets the module loader used during deserialization. | ||
557 | @function | ||
558 | @param {String} name The string representing a module/name pair, such as "my-module[MyModule]". | ||
559 | @param {Object} description The description object on which the parseForModuleAndName will populate the module and name properties. [Optional] | ||
560 | @returns {Object} The description object with module and name properties populated. | ||
561 | */ | ||
562 | parseForModuleAndName: { | ||
563 | value: function(name, desc) { | ||
564 | var bracketIndex; | ||
565 | |||
566 | if (typeof desc === "undefined") { | ||
567 | desc = {}; | ||
568 | } | ||
569 | bracketIndex = name.indexOf("["); | ||
570 | if (bracketIndex > 0) { | ||
571 | desc.module = name.substr(0, bracketIndex); | ||
572 | desc.name = name.slice(bracketIndex+1, -1); | ||
573 | } else { | ||
574 | desc.module = name; | ||
575 | Deserializer._findObjectNameRegExp.test(name); | ||
576 | desc.name = RegExp.$1.replace(Deserializer._toCamelCaseRegExp, Deserializer._replaceToCamelCase); | ||
577 | } | ||
578 | return desc; | ||
579 | } | ||
580 | }, | ||
581 | |||
562 | /** | 582 | /** |
563 | @private | 583 | @private |
564 | */ | 584 | */ |
@@ -680,23 +700,25 @@ var Deserializer = Montage.create(Montage, /** @lends module:montage/core/deseri | |||
680 | hasObject = object != null, | 700 | hasObject = object != null, |
681 | counter, | 701 | counter, |
682 | descString, | 702 | descString, |
683 | objectLocation; | 703 | objectLocation, |
704 | bracketIndex; | ||
684 | 705 | ||
685 | if ("module" in desc) { | 706 | if ("module" in desc) { |
686 | moduleId = desc.module; | 707 | moduleId = desc.module; |
687 | objectName = name = desc.name; | 708 | objectName = name = desc.name; |
688 | } else if ("prototype" in desc || "object" in desc) { | 709 | } else if ("prototype" in desc || "object" in desc) { |
689 | objectLocation = (desc.prototype || desc.object).split("["); | 710 | bracketIndex = (desc.prototype || desc.object).indexOf("["); |
690 | // this code is actually only used when canEval == false, | 711 | // this code is actually only used when canEval == false, |
691 | // module+name are added when the modules are parsed but it's | 712 | // module+name are added when the modules are parsed but it's |
692 | // slow to redo the _serializationString in order to keep the | 713 | // slow to redo the _serializationString in order to keep the |
693 | // added module+name when we do JSON.parse(_serializationString) | 714 | // added module+name when we do JSON.parse(_serializationString) |
694 | // at canEval == false. | 715 | // at canEval == false. |
695 | moduleId = objectLocation[0]; | 716 | if (bracketIndex > 0) { |
696 | if (objectLocation.length == 2) { | 717 | moduleId = name.substr(0, bracketIndex); |
697 | objectName = name = objectLocation[1].slice(0, -1); | 718 | objectName = name = name.slice(bracketIndex+1, -1); |
698 | } else { | 719 | } else { |
699 | self._findObjectNameRegExp.test(moduleId); | 720 | moduleId = name; |
721 | self._findObjectNameRegExp.test(name); | ||
700 | objectName = name = RegExp.$1.replace(self._toCamelCaseRegExp, function(_, g1) { return g1.toUpperCase() }); | 722 | objectName = name = RegExp.$1.replace(self._toCamelCaseRegExp, function(_, g1) { return g1.toUpperCase() }); |
701 | } | 723 | } |
702 | } | 724 | } |
@@ -1142,8 +1164,4 @@ function deserialize(serialization, require, origin) { | |||
1142 | return deferred.promise; | 1164 | return deferred.promise; |
1143 | } | 1165 | } |
1144 | 1166 | ||
1145 | if (typeof exports !== "undefined") { | 1167 | exports.deserialize = deserialize; |
1146 | exports.Deserializer = Deserializer; | ||
1147 | exports.deserialize = deserialize; | ||
1148 | } | ||
1149 | |||