cafescript
Version:
CafeScript is a node component driven preprocessor.
58 lines (44 loc) • 1.25 kB
Markdown
CafeScript is a node component driven preprocessor.
CafeScript can be imported as a library that will run .cafe scripts and output them to `process.stdout` or installed globally and run as `$ cafe myfile.cafe`.
CafeScript .cafe files are simillar to .php files. CafeScript will preprocess the file running the JavaScript code between the `<$ $>` tags. The JavaScript has access to NodeJS globals as well as a print function. The print function prints to the output stream which defaults to stdout.
```
// main.js
require('cafescript');
var script = require('./myscript.cafe');
script();
```
```
<!-- myscript.cafe -->
<$
var hello = 'Hello, World';
$>
<html>
<head>
<title><$ print(hello); $></title>
</head>
<body>
<$
// Include other scripts like this:
// var script = require('./other.cafe');
// script();
print('CafeScript');
$>
<div>
<$
// Use inline mode
$>
<$= 'hello' $>
</div>
</body>
</html>
```
CafeScript also exports a middleware function with the signature `function(req, res)` where `res` is an output stream the file will use as an output and `req` is an accesable global `request` in the script.
Trevor Hall
MIT