Refactoring extension registration - abstract away object method registration
[fnpeditor.git] / src / wlxml / wlxml.js
index 98d6a10..8d99cde 100644 (file)
@@ -172,6 +172,9 @@ var WLXMLDocument = function(xml, options) {
     this.ElementNodeFactory.prototype.registerTransformation = function(Transformation) {
         return this.transformations.register(Transformation);
     };
+    this.ElementNodeFactory.prototype.registerMethod = function(methodName, method) {
+        this[methodName] = method;
+    };
 
     this.TextNodeFactory = function() {
         smartxml.TextNode.apply(this, arguments);
@@ -181,6 +184,9 @@ var WLXMLDocument = function(xml, options) {
     this.TextNodeFactory.prototype.registerTransformation = function(Transformation) {
         return this.transformations.register(Transformation);
     };
+    this.TextNodeFactory.prototype.registerMethod = function(methodName, method) {
+        this[methodName] = method;
+    };
 
     this.classMethods = {};
     this.classTransformations = {};
@@ -279,6 +285,10 @@ $.extend(WLXMLDocument.prototype, {
         this.trigger('contentSet');
     },
 
+    registerMethod: function(methodName, method) {
+        this[methodName] = method;
+    },
+
     registerTransformation: function(Transformation) {
         return this.transformations.register(Transformation);
     },
@@ -328,7 +338,7 @@ $.extend(WLXMLDocument.prototype, {
                             );
                         }
                         targets.forEach(function(target) {
-                            target[methodName] = method;
+                            target.registerMethod(methodName, method)
                         });
                     });
                 }
@@ -371,7 +381,6 @@ var wlxmlClasses = {
     }
 };
 
-var classMethods = {};
 
 return {
     WLXMLDocumentFromXML: function(xml, options) {
@@ -381,32 +390,7 @@ return {
 
     WLXMLElementNodeFromXML: function(xml) {
         return this.WLXMLDocumentFromXML(xml).root;
-    },
-
-    registerExtension: function(extension) {
-        // @@ depracated
-        if(extension.documentTransformations) {
-            extension.documentTransformations.forEach(function(method) {
-                WLXMLDocument.prototype.transformations.register(transformations.createContextTransformation(method));
-            });
-        }
-
-        _.pairs(extension.classMethods).forEach(function(pair) {
-            var className = pair[0],
-                methods = pair[1];
-            _.pairs(methods).forEach(function(pair) {
-                var methodName = pair[0],
-                    method = pair[1];
-                classMethods[className] = classMethods[className] || {};
-                classMethods[className][methodName] = method;
-            });
-            
-        });
-
-        _.extend(WLXMLDocument.prototype, extension.documentMethods);
-
     }
-
 };
 
 });
\ No newline at end of file