Serve / JSPP
This module provides a Javascript Pre-processor implementation for use in web applications.
This is very much only a proof-of-concept and will most definitely be rewritten entirely.
Example
var JSPP = Serve.module('JSPreProcessor/libJSPP');
// Although designed for use with HTML templates, any template
// where <? and ?> won't exist will also work.
var template = `<html>
<head>
<title>Hello, <? this.INT__SEND(params['name']); ?></title>
<body>
This is just a message from <? this.INT__SEND( myName() ); ?>.
</body>
</html>`;
// A mapped object can be passed to a template object:
var params = { 'name':'Joe' };
// Functions from the global object can also be called from within a template:
function myName() {
return 'JSPP';
}
// This converts the template into eval-able code:
var code = JSPP.process(template);
// This runs the resulting code, returning the generated object for us to use:
var obj = Serve.eval(code);
// Finally, we can operate on the resulting object:
var output = obj.process( params );
// And clean up the object:
JSPP.destroyObject( obj );
Serve.print(output);
Serve.quit(0);
Result
<html>
<head>
<title>Hello, Joe</title>
<body>
This is just a message from JSPP.
</body>
</html>
Methods