Comparing version 0.0.28 to 0.0.29
@@ -122,3 +122,3 @@ const htmlEncode = require('js-htmlencode'); | ||
background-color: #fbfbfb; | ||
white-space: pre-wrap; | ||
white-space: pre; | ||
} | ||
@@ -125,0 +125,0 @@ ol li.highlight{ |
'use strict'; | ||
require('./utils'); | ||
function compilePageSync(Html, Model, debug) { | ||
function compilePageSync(Html, Model, Shared, debug) { | ||
'use strict'; | ||
@@ -12,2 +12,3 @@ | ||
sandbox.Model = Model; | ||
sandbox.Shared = Shared; | ||
vm.runInNewContext(Html._js, sandbox); | ||
@@ -22,5 +23,5 @@ } | ||
function compilePage(Html, Model, debug, done) { | ||
function compilePage(Html, Model, Shared, debug, done) { | ||
try { | ||
compilePageSync(Html, Model, debug); | ||
compilePageSync(Html, Model, Shared, debug); | ||
return Html.__renderLayout(done); | ||
@@ -57,3 +58,2 @@ } | ||
// function (process,...){...}() prevents [this] to exist for the 'vm.runInNewContext()' method | ||
var deleteTemplate = (debugMode) ? "" : "delete Html.__template;"; | ||
this._js = ` | ||
@@ -63,3 +63,2 @@ (function (process, window, global, module, compilePage, compilePageSync, undefined) { | ||
delete Html._js; | ||
${deleteTemplate} | ||
delete Html._vm; | ||
@@ -69,4 +68,8 @@ delete Html._sandbox; | ||
}).call();`; | ||
this.__template = args.template; | ||
// User section. | ||
if (debugMode) | ||
this.__dbg = { viewName: args.filePath, template: args.template } | ||
this.$ = | ||
this.layout = null; | ||
@@ -96,3 +99,4 @@ // Private | ||
sections, | ||
parsedSections: args.parsedSections | ||
parsedSections: args.parsedSections, | ||
viewsSharedData: args.viewsSharedData | ||
}; | ||
@@ -174,3 +178,4 @@ compile(compileOpt, done); | ||
sections, | ||
parsedSections: args.parsedSections | ||
parsedSections: args.parsedSections, | ||
viewsSharedData: args.viewsSharedData | ||
}; | ||
@@ -285,3 +290,3 @@ let html = compileSync(compileOpt); | ||
compilePage(html, this.args.model, isDebugMode(opts), (err, html) => { | ||
compilePage(html, this.args.model, this.args.viewsSharedData, isDebugMode(opts), (err, html) => { | ||
if (err) | ||
@@ -304,3 +309,3 @@ return onError(err, this); | ||
var html = this.getHtml(htmlArgs); | ||
compilePageSync(html, this.args.model, isDebugMode(opts)); | ||
compilePageSync(html, this.args.model, this.args.viewsSharedData, isDebugMode(opts)); | ||
} | ||
@@ -315,3 +320,2 @@ catch (exc) { | ||
getHtml(htmlArgs) { | ||
let jshtml = this.args.template; | ||
@@ -327,2 +331,3 @@ var isString = Object.prototype.toString.call(jshtml) === "[object String]"; | ||
this.args.parsedSections = this.args.parsedSections || {}; | ||
this.args.viewsSharedData = this.args.viewsSharedData || {}; | ||
this.blocks = []; | ||
@@ -329,0 +334,0 @@ this.parseHtml(this.blocks); |
{ | ||
"name": "raz", | ||
"description": "Razor-like syntax for templating views in Express framework by mixing HTML with JavaScript.", | ||
"version": "0.0.28", | ||
"version": "0.0.29", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Sergey", |
@@ -94,2 +94,4 @@ console.log("STARTED: server.test.js"); | ||
expect(layouts, "layouts count").to.have.lengthOf(layoutNames.length); | ||
let sharedTests = $('div.shared-data:contains("Test shared object.")'); | ||
expect(sharedTests, "views shared data test").to.have.lengthOf(3); | ||
@@ -96,0 +98,0 @@ for (var i = 0; i < layouts.length; i++) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
162771
3698