redoculous
v0.3.3
Published
PHP style templates
Downloads
13
Maintainers
Readme
redoculous
An async template library in the style of PHP. Try it out!
- Use the entire power of the node runtime.
- Handle asynchronous code easily with
await
- Identify errors fast with accurate stack traces.
Example
import render from 'redoculous';
import fs from 'fs';
const path = '/path/to/template.md.doc';
const raw = fs.readFileSync(path);
render({
template: raw,
filepath: path,
globals: { foo: 'bar' }
}).then(
text => console.log(text),
err => console.error(err),
);
API
render(options: Object) -> Promise<String>
Process a template into text. Takes the following options:
template: String
the template to renderfilepath: String
where to resolverequire
fromglobals: ?Object
the initial variables your template can use
Syntax
<?doc
// you have a full node environment to play around in
const foo = "World";
const bar = require("./module");
?>
# Interpolate exported values easily with: <?= foo ?>
<?doc
// all code is run inside an async function
const result = await new Promise(res => setTimeout(
res,
500,
"value"
));
?>
The result is <?= result ?>
<?doc
// you can also interpolate code and text
for (let i = 0; i < 10; i++) { ?>
repeating <?= i ?> times
<?doc } ?>