Added a simple javascript "shim" to invoke dustjs for later use with testing

master
Tom Alexander 4 years ago
parent d82224ecd1
commit 26a752baea
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

@ -0,0 +1,9 @@
* Compliance Tests
These tests run my implementation of LinkedIn's Dust and the official implementation of [LinkedIn's DustJS](https://www.dustjs.com) as compares the output to ensure they match.
** Setup
Install LinkedIn's DustJS in order to rust the compliance tests
** Running
The dustjs_shim expects a path to a template file as the first parameter, and it expects a json context over stdin. For example, to invoke it on the command line you could run:
```sh
cat test_cases/hello_world/input1.json | node dustjs_shim.js test_cases/hello_world/template.dust
```

@ -0,0 +1,29 @@
var dust = require('dustjs-linkedin');
var fs = require('fs');
var argv = process.argv.slice(2);
if (argv.length != 1) {
console.error("Expecting only 1 argument (a path to a template)");
process.exit(1);
}
var context = JSON.parse(fs.readFileSync(0, 'utf-8'));
try {
var template_source = fs.readFileSync(argv[0], 'utf-8');
} catch (err) {
console.error(err);
process.exit(1);
}
var compiled_template = dust.compile(template_source, "tmpl");
dust.loadSource(compiled_template);
dust.render("tmpl", context, function(err, out) {
if(err) {
console.error(err);
process.exit(1);
} else {
console.log(out);
process.exit(0);
}
});
Loading…
Cancel
Save