From 5dca0bb99a1586afed209aeff4422451c1034239 Mon Sep 17 00:00:00 2001 From: Emily Stark Date: Thu, 11 Sep 2014 16:37:12 -0700 Subject: [PATCH] Fix html attributes in boilerplate generation. We were not passing html attributes through to the Boilerplate object, so appcache manifest was never showing up in the tag. Add 'extraData' to `Boilerplate.toHTML` so that we can specify the html attributes at request time. --- .../boilerplate-generator.js | 10 +++--- packages/webapp/webapp_server.js | 31 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/boilerplate-generator/boilerplate-generator.js b/packages/boilerplate-generator/boilerplate-generator.js index a3c085642e..21d96903ee 100644 --- a/packages/boilerplate-generator/boilerplate-generator.js +++ b/packages/boilerplate-generator/boilerplate-generator.js @@ -21,14 +21,18 @@ Boilerplate = function (arch, manifest, options) { ); }; -Boilerplate.prototype.toHTML = function () { +// The 'extraData' argument can be used to extend 'self.baseData'. Its +// purpose is to allow you to specify data that you might not know at +// the time that you construct the Boilerplate object. (e.g. it is used +// by 'webapp' to specify data that is only known at request-time). +Boilerplate.prototype.toHTML = function (extraData) { var self = this; if (! self.baseData || ! self.func) throw new Error('Boilerplate did not instantiate correctly.'); return "\n" + - Blaze.toHTML(Blaze.With(self.baseData, + Blaze.toHTML(Blaze.With(_.extend(self.baseData, extraData), self.func)); }; @@ -98,5 +102,3 @@ var _getTemplate = _.memoize(function (arch) { var filename = 'boilerplate_' + arch + '.html'; return Assets.getText(filename); }); - - diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index 20f75c4a37..fafd0985dc 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -259,22 +259,23 @@ var boilerplateByArch = {}; // XXX so far this function is always called with arch === 'web.browser' var memoizedBoilerplate = {}; var getBoilerplate = function (request, arch) { - var calculateMemoizationHash = function (request, arch) { - var htmlAttributes = getHtmlAttributes(request); - // The only thing that changes from request to request (for now) are - // the HTML attributes (used by, eg, appcache) and whether inline - // scripts are allowed, so we can memoize based on that. - return JSON.stringify({ - inlineScriptsAllowed: inlineScriptsAllowed, - htmlAttributes: htmlAttributes, - arch: arch + + var htmlAttributes = getHtmlAttributes(request); + + // The only thing that changes from request to request (for now) are + // the HTML attributes (used by, eg, appcache) and whether inline + // scripts are allowed, so we can memoize based on that. + var memHash = JSON.stringify({ + inlineScriptsAllowed: inlineScriptsAllowed, + htmlAttributes: htmlAttributes, + arch: arch + }); + + if (! memoizedBoilerplate[memHash]) { + memoizedBoilerplate[memHash] = boilerplateByArch[arch].toHTML({ + htmlAttributes: htmlAttributes }); - }; - - var memHash = calculateMemoizationHash(request, arch); - - if (! memoizedBoilerplate[memHash]) - memoizedBoilerplate[memHash] = boilerplateByArch[arch].toHTML(); + } return memoizedBoilerplate[memHash]; };