Turbx
![npm license](https://img.shields.io/npm/l/turbx)
![npm monthly downloads](https://img.shields.io/npm/dm/turbx)
![donation link](https://img.shields.io/badge/buy%20me%20a%20coffee-paypal-blue)
A Fast and Easy To Use View Engine, Compiled In Go.
Whats New
- Compiler will auto compress to gzip or brotli if the browser supports it
Installation
sudo apt-get install libpcre3-dev
npm install turbx
Setup
const express = require('express');
const {join} = require('path');
const turbx = require('turbx');
const app = express();
app.engine('xhtml', turbx({
template: 'layout',
opts: {default: 'some default options for res.render'},
before: function(opts){
},
after: function(opts, html ){
},
}));
app.set('views', join(__dirname, 'views'));
app.set('view engine', 'md');
app.use(function(req, res, next){
res.render('index', {
title: 'example',
content: '<h2>Hello, World!</h2>',
$GoogleAuthToken: 'This Value Will Never Change',
});
});
app.use(async function(req, res, next){
let preCompiled = await res.inCache('index');
if(!preCompiled){
const SomethingConsistant = await someLongProcess();
await res.preRender('index', {
$myConstVar: SomethingConsistant,
});
}
res.render('index', {
title: 'example',
content: '<h2>Hello, World!</h2>',
});
});
app.use('/fix-cache', async function(req, res, next){
turbx.preCompile('index', {
$MyConstOpts: 'new constant option',
});
res.render('index', {
title: 'example',
content: '<h2>Hello, World!</h2>',
});
});
Usage
/* this is also a comment */
// this is an inline comment
{{title}}
{{{content}}}
{{title|name|'Default Title'}}
<a {{href="url"}}>Link</a>
<a {{="href"}}>Link</a>
{{obj.key}}
{{arr.0}}
{{obj[key]}}
{{obj[myVar]}}
{{$normalVal|'make this constant anyway, even if not sent as a constant'}}
<_if var1 & var2="'b'" | var2="'c'" | !var3 | (group & group1.test1)>
do stuff...
<_else !var1 & var2="var3" | (var3=">=3" & var3="!0")/>
do other stuff...
<_else/>
do final stuff...
</_if>
<_each myObj as="value" of="key">
{{key}}: {{value}}
</_each>
<MyComponent arg1="value 1" arg2="value 2">
Some body to add to the component
</MyComponent>
<MyComponent arg1="value"/>
{{arg1}} - {{arg2}}
<h1>
{{{body}}}
</h1>
<html>
<head></head>
<body>
<header></header>
<main>
<Body/>
</main>
<footer>
</body>
</html>
Other Functions
<_lorem/>
<_lorem 2/>
<_lorem s 3 5 10/>
<_lorem w 1 5 10/>
<_json myList/>
Additional Features
turbx.rateLimit(app, {opts });
turbx.renderPages(app, {opts});