PHP Classes

File: test/05-asynchronous/test.js

Recommend this page to a friend!
  Classes of Nikos M.   Contemplate   test/05-asynchronous/test.js   Download  
File: test/05-asynchronous/test.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Contemplate
Template engine that provides programming controls
Author: By
Last change: v.1.6.0

* local keyword to define literal local vars, some names are reserved
* literal code can communicate to and fro template code
* better variable parsing, any valid expression can be inside variable bracket notation
* update tests
Date: 1 year ago
Size: 1,402 bytes
 

Contents

Class file image Download
"use strict"; const Contemplate = require(__dirname + '/../../src/js/Contemplate.js'); // make sure it exists Contemplate.setCacheDir(__dirname + '/_tplcache'); // dynamically update the cached template if original template has changed Contemplate.setCacheMode(Contemplate.CACHE_TO_DISK_AUTOUPDATE); // add templates var TPLS = { 'layout/base.tpl.html' : __dirname+'/_tpls/layout/base.tpl.html', 'demo.tpl.html' : __dirname+'/_tpls/demo.tpl.html', 'include/sub.tpl.html' : __dirname+'/_tpls/include/sub.tpl.html', 'common/foo.tpl.html' : __dirname+'/_tpls/common/foo.tpl.html', 'common/bar.tpl.html' : __dirname+'/_tpls/common/bar.tpl.html' }; /*Contemplate.add(TPLS);*/ /*Contemplate.setTemplateFinder(function(tpl, cb) { // should handle both async and sync operation depending if callback cb is provided if (Object.prototype.hasOwnProperty.call(TPLS, tpl)) { if ('function' === typeof cb) return cb(TPLS[tpl]); else return TPLS[tpl]; } else { if ('function' === typeof cb) return cb(null); else return null; } });*/ Contemplate.setTemplateDirs([ __dirname + '/_tpls' ]); // promise-based Contemplate.tplPromise('demo.tpl.html', null, 'global') .then(function(tpl) { console.log(tpl.render({'foo':'bar','bar':'foo'})); }) .catch(function(err) { setTimeout(function() { throw err; }, 0); });