X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/8464a511c74dff643095ce419659df60b0580b7a..ea72ab1c5af777c4ad75937bda6a5ec6adcd77a3:/src/smartxml/transformations.js diff --git a/src/smartxml/transformations.js b/src/smartxml/transformations.js index 53dc384..772cf75 100644 --- a/src/smartxml/transformations.js +++ b/src/smartxml/transformations.js @@ -5,8 +5,19 @@ define(function(require) { 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 || {}; @@ -19,10 +30,10 @@ toret.createGenericTransformation = function(desc) { Object.defineProperty(transformation.args, key, { get: function() { if(transformation.hasRun) { - console.log('returning via path'); + //console.log('returning via path'); return transformation.document.getNodeByPath(path); } else { - console.log('returning original arg'); + //console.log('returning original arg'); return value; } @@ -64,9 +75,9 @@ toret.createGenericTransformation = function(desc) { // 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); @@ -95,10 +106,11 @@ toret.createContextTransformation = function(desc) { -toret.TransformationStorage = function() {}; +toret.TransformationStorage = function() { + this._transformations = {}; +}; _.extend(toret.TransformationStorage.prototype, { - _transformations: {}, register: function(Transformation) { var list = (this._transformations[Transformation.prototype.name] = this._transformations[Transformation.prototype.name] || []);