Added parsed YAML support for template node (#1443)

This commit is contained in:
Nathanaël Lécaudé 2017-11-30 08:38:50 -05:00 committed by Nick O'Leary
parent d426aaa88a
commit f09e61a59a
3 changed files with 7 additions and 0 deletions

View File

@ -42,6 +42,7 @@
<select id="node-input-output" style="width:180px;">
<option value="str" data-i18n="template.label.plain"></option>
<option value="json" data-i18n="template.label.json"></option>
<option value="yaml" data-i18n="template.label.yaml"></option>
</select>
</div>

View File

@ -17,6 +17,8 @@
module.exports = function(RED) {
"use strict";
var mustache = require("mustache");
var yaml = require("js-yaml");
/**
* Custom Mustache Context capable to resolve message property and node
@ -80,6 +82,9 @@ module.exports = function(RED) {
if (node.outputFormat === "json") {
value = JSON.parse(value);
}
if (node.outputFormat === "yaml") {
value = yaml.load(value);
}
if (node.fieldType === 'msg') {
RED.util.setMessageProperty(msg,node.field,value);

View File

@ -195,6 +195,7 @@
"mustache": "Mustache template",
"plain": "Plain text",
"json": "Parsed JSON",
"yaml": "Parsed YAML",
"none": "none"
},
"templatevalue": "This is the payload: {{payload}} !"