Skip to content
Browse files

new methods to add script tag and specify the script type

  • Loading branch information...
1 parent fb8715d commit 6aaab79b6c7c46264e5ac34ac64e4a7004097b4f @scichelli committed May 21, 2011
Showing with 27 additions and 3 deletions.
  1. +14 −0 src/HtmlTags.Testing/HtmlDocumentTester.cs
  2. +13 −3 src/HtmlTags/HtmlDocument.cs
View
14 src/HtmlTags.Testing/HtmlDocumentTester.cs
@@ -139,6 +139,13 @@ public void add_attributes_to_script_tag()
}
[Test]
+ public void add_script_of_a_different_type()
+ {
+ document.AddScript("text/x-ecmascript", "var today;");
+ document.ToString().ShouldContain("</title><script type=\"text/x-ecmascript\">" + Environment.NewLine + "var today;" + Environment.NewLine + "</script></head>");
+ }
+
+ [Test]
public void reference_javascript_by_file()
{
var path = "scripts/myfile.js";
@@ -161,6 +168,13 @@ public void reference_javascript_file_and_override_attributes()
}
[Test]
+ public void reference_script_file_of_a_different_type()
+ {
+ document.ReferenceScriptFile("text/vbscript", "nojudgment.vbs");
+ document.ToString().ShouldContain("</title><script type=\"text/vbscript\" src=\"nojudgment.vbs\"></script></head>");
+ }
+
+ [Test]
public void pop_rewinds_the_current()
{
document.Push("div/span");
View
16 src/HtmlTags/HtmlDocument.cs
@@ -153,15 +153,25 @@ public void AddStyle(string styling)
public void AddJavaScript(string javascript)
{
+ AddScript("text/javascript", javascript);
+ }
+
+ public void AddScript(string scriptType, string scriptContents)
+ {
var key = Guid.NewGuid().ToString();
- Last = _head.Add("script").Attr("type", "text/javascript").Text(key);
+ Last = _head.Add("script").Attr("type", scriptType).Text(key);
- _alterations.Add(html => html.Replace(key, Environment.NewLine + javascript + Environment.NewLine));
+ _alterations.Add(html => html.Replace(key, Environment.NewLine + scriptContents + Environment.NewLine));
}
public void ReferenceJavaScriptFile(string path)
{
- Last = _head.Add("script").Attr("type", "text/javascript").Attr("src", path);
+ ReferenceScriptFile("text/javascript", path);
+ }
+
+ public void ReferenceScriptFile(string scriptType, string path)
+ {
+ Last = _head.Add("script").Attr("type", scriptType).Attr("src", path);
}
public void ReferenceStyle(string path)

0 comments on commit 6aaab79

Please sign in to comment.
Something went wrong with that request. Please try again.