CMS-Compiler
Kompiliere Seiten aus dem CMS-Editor von Total.js und rendere sie mit ihren Widgets.
CMSCOMPILER(html, widgets, [used]) kompiliert eine mit dem Total.js-CMS-Editor erstellte Seite. Widgets im HTML sind mit data-cms="id__config" markiert. Der Compiler entfernt das Editor-Markup, behält statische Teile als Strings und bereitet Widgets für das Rendern vor, sodass eine Seite einmal kompiliert und viele Male gerendert werden kann.
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]) ruft die Widgets auf und baut das HTML. Ein Widget ruft next(html, [replace], [cache]) auf; mit cache wird seine Ausgabe in der kompilierten Seite gespeichert und wiederverwendet. Ein Layout ist eine kompilierte Seite mit einem Element id="CMS"; übergib es als zweites Argument, und die Seite wird darin eingefügt. Navigationen (<script type="text/navigation" name="...">) und Breadcrumbs (<script type="text/breadcrumb">) sind Tangular-Templates, die meta.navigation(id) und meta.breadcrumb lesen.