var doc = this,
existingPropertyNames = _.values(this);
- var getTrans = function(desc, methodName) {
- if(typeof desc === 'function') {
- desc = {impl: desc};
- }
- if(!desc.impl) {
- throw new Error('Got transformation description without implementation.')
- }
- desc.name = desc.name || methodName;
- return desc;
- };
-
['document', 'documentNode'].forEach(function(dstName) {
var dstExtension = extension[dstName];
if(dstExtension) {
if(dstExtension.transformations) {
_.pairs(dstExtension.transformations).forEach(function(pair) {
- var transformation = getTrans(pair[1], pair[0]),
+ var name = pair[0],
+ desc = pair[1],
operation;
operation = {document: 'registerTransformation', documentNode: 'registerNodeTransformation'}[dstName];
- doc[operation](transformations.createContextTransformation(transformation));
-
+ doc[operation](transformations.createContextTransformation(desc, name));
});
}
}
var _ = require('libs/underscore'),
toret = {};
+var getTransDesc = function(desc, name) {
+ if(typeof desc === 'function') {
+ desc = {impl: desc};
+ }
+ if(!desc.impl) {
+ throw new Error('Got transformation description without implementation.')
+ }
+ desc.name = desc.name || name;
+ return desc;
+};
-toret.createGenericTransformation = function(desc) {
+toret.createGenericTransformation = function(desc, name) {
+ desc = getTransDesc(desc, name);
var GenericTransformation = function(document, args) {
this.args = args || {};
// var t = T(doc, {a:1,b:2,c3:3});
-toret.createContextTransformation = function(desc) {
+toret.createContextTransformation = function(desc, name) {
// mozna sie pozbyc przez przeniesienie object/context na koniec argumentow konstruktora generic transformation
- var GenericTransformation = toret.createGenericTransformation(desc);
+ var GenericTransformation = toret.createGenericTransformation(desc, name);
var ContextTransformation = function(document, object, args) {
GenericTransformation.call(this, document, args);
registerExtension: function(extension) {
//debugger;
smartxml.Document.prototype.registerExtension.call(this, extension);
- var doc = this,
- existingPropertyNames = _.values(this);
-
- var getTrans = function(desc, methodName) {
- if(typeof desc === 'function') {
- desc = {impl: desc};
- }
- if(!desc.impl) {
- throw new Error('Got transformation description without implementation.')
- }
- desc.name = desc.name || methodName;
- return desc;
- };
+ var doc = this;
_.pairs(extension.wlxmlClass).forEach(function(pair) {
var className = pair[0],
});
_.pairs(classExtension.transformations || {}).forEach(function(pair) {
- var transformation = getTrans(pair[1], pair[0]);
- doc.registerClassTransformation(transformations.createContextTransformation(transformation), className);
+ var name = pair[0],
+ desc = pair[1];
+ doc.registerClassTransformation(transformations.createContextTransformation(desc, name), className);
});
});