Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Automated g4 rollback

*** 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...
commit 62473f3396d8a65ff418fff59f7d8eab6b02175f 1 parent 9eb1e6a
xtof@google.com authored
Showing with 4 additions and 40 deletions.
  1. +4 −17 closure/goog/soy/renderer.js
  2. +0 −23 closure/goog/soy/renderer_test.html
View
21 closure/goog/soy/renderer.js
@@ -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');
@@ -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_()));
};
@@ -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.
@@ -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;
};
View
23 closure/goog/soy/renderer_test.html
@@ -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);
@@ -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);
}
Please sign in to comment.
Something went wrong with that request. Please try again.