Skip to content

Commit 4bb67f4

Browse files
committed
add server option for views, which serializes as an empty template for the browser
note that this is in addition to the existing `serverOnly` option, which does not serialize the view at all, so it cannot be used from other views on the browser
1 parent a63e8a0 commit 4bb67f4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/templates.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,23 @@ Views.prototype.serialize = function(options) {
381381
var out = 'function(derbyTemplates, views) {' +
382382
'var expressions = derbyTemplates.expressions;' +
383383
'var templates = derbyTemplates.templates;';
384+
var forServer = options && options.server;
385+
var minify = options && options.minify;
384386
for (var name in this.nameMap) {
385387
var view = this.nameMap[name];
386-
if (options && !options.server && view.options && view.options.serverOnly) continue;
387388
var template = view.template || view.parse();
389+
if (!forServer && view.options) {
390+
// Do not serialize views with the `serverOnly` option, except when
391+
// serializing for a server script
392+
if (view.options.serverOnly) continue;
393+
// For views with the `server` option, serialize them with a blank
394+
// template body. This allows them to be used from other views on the
395+
// browser, but they will output nothing on the browser
396+
if (view.options.server) template = exports.emptyTemplate;
397+
}
388398
out += 'views.register(' + serializeObject.args([
389399
view.name
390-
, (options && options.minify) ? null : view.source
400+
, (minify) ? null : view.source
391401
, (hasKeys(view.options)) ? view.options : null
392402
]) + ').parse = function() {return this.template = ' + template.serialize() + '};';
393403
}

0 commit comments

Comments
 (0)