fnp
/
fnpeditor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
moving wlxml object api transformations directly into .object properties name space
[fnpeditor.git]
/
src
/
smartxml
/
transformations.js
diff --git
a/src/smartxml/transformations.js
b/src/smartxml/transformations.js
index
8cf0819
..
eaa292c
100644
(file)
--- a/
src/smartxml/transformations.js
+++ b/
src/smartxml/transformations.js
@@
-5,8
+5,18
@@
define(function(require) {
var _ = require('libs/underscore'),
toret = {};
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.')
+ }
+ return desc;
+};
-toret.createGenericTransformation = function(desc) {
+toret.createGenericTransformation = function(desc, name) {
+ desc = getTransDesc(desc);
var GenericTransformation = function(document, args) {
this.args = args || {};
var GenericTransformation = function(document, args) {
this.args = args || {};
@@
-19,10
+29,10
@@
toret.createGenericTransformation = function(desc) {
Object.defineProperty(transformation.args, key, {
get: function() {
if(transformation.hasRun) {
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 {
return transformation.document.getNodeByPath(path);
} else {
- console.log('returning original arg');
+
//
console.log('returning original arg');
return value;
}
return value;
}
@@
-37,7
+47,7
@@
toret.createGenericTransformation = function(desc) {
}
};
_.extend(GenericTransformation.prototype, {
}
};
_.extend(GenericTransformation.prototype, {
- name:
desc.
name,
+ name: name,
run: function() {
var changeRoot;
if(!desc.undo) {
run: function() {
var changeRoot;
if(!desc.undo) {
@@
-64,9
+74,9
@@
toret.createGenericTransformation = function(desc) {
// var t = T(doc, {a:1,b:2,c3:3});
// 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
// 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);
var ContextTransformation = function(document, object, args) {
GenericTransformation.call(this, document, args);