mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow the template node to be treated as plain text
This commit is contained in:
parent
3a97e20bde
commit
bba210e112
@ -1,5 +1,5 @@
|
|||||||
<!--
|
<!--
|
||||||
Copyright 2013, 2015 IBM Corp.
|
Copyright 2013, 2016 IBM Corp.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -24,12 +24,12 @@
|
|||||||
<input type="text" id="node-input-field" placeholder="payload" style="width:250px;">
|
<input type="text" id="node-input-field" placeholder="payload" style="width:250px;">
|
||||||
<input type="hidden" id="node-input-fieldType">
|
<input type="hidden" id="node-input-fieldType">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row" style="margin-bottom: 0px;">
|
<div class="form-row" style="position: relative; margin-bottom: 0px;">
|
||||||
<label for="node-input-template"><i class="fa fa-file-code-o"></i> <span data-i18n="template.label.template"></span></label>
|
<label for="node-input-template"><i class="fa fa-file-code-o"></i> <span data-i18n="template.label.template"></span></label>
|
||||||
<input type="hidden" id="node-input-template" autofocus="autofocus">
|
<input type="hidden" id="node-input-template" autofocus="autofocus">
|
||||||
<div style="float:right;margin-bottom: 3px; font-size: 0.8em;">
|
<div style="position: absolute; right:0;display:inline-block; text-align: right; font-size: 0.8em;">
|
||||||
<span data-i18n="template.label.format"></span>:
|
<span data-i18n="template.label.format"></span>:
|
||||||
<select id="node-input-format" style=" height: 20px; font-size: 1em !important; width:110px;">
|
<select id="node-input-format" style="width:110px; font-size: 10px !important; height: 24px; padding:0;">
|
||||||
<option value="handlebars">mustache</option>
|
<option value="handlebars">mustache</option>
|
||||||
<option value="html">HTML</option>
|
<option value="html">HTML</option>
|
||||||
<option value="json">JSON</option>
|
<option value="json">JSON</option>
|
||||||
@ -41,6 +41,13 @@
|
|||||||
<div class="form-row node-text-editor-row">
|
<div class="form-row node-text-editor-row">
|
||||||
<div style="height: 250px;" class="node-text-editor" id="node-input-template-editor" ></div>
|
<div style="height: 250px;" class="node-text-editor" id="node-input-template-editor" ></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-syntax"><i class="fa fa-code"></i> <span data-i18n="template.label.syntax"></span></label>
|
||||||
|
<select id="node-input-syntax" style="width:180px;">
|
||||||
|
<option value="mustache" data-i18n="template.label.mustache"></option>
|
||||||
|
<option value="plain" data-i18n="template.label.plain"></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="template">
|
<script type="text/x-red" data-help-name="template">
|
||||||
@ -69,6 +76,7 @@
|
|||||||
field: {value:"payload"},
|
field: {value:"payload"},
|
||||||
fieldType: {value:"msg"},
|
fieldType: {value:"msg"},
|
||||||
format: {value:"handlebars"},
|
format: {value:"handlebars"},
|
||||||
|
syntax: {value:"mustache"},
|
||||||
template: {value:"This is the payload: {{payload}} !"},
|
template: {value:"This is the payload: {{payload}} !"},
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -82,6 +90,10 @@
|
|||||||
if (!this.fieldType) {
|
if (!this.fieldType) {
|
||||||
this.fieldType = 'msg';
|
this.fieldType = 'msg';
|
||||||
}
|
}
|
||||||
|
if (!this.syntax) {
|
||||||
|
this.syntax = 'mustache';
|
||||||
|
$("#node-input-syntax").val(this.syntax);
|
||||||
|
}
|
||||||
$("#node-input-field").typedInput({
|
$("#node-input-field").typedInput({
|
||||||
default: 'msg',
|
default: 'msg',
|
||||||
types: ['msg','flow','global'],
|
types: ['msg','flow','global'],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright 2013 IBM Corp.
|
* Copyright 2013, 2016 IBM Corp.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -23,12 +23,18 @@ module.exports = function(RED) {
|
|||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.field = n.field || "payload";
|
this.field = n.field || "payload";
|
||||||
this.template = n.template;
|
this.template = n.template;
|
||||||
|
this.syntax = n.syntax || "mustache";
|
||||||
this.fieldType = n.fieldType || "msg";
|
this.fieldType = n.fieldType || "msg";
|
||||||
|
|
||||||
var node = this;
|
var node = this;
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
try {
|
try {
|
||||||
var value = mustache.render(node.template,msg);
|
var value;
|
||||||
|
if (node.syntax === "mustache") {
|
||||||
|
value = mustache.render(node.template,msg);
|
||||||
|
} else {
|
||||||
|
value = node.template;
|
||||||
|
}
|
||||||
if (node.fieldType === 'msg') {
|
if (node.fieldType === 'msg') {
|
||||||
RED.util.setMessageProperty(msg,node.field,value);
|
RED.util.setMessageProperty(msg,node.field,value);
|
||||||
} else if (node.fieldType === 'flow') {
|
} else if (node.fieldType === 'flow') {
|
||||||
|
@ -137,8 +137,11 @@
|
|||||||
"template": {
|
"template": {
|
||||||
"label": {
|
"label": {
|
||||||
"template": "Template",
|
"template": "Template",
|
||||||
"property": "Property",
|
"property": "Set property",
|
||||||
"format": "Syntax Highlight"
|
"format": "Syntax Highlight",
|
||||||
|
"syntax": "Format",
|
||||||
|
"mustache": "Mustache template",
|
||||||
|
"plain": "Plain text"
|
||||||
},
|
},
|
||||||
"templatevalue": "This is the payload: {{payload}} !"
|
"templatevalue": "This is the payload: {{payload}} !"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user