Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

new methods to add script tag and specify the script type

  • Loading branch information...
commit 6aaab79b6c7c46264e5ac34ac64e4a7004097b4f 1 parent fb8715d
Sharon Cichelli authored
14 src/HtmlTags.Testing/HtmlDocumentTester.cs
@@ -139,6 +139,13 @@ public void add_attributes_to_script_tag()
139 139 }
140 140
141 141 [Test]
  142 + public void add_script_of_a_different_type()
  143 + {
  144 + document.AddScript("text/x-ecmascript", "var today;");
  145 + document.ToString().ShouldContain("</title><script type=\"text/x-ecmascript\">" + Environment.NewLine + "var today;" + Environment.NewLine + "</script></head>");
  146 + }
  147 +
  148 + [Test]
142 149 public void reference_javascript_by_file()
143 150 {
144 151 var path = "scripts/myfile.js";
@@ -161,6 +168,13 @@ public void reference_javascript_file_and_override_attributes()
161 168 }
162 169
163 170 [Test]
  171 + public void reference_script_file_of_a_different_type()
  172 + {
  173 + document.ReferenceScriptFile("text/vbscript", "nojudgment.vbs");
  174 + document.ToString().ShouldContain("</title><script type=\"text/vbscript\" src=\"nojudgment.vbs\"></script></head>");
  175 + }
  176 +
  177 + [Test]
164 178 public void pop_rewinds_the_current()
165 179 {
166 180 document.Push("div/span");
16 src/HtmlTags/HtmlDocument.cs
@@ -153,15 +153,25 @@ public void AddStyle(string styling)
153 153
154 154 public void AddJavaScript(string javascript)
155 155 {
  156 + AddScript("text/javascript", javascript);
  157 + }
  158 +
  159 + public void AddScript(string scriptType, string scriptContents)
  160 + {
156 161 var key = Guid.NewGuid().ToString();
157   - Last = _head.Add("script").Attr("type", "text/javascript").Text(key);
  162 + Last = _head.Add("script").Attr("type", scriptType).Text(key);
158 163
159   - _alterations.Add(html => html.Replace(key, Environment.NewLine + javascript + Environment.NewLine));
  164 + _alterations.Add(html => html.Replace(key, Environment.NewLine + scriptContents + Environment.NewLine));
160 165 }
161 166
162 167 public void ReferenceJavaScriptFile(string path)
163 168 {
164   - Last = _head.Add("script").Attr("type", "text/javascript").Attr("src", path);
  169 + ReferenceScriptFile("text/javascript", path);
  170 + }
  171 +
  172 + public void ReferenceScriptFile(string scriptType, string path)
  173 + {
  174 + Last = _head.Add("script").Attr("type", scriptType).Attr("src", path);
165 175 }
166 176
167 177 public void ReferenceStyle(string path)

0 comments on commit 6aaab79

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