Skip to content

Commit

Permalink
DOMBuilder API changing for 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
insin committed May 30, 2011
1 parent 62bf5a2 commit ef7de28
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
8 changes: 4 additions & 4 deletions newforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ ErrorList.prototype.extend = function(errorList)
ErrorList.prototype.asUL = function()
{
return DOMBuilder.createElement("ul", {"class": "errorlist"},
DOMBuilder.map("li", this.errors));
DOMBuilder.map("li", {}, this.errors));
};

/**
Expand Down Expand Up @@ -4915,14 +4915,14 @@ BaseForm.prototype._htmlOutput = function(normalRow, errorRow, errorsOnSeparateR

if (bf.label)
{
var isSafe = DOMBuilder.isSafe(bf.label);
var isSafe = DOMBuilder.html && DOMBuilder.html.isSafe(bf.label);
label = ""+bf.label;
// Only add the suffix if the label does not end in punctuation
if (this.labelSuffix &&
":?.!".indexOf(label.charAt(label.length - 1)) == -1)
label += this.labelSuffix;
if (isSafe)
label = DOMBuilder.markSafe(label);
label = DOMBuilder.html.markSafe(label);
label = bf.labelTag({contents: label}) || "";
}

Expand Down Expand Up @@ -6108,7 +6108,7 @@ var forms = {
// Expose newforms to the outside world
if (modules)
{
module.exports = forms;
extend(module.exports, forms);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,14 @@ BaseForm.prototype._htmlOutput = function(normalRow, errorRow, errorsOnSeparateR

if (bf.label)
{
var isSafe = DOMBuilder.isSafe(bf.label);
var isSafe = DOMBuilder.html && DOMBuilder.html.isSafe(bf.label);
label = ""+bf.label;
// Only add the suffix if the label does not end in punctuation
if (this.labelSuffix &&
":?.!".indexOf(label.charAt(label.length - 1)) == -1)
label += this.labelSuffix;
if (isSafe)
label = DOMBuilder.markSafe(label);
label = DOMBuilder.html.markSafe(label);
label = bf.labelTag({contents: label}) || "";
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ ErrorList.prototype.extend = function(errorList)
ErrorList.prototype.asUL = function()
{
return DOMBuilder.createElement("ul", {"class": "errorlist"},
DOMBuilder.map("li", this.errors));
DOMBuilder.map("li", {}, this.errors));
};

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/errormessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ test("Overriding forms.ErrorList", function()
}
CustomErrorList.prototype.asDIV = function() {
return DOMBuilder.createElement("div", {"class": "error"},
DOMBuilder.map("p", this.errors));
DOMBuilder.map("p", {}, this.errors));
};

// This form should render errors the default way.
Expand Down
4 changes: 2 additions & 2 deletions tests/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,14 @@ test("Escaping", function()
// Validation errors are HTML-escaped when output as HTML
var EscapingForm = forms.Form({
specialName: forms.CharField({label: "<em>Special</em> Field"}),
specialSafeName: forms.CharField({label: DOMBuilder.markSafe("<em>Special</em> Field")}),
specialSafeName: forms.CharField({label: DOMBuilder.html.markSafe("<em>Special</em> Field")}),

cleanSpecialName: function() {
throw forms.ValidationError("Something's wrong with '" + this.cleanedData.specialName + "'");
},
cleanSpecialSafeName: function() {
throw forms.ValidationError(
DOMBuilder.markSafe(
DOMBuilder.html.markSafe(
"'<b>" + this.cleanedData.specialSafeName + "</b>' is a safe string"));
}
});
Expand Down
6 changes: 2 additions & 4 deletions tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
<!--script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script-->
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<!-- Supporting libraries -->
<script type="text/javascript" src="https://github.com/insin/DOMBuilder/raw/master/DOMBuilder.js"></script>
<script type="text/javascript">
DOMBuilder.mode = "HTML";
</script>
<script type="text/javascript" src="https://github.com/insin/DOMBuilder/raw/master/lib/DOMBuilder.js"></script>
<script type="text/javascript" src="https://github.com/insin/DOMBuilder/raw/master/lib/DOMBuilder.html.js"></script>
<!-- Code under test -->
<script type="text/javascript" src="../newforms.js"></script>
<!-- Custom test assertions -->
Expand Down
2 changes: 1 addition & 1 deletion tests/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ test("ValidationError", function()
var example = "Example of link: <a href=\"http://www.example.com/\">example</a>";
equals(""+forms.ErrorList(forms.ValidationError(example).messages).asUL(),
"<ul class=\"errorlist\"><li>Example of link: &lt;a href=&quot;http://www.example.com/&quot;&gt;example&lt;/a&gt;</li></ul>");
equals(""+forms.ErrorList(forms.ValidationError(DOMBuilder.markSafe(example)).messages).asUL(),
equals(""+forms.ErrorList(forms.ValidationError(DOMBuilder.html.markSafe(example)).messages).asUL(),
"<ul class=\"errorlist\"><li>Example of link: <a href=\"http://www.example.com/\">example</a></li></ul>");
});
12 changes: 6 additions & 6 deletions tests/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test("TextInput", function()
"<input class=\"special\" type=\"text\" name=\"email\">");

// Attributes can be safe strings if needed
w = forms.TextInput({attrs: {"onblur": DOMBuilder.markSafe("function('foo')")}});
w = forms.TextInput({attrs: {"onblur": DOMBuilder.html.markSafe("function('foo')")}});
equal(""+w.render("email", ""),
"<input onblur=\"function('foo')\" type=\"text\" name=\"email\">");
});
Expand Down Expand Up @@ -201,7 +201,7 @@ test("Textarea", function()
"<textarea rows=\"10\" cols=\"40\" name=\"msg\">value</textarea>");
equal(""+w.render("msg", "some \"quoted\" & ampersanded value"),
"<textarea rows=\"10\" cols=\"40\" name=\"msg\">some &quot;quoted&quot; &amp; ampersanded value</textarea>");
equal(""+w.render("msg", DOMBuilder.markSafe("pre &quot;quoted&quot; value")),
equal(""+w.render("msg", DOMBuilder.html.markSafe("pre &quot;quoted&quot; value")),
"<textarea rows=\"10\" cols=\"40\" name=\"msg\">pre &quot;quoted&quot; value</textarea>");
equal(""+w.render("msg", "value", {attrs: {"class": "pretty", rows: 20}}),
"<textarea rows=\"20\" cols=\"40\" name=\"msg\" class=\"pretty\">value</textarea>");
Expand Down Expand Up @@ -356,7 +356,7 @@ test("Select", function()
"</select>");

// Choices are escaped correctly
equal(""+w.render("num", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.markSafe("you &gt; me")]]}),
equal(""+w.render("num", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.html.markSafe("you &gt; me")]]}),
"<select name=\"num\">\n" +
"<option value=\"1\">1</option>\n" +
"<option value=\"2\">2</option>\n" +
Expand Down Expand Up @@ -529,7 +529,7 @@ test("SelectMultiple", function()
"</select>");

// Choices are escaped correctly
equal(""+w.render("nums", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.markSafe("you &gt; me")]]}),
equal(""+w.render("nums", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.html.markSafe("you &gt; me")]]}),
"<select name=\"nums\" multiple=\"multiple\">\n" +
"<option value=\"1\">1</option>\n" +
"<option value=\"2\">2</option>\n" +
Expand Down Expand Up @@ -732,7 +732,7 @@ test("RadioSelect", function()

// Choices are escaped correctly
w = forms.RadioSelect();
equal(""+w.render("escape", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.markSafe("you &gt; me")]]}),
equal(""+w.render("escape", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.html.markSafe("you &gt; me")]]}),
"<ul>\n" +
"<li><label><input type=\"radio\" name=\"escape\" value=\"bad\"> you &amp; me</label></li>\n" +
"<li><label><input type=\"radio\" name=\"escape\" value=\"good\"> you &gt; me</label></li>\n" +
Expand Down Expand Up @@ -852,7 +852,7 @@ test("CheckboxSelectMultiple", function()
"</ul>");

// Choices are escaped correctly
equal(""+w.render("escape", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.markSafe("you &gt; me")]]}),
equal(""+w.render("escape", null, {choices: [["bad", "you & me"], ["good", DOMBuilder.html.markSafe("you &gt; me")]]}),
"<ul>\n" +
"<li><label><input type=\"checkbox\" name=\"escape\" value=\"1\"> 1</label></li>\n" +
"<li><label><input type=\"checkbox\" name=\"escape\" value=\"2\"> 2</label></li>\n" +
Expand Down

0 comments on commit ef7de28

Please sign in to comment.