mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
fd6f7cd881
commit
7759aacb35
@ -22,8 +22,8 @@ module.exports = function(RED) {
|
|||||||
* Custom Mustache Context capable to resolve message property and node
|
* Custom Mustache Context capable to resolve message property and node
|
||||||
* flow and global context
|
* flow and global context
|
||||||
*/
|
*/
|
||||||
function NodeContext(msg, nodeContext) {
|
function NodeContext(msg, nodeContext,parent) {
|
||||||
this.msgContext = new mustache.Context(msg);
|
this.msgContext = new mustache.Context(msg,parent);
|
||||||
this.nodeContext = nodeContext;
|
this.nodeContext = nodeContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
NodeContext.prototype.lookup = function (name) {
|
NodeContext.prototype.lookup = function (name) {
|
||||||
// try message first:
|
// try message first:
|
||||||
|
try {
|
||||||
var value = this.msgContext.lookup(name);
|
var value = this.msgContext.lookup(name);
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
return value;
|
return value;
|
||||||
@ -49,7 +50,14 @@ module.exports = function(RED) {
|
|||||||
return this.nodeContext.global.get(variableName);
|
return this.nodeContext.global.get(variableName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch(err) {
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeContext.prototype.push = function push (view) {
|
||||||
|
return new NodeContext(view, this.nodeContext,this.msgContext);
|
||||||
|
};
|
||||||
|
|
||||||
function TemplateNode(n) {
|
function TemplateNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
@ -166,6 +166,18 @@ describe('template node', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle block contexts objects', function(done) {
|
||||||
|
var flow = [{id:"n1", type:"template", template: "A{{#payload.A}}{{payload.A}}{{.}}{{/payload.A}}B",wires:[["n2"]]},{id:"n2",type:"helper"}];
|
||||||
|
helper.load(templateNode, flow, function() {
|
||||||
|
var n1 = helper.getNode("n1");
|
||||||
|
var n2 = helper.getNode("n2");
|
||||||
|
n2.on("input", function(msg) {
|
||||||
|
msg.should.have.property('payload','AabcabcB');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
n1.receive({payload:{A:"abc"}});
|
||||||
|
});
|
||||||
|
});
|
||||||
it('should raise error if passed bad template', function(done) {
|
it('should raise error if passed bad template', function(done) {
|
||||||
var flow = [{id:"n1", type:"template", field: "payload", template: "payload={{payload",wires:[["n2"]]},{id:"n2",type:"helper"}];
|
var flow = [{id:"n1", type:"template", field: "payload", template: "payload={{payload",wires:[["n2"]]},{id:"n2",type:"helper"}];
|
||||||
helper.load(templateNode, flow, function() {
|
helper.load(templateNode, flow, function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user