redoculous

0.3.3 • Public • Published

redoculous Build Status

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 render
  • filepath: String where to resolve require from
  • globals: ?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 } ?>
 

Package Sidebar

Install

npm i redoculous

Weekly Downloads

2

Version

0.3.3

License

MIT

Last publish

Collaborators

  • nickclaw