From bc1fb3b4042b812dc4d1a8cf6eab6989d4aa6335 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Mon, 5 May 2014 08:58:53 +0100 Subject: [PATCH] Tiny formatting tidy ups. --- nodes/core/core/80-function.js | 52 +++++++++++++++++----------------- nodes/core/core/80-template.js | 19 ++++++------- nodes/core/core/90-comment.js | 1 - 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/nodes/core/core/80-function.js b/nodes/core/core/80-function.js index 08fbce1f4..28cacb11c 100644 --- a/nodes/core/core/80-function.js +++ b/nodes/core/core/80-function.js @@ -19,7 +19,7 @@ module.exports = function(RED) { var vm = require("vm"); var fs = require('fs'); var fspath = require('path'); - + function FunctionNode(n) { RED.nodes.createNode(this,n); this.name = n.name; @@ -30,42 +30,42 @@ module.exports = function(RED) { try { this.script = vm.createScript(functionText); this.on("input", function(msg) { - if (msg != null) { - var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context}; - try { - this.script.runInNewContext(sandbox); - var results = sandbox.results; - - if (results == null) { - results = []; - } else if (results.length == null) { - results = [results]; - } - if (msg._topic) { - for (var m in results) { - if (results[m]) { - if (util.isArray(results[m])) { - for (var n in results[m]) { - results[m][n]._topic = msg._topic; - } - } else { - results[m]._topic = msg._topic; + if (msg != null) { + var sandbox = {msg:msg,console:console,util:util,Buffer:Buffer,context:this.context}; + try { + this.script.runInNewContext(sandbox); + var results = sandbox.results; + + if (results == null) { + results = []; + } else if (results.length == null) { + results = [results]; + } + if (msg._topic) { + for (var m in results) { + if (results[m]) { + if (util.isArray(results[m])) { + for (var n in results[m]) { + results[m][n]._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) { this.error(err); } } - + RED.nodes.registerType("function",FunctionNode); RED.library.register("functions"); } diff --git a/nodes/core/core/80-template.js b/nodes/core/core/80-template.js index e5939537c..aafb893e4 100644 --- a/nodes/core/core/80-template.js +++ b/nodes/core/core/80-template.js @@ -18,24 +18,23 @@ module.exports = function(RED) { var mustache = require("mustache"); var util = require("util"); var fs = require('fs'); - + function TemplateNode(n) { RED.nodes.createNode(this,n); this.name = n.name; this.template = n.template; this.on("input", function(msg) { - if (msg != null) { - try { - msg.payload = mustache.render(this.template,msg) - this.send(msg); - } catch(err) { - this.error(err.message); - } + if (msg != null) { + try { + msg.payload = mustache.render(this.template,msg) + this.send(msg); + } catch(err) { + this.error(err.message); } + } }); } - + RED.nodes.registerType("template",TemplateNode); - RED.library.register("templates"); } diff --git a/nodes/core/core/90-comment.js b/nodes/core/core/90-comment.js index 2cb5ed75d..759b16207 100644 --- a/nodes/core/core/90-comment.js +++ b/nodes/core/core/90-comment.js @@ -18,6 +18,5 @@ module.exports = function(RED) { function CommentNode(n) { RED.nodes.createNode(this,n); } - RED.nodes.registerType("comment",CommentNode); }