UNPKG

826 BJavaScriptView Raw
1var fs = require('fs'),
2 path = require('path'),
3 Handlebars = require('handlebars'),
4 pageTemplate = Handlebars.compile(fs.readFileSync(path.join(__dirname,'../tpl/PreviewDocument.hbs')).toString());
5
6/*
7 Register a special helper for missing vars.
8 A missing var will simply return its name:
9 {{myMissingVar}} => "myMissingVar"
10 */
11Handlebars.registerHelper('helperMissing', function(options) {
12 var varName = options.name;
13 return varName;
14});
15
16function PreviewDocument(){
17 this.components = [];
18}
19
20PreviewDocument.prototype.addComponent = function(component) {
21 this.components.push(component);
22};
23
24PreviewDocument.prototype.render = function() {
25
26 return pageTemplate({
27 component: this.components[0],
28 html: this.components[0].render(),
29 cacheBust: (new Date()).getTime()
30 });
31};
32
33module.exports = PreviewDocument;
\No newline at end of file