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 <html> tag. Add
'extraData' to `Boilerplate.toHTML` so that we can specify the html
attributes at request time.
This commit is contained in:
Emily Stark
2014-09-11 16:37:12 -07:00
parent e37c953413
commit 5dca0bb99a
2 changed files with 22 additions and 19 deletions

View File

@@ -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 "<!DOCTYPE html>\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);
});

View File

@@ -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];
};