Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Automated g4 rollback
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Broke

*** Original change description ***

Restrict goog.soy.Renderer.render to only render strict Soy templates of kind="html".

Also, strenghten .renderStrict to assume kind="html" if called without explicit kind in opt_kind parameter.

DELTA=40 (0 added, 36 deleted, 4 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6220


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2483 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information
xtof@google.com committed Jan 30, 2013
1 parent 9eb1e6a commit 62473f3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
21 changes: 4 additions & 17 deletions closure/goog/soy/renderer.js
Expand Up @@ -40,8 +40,6 @@ goog.provide('goog.soy.Renderer');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.soy');
goog.require('goog.soy.data.SanitizedContent');
goog.require('goog.soy.data.SanitizedContentKind');



Expand Down Expand Up @@ -121,22 +119,14 @@ goog.soy.Renderer.prototype.renderElement = function(element, template,

/**
* Renders a Soy template and returns the output string.
* If the template is strict, it must be of kind HTML. To render strict
* templates of other kinds, use {@code renderText} (for {@code kind="text"}) or
* {@code renderStrict}.
*
* @param {Function} template The Soy template defining the element's content.
* @param {Object=} opt_templateData The data for the template.
* @return {string} The return value of rendering the template directly.
*/
goog.soy.Renderer.prototype.render = function(template, opt_templateData) {
var result = template(
opt_templateData || {}, undefined, this.getInjectedData_());
goog.asserts.assert(!(result instanceof goog.soy.data.SanitizedContent) ||
result.contentKind === goog.soy.data.SanitizedContentKind.HTML,
'render was called with a strict template of kind other than "html"' +
' (consider using renderText or renderStrict)');
return String(result);
return String(
template(opt_templateData || {}, undefined, this.getInjectedData_()));
};


Expand Down Expand Up @@ -168,8 +158,7 @@ goog.soy.Renderer.prototype.renderText = function(template, opt_templateData) {
* RETURN_TYPE} template The Soy template to render.
* @param {Object=} opt_templateData The data for the template.
* @param {goog.soy.data.SanitizedContentKind=} opt_kind The output kind to
* assert. If null, the template must be of kind="html" (i.e., opt_kind
* defaults to goog.soy.data.SanitizedContentKind.HTML).
* assert.
* @return {RETURN_TYPE} The SanitizedContent object. This return type is
* generic based on the return type of the template, such as
* soy.SanitizedHtml.
Expand All @@ -181,9 +170,7 @@ goog.soy.Renderer.prototype.renderStrict = function(
opt_templateData || {}, undefined, this.getInjectedData_());
goog.asserts.assertInstanceof(result, goog.soy.data.SanitizedContent,
'renderStrict cannot be called on a non-strict soy template');
goog.asserts.assert(
result.contentKind ===
(opt_kind || goog.soy.data.SanitizedContentKind.HTML),
goog.asserts.assert(!opt_kind || result.contentKind === opt_kind,
'renderStrict was called with the wrong kind of template');
return result;
};
Expand Down
23 changes: 0 additions & 23 deletions closure/goog/soy/renderer_test.html
Expand Up @@ -89,18 +89,6 @@
}


function testRenderRejectsNonHtmlStrictTemplates() {
var renderer = new goog.soy.Renderer(dataSupplier);
assertEquals(
'Assertion failed: ' +
'render was called with a strict template of kind other than "html"' +
' (consider using renderText or renderStrict)',
assertThrows(function() {
renderer.render(example.unsanitizedTextTemplate, {});
}).message);
}


function testRenderStrictDoesNotConvertToString() {
var renderer = new goog.soy.Renderer(dataSupplier);
var result = renderer.renderStrict(example.sanitizedHtmlTemplate);
Expand Down Expand Up @@ -131,17 +119,6 @@
renderer.renderStrict(example.sanitizedHtmlTemplate, {},
goog.soy.data.SanitizedContentKind.JS);
}).message);

// renderStrict's opt_kind parameter defaults to SanitizedContentKind.HTML:
// Passes.
renderer.renderStrict(example.sanitizedHtmlTemplate, {});
// Rendering non-HTML template fails:
assertEquals(
'Assertion failed: ' +
'renderStrict was called with the wrong kind of template',
assertThrows(function() {
renderer.renderStrict(example.unsanitizedTextTemplate, {});
}).message);
}


Expand Down

0 comments on commit 62473f3

Please sign in to comment.