Compilatore CMS
Compila le pagine create con l'editor CMS di Total.js e renderizzale con i loro widget.
CMSCOMPILER(html, widgets, [used]) compila una pagina creata con l'editor di Total.js CMS. I widget nell'HTML sono contrassegnati con data-cms="id__config". Il compilatore rimuove il markup dell'editor, mantiene le parti statiche come stringhe e prepara i widget per il rendering, così una pagina può essere compilata una volta e renderizzata molte volte.
var widgets = [];
widgets.push({
id: 'contact',
css: '.contact{padding:20px}',
render: function(opt, next) {
// opt.config is the widget configuration from the editor
next('<a href="mailto:' + opt.config.email + '">' + opt.config.email + '</a>');
}
});
var page = CMSCOMPILER(html, widgets);
page.importcss().importjs().importmeta('<title>Contact</title>');
exports.install = function() {
ROUTE('GET /contact/', function() {
var $ = this;
page.render({ url: $.url }, function(err, html) {
$.html(html);
});
});
};render(meta, [layout], [callback]) chiama i widget e costruisce l'HTML. Un widget chiama next(html, [replace], [cache]); con cache il suo output viene memorizzato nella pagina compilata e riutilizzato. Un layout è una pagina compilata con un elemento id="CMS"; passalo come secondo argomento e la pagina viene inserita al suo interno. Le navigazioni (<script type="text/navigation" name="...">) e i breadcrumb (<script type="text/breadcrumb">) sono template Tangular che leggono meta.navigation(id) e meta.breadcrumb.