Add Moustache Template
This commit is contained in:
parent
3905c01a0d
commit
542809d5f5
@ -106,6 +106,7 @@
|
|||||||
"loglevel-message-prefix": "^3.0.0",
|
"loglevel-message-prefix": "^3.0.0",
|
||||||
"moment": "^2.22.2",
|
"moment": "^2.22.2",
|
||||||
"moment-timezone": "^0.5.21",
|
"moment-timezone": "^0.5.21",
|
||||||
|
"mustache": "^2.3.2",
|
||||||
"node-forge": "^0.7.5",
|
"node-forge": "^0.7.5",
|
||||||
"node-md6": "^0.1.0",
|
"node-md6": "^0.1.0",
|
||||||
"notepack.io": "^2.1.3",
|
"notepack.io": "^2.1.3",
|
||||||
|
|||||||
@ -342,7 +342,8 @@
|
|||||||
"Remove EXIF",
|
"Remove EXIF",
|
||||||
"Extract EXIF",
|
"Extract EXIF",
|
||||||
"Numberwang",
|
"Numberwang",
|
||||||
"XKCD Random Number"
|
"XKCD Random Number",
|
||||||
|
"Render Moustache"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
49
src/core/operations/RenderMoustache.mjs
Normal file
49
src/core/operations/RenderMoustache.mjs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* @author gchq77703 []
|
||||||
|
* @copyright Crown Copyright 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Operation from "../Operation";
|
||||||
|
import Moustache from "mustache";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render Moustache operation
|
||||||
|
*/
|
||||||
|
class RenderMoustache extends Operation {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render Moustache constructor
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.name = "Render Moustache";
|
||||||
|
this.module = "Default";
|
||||||
|
this.description = "Uses a provided Moustache template in order to render a JSON value.";
|
||||||
|
this.infoURL = "https://mustache.github.io/mustache.5.html";
|
||||||
|
this.inputType = "JSON";
|
||||||
|
this.outputType = "html";
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
name: "Template",
|
||||||
|
type: "text",
|
||||||
|
value: "Hello {{name}}."
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {JSON} input
|
||||||
|
* @param {Object[]} args
|
||||||
|
* @returns {html}
|
||||||
|
*/
|
||||||
|
run(input, args) {
|
||||||
|
const [template] = args;
|
||||||
|
|
||||||
|
return Moustache.render(template, input)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default RenderMoustache;
|
||||||
@ -64,6 +64,7 @@ import "./tests/operations/SetUnion";
|
|||||||
import "./tests/operations/SymmetricDifference";
|
import "./tests/operations/SymmetricDifference";
|
||||||
import "./tests/operations/TranslateDateTimeFormat";
|
import "./tests/operations/TranslateDateTimeFormat";
|
||||||
import "./tests/operations/Magic";
|
import "./tests/operations/Magic";
|
||||||
|
import "./tests/operations/RenderMoustache"
|
||||||
|
|
||||||
let allTestsPassing = true;
|
let allTestsPassing = true;
|
||||||
const testStatusCounts = {
|
const testStatusCounts = {
|
||||||
|
|||||||
47
test/tests/operations/RenderMoustache.mjs
Normal file
47
test/tests/operations/RenderMoustache.mjs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* Render Moustache tests.
|
||||||
|
*
|
||||||
|
* @author gchq77703 []
|
||||||
|
*
|
||||||
|
* @copyright Crown Copyright 2018
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../TestRegister";
|
||||||
|
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Render Moustache",
|
||||||
|
input: `{
|
||||||
|
"name": "Dave",
|
||||||
|
"value": "£50,000",
|
||||||
|
"in_england": true,
|
||||||
|
"taxed_value": "£40,000"
|
||||||
|
}`,
|
||||||
|
expectedOutput: `Hello Dave
|
||||||
|
You have just won £50,000!
|
||||||
|
Well, £40,000 after taxes.
|
||||||
|
`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Render Moustache",
|
||||||
|
args: [`Hello {{name}}
|
||||||
|
You have just won {{value}}!
|
||||||
|
{{#in_england}}
|
||||||
|
Well, {{taxed_value}} after taxes.
|
||||||
|
{{/in_england}}`]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Render Moustache",
|
||||||
|
input: `{}`,
|
||||||
|
expectedOutput: `Hello .`,
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Render Moustache",
|
||||||
|
args: [`Hello {{name}}.`]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
Loading…
x
Reference in New Issue
Block a user