Permalink
Browse files

revert change re Last property; Add* and Reference* return the script…

…/style tags instead.
  • Loading branch information...
1 parent 6aaab79 commit f8103728490297bec21d8ccc0e27d890ad39ec98 @scichelli committed May 22, 2011
Showing with 40 additions and 22 deletions.
  1. +28 −8 src/HtmlTags.Testing/HtmlDocumentTester.cs
  2. +12 −14 src/HtmlTags/HtmlDocument.cs
View
36 src/HtmlTags.Testing/HtmlDocumentTester.cs
@@ -71,8 +71,7 @@ public void add_styling()
[Test]
public void add_attributes_to_style_tag()
{
- document.AddStyle("p { display: block; }");
- document.Last.Attr("media", "screen");
+ document.AddStyle("p { display: block; }").Attr("media", "screen");
document.ToString().ShouldContain("</title><style media=\"screen\">p { display: block; }</style></head>");
}
@@ -88,8 +87,7 @@ public void reference_external_stylesheet()
public void reference_external_stylesheet_and_override_attributes()
{
document.ReferenceStyle("main.css");
- document.ReferenceStyle("print.css");
- document.Last.Attr("media", "print");
+ document.ReferenceStyle("print.css").Attr("media", "print");
document.ToString().ShouldContain(
String.Format("{0}{1}{2}{3}",
"</title>",
@@ -132,8 +130,7 @@ public void add_javascript()
[Test]
public void add_attributes_to_script_tag()
{
- document.AddJavaScript("var today;");
- document.Last.Attr("defer", "true");
+ document.AddJavaScript("var today;").Attr("defer", "true");
var expected = String.Format("</title><script type=\"text/javascript\" defer=\"true\">{0}var today;{0}</script></head>", Environment.NewLine);
document.ToString().ShouldContain(expected);
}
@@ -157,8 +154,7 @@ public void reference_javascript_by_file()
public void reference_javascript_file_and_override_attributes()
{
document.ReferenceJavaScriptFile("nav.js");
- document.ReferenceJavaScriptFile("biz.js");
- document.Last.Attr("type", "text/vbscript");
+ document.ReferenceJavaScriptFile("biz.js").Attr("type", "text/vbscript");
document.ToString().ShouldContain(
String.Format("{0}{1}{2}{3}",
"</title>",
@@ -230,6 +226,30 @@ public void the_last_property()
}
[Test]
+ public void adding_styles_does_not_alter_the_Last_property()
+ {
+ document.Add("p");
+
+ document.AddStyle("font-weight: bold;");
+ document.Last.TagName().ShouldEqual("p");
+
+ document.ReferenceStyle("my.css");
+ document.Last.TagName().ShouldEqual("p");
+ }
+
+ [Test]
+ public void adding_scripts_does_not_alter_the_Last_property()
+ {
+ document.Add("p");
+
+ document.AddJavaScript("alert('hi');");
+ document.Last.TagName().ShouldEqual("p");
+
+ document.ReferenceJavaScriptFile("my.js");
+ document.Last.TagName().ShouldEqual("p");
+ }
+
+ [Test]
public void write_to_file_sends_the_document_to_the_file_writer()
{
string actualContent = null;
View
26 src/HtmlTags/HtmlDocument.cs
@@ -143,40 +143,38 @@ public override string ToString()
return substitute(value);
}
- public void AddStyle(string styling)
+ public HtmlTag AddStyle(string styling)
{
var key = Guid.NewGuid().ToString();
- Last = _head.Add("style").Text(key);
-
_alterations.Add(html => html.Replace(key, styling));
+ return _head.Add("style").Text(key);
}
- public void AddJavaScript(string javascript)
+ public HtmlTag AddJavaScript(string javascript)
{
- AddScript("text/javascript", javascript);
+ return AddScript("text/javascript", javascript);
}
- public void AddScript(string scriptType, string scriptContents)
+ public HtmlTag AddScript(string scriptType, string scriptContents)
{
var key = Guid.NewGuid().ToString();
- Last = _head.Add("script").Attr("type", scriptType).Text(key);
-
_alterations.Add(html => html.Replace(key, Environment.NewLine + scriptContents + Environment.NewLine));
+ return _head.Add("script").Attr("type", scriptType).Text(key);
}
- public void ReferenceJavaScriptFile(string path)
+ public HtmlTag ReferenceJavaScriptFile(string path)
{
- ReferenceScriptFile("text/javascript", path);
+ return ReferenceScriptFile("text/javascript", path);
}
- public void ReferenceScriptFile(string scriptType, string path)
+ public HtmlTag ReferenceScriptFile(string scriptType, string path)
{
- Last = _head.Add("script").Attr("type", scriptType).Attr("src", path);
+ return _head.Add("script").Attr("type", scriptType).Attr("src", path);
}
- public void ReferenceStyle(string path)
+ public HtmlTag ReferenceStyle(string path)
{
- Last = _head.Add("link")
+ return _head.Add("link")
.Attr("media", "screen")
.Attr("href", path)
.Attr("type", "text/css")

0 comments on commit f810372

Please sign in to comment.