npm install afesh
npm install afe
`
Template side ##
$3
`
echo(title); ?>
html('link'); ?>
`
$3
`
for (var c=0; c<10; c++) {
?>
}
?>
`
`
if (condition) {
?>
} else {
?>
}
`
Note: ?: operator will not work,
like:
`
condition ? ?>err : ?>err ; ?>
`
$3
main.afe
`
include('meta', {cs: 'utf-8' }); ?>
`
meta.afe
`
`
output:
`html
`
---
page.afe
`
var func = include('func');
func.span('Some text.');
?>
func.p('test');
// No end tag needed at end of file, like php.
`
func.afe
`
// This is a function only script,
// you can include it any where, and call the exported methods.
module.exports.span = function (data) {
html('');
echo(data);
?>
}
module.exports.p = function (data) {
?>
echo(data);
?>
}
`
output:
`html
Some text.test
`
---
$3
`
echo($.title); // $ tag to access data from renderFile.
echo($$.count); // $$ tag for the data from include call.
`
Nodejs side ##
Only two methods, renderFile/reset.
renderFile(filename [, data [, options]], callback);
callback(error, html);
All afe script are cached, you may need to purge them some time.
afe.reset();
`javascript
var afe = require('afe');
var data = {
title: 'Site Title'
};
var options = {
root: Path.join(__dirname, 'views')
};
afe.renderFile('test.afe', data, options, function (err, html) {
console.log('afe err:', err);
console.log('html:', html);
});
// clear cache and vm context.
afe.reset();
`
#### options
* root Root folder of the script. The parent dir .. was disabled.
All include in the template are relative to root path.
* debug Enable console in the template script, and generated code will dump to the terminal.
* delimiter Character to use with angle brackets for open/close, default is ?, ?>`.