1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Tiny formatting tidy ups.

This commit is contained in:
Dave C-J 2014-05-05 08:58:53 +01:00
parent 7674492819
commit bc1fb3b404
3 changed files with 35 additions and 37 deletions

View File

@ -30,36 +30,36 @@ module.exports = function(RED) {
try { try {
this.script = vm.createScript(functionText); this.script = vm.createScript(functionText);
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { if (msg != null) {
var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context}; var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context};
try { try {
this.script.runInNewContext(sandbox); this.script.runInNewContext(sandbox);
var results = sandbox.results; var results = sandbox.results;
if (results == null) { if (results == null) {
results = []; results = [];
} else if (results.length == null) { } else if (results.length == null) {
results = [results]; results = [results];
} }
if (msg._topic) { if (msg._topic) {
for (var m in results) { for (var m in results) {
if (results[m]) { if (results[m]) {
if (util.isArray(results[m])) { if (util.isArray(results[m])) {
for (var n in results[m]) { for (var n in results[m]) {
results[m][n]._topic = msg._topic; results[m][n]._topic = msg._topic;
}
} else {
results[m]._topic = msg._topic;
} }
} else {
results[m]._topic = msg._topic;
} }
} }
} }
this.send(results);
} catch(err) {
this.error(err);
} }
this.send(results);
} catch(err) {
this.error(err);
} }
}
}); });
} catch(err) { } catch(err) {
this.error(err); this.error(err);

View File

@ -24,18 +24,17 @@ module.exports = function(RED) {
this.name = n.name; this.name = n.name;
this.template = n.template; this.template = n.template;
this.on("input", function(msg) { this.on("input", function(msg) {
if (msg != null) { if (msg != null) {
try { try {
msg.payload = mustache.render(this.template,msg) msg.payload = mustache.render(this.template,msg)
this.send(msg); this.send(msg);
} catch(err) { } catch(err) {
this.error(err.message); this.error(err.message);
}
} }
}
}); });
} }
RED.nodes.registerType("template",TemplateNode); RED.nodes.registerType("template",TemplateNode);
RED.library.register("templates"); RED.library.register("templates");
} }

View File

@ -18,6 +18,5 @@ module.exports = function(RED) {
function CommentNode(n) { function CommentNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }
RED.nodes.registerType("comment",CommentNode); RED.nodes.registerType("comment",CommentNode);
} }