Skip to content
This repository
Browse code

Added `make docs`

  • Loading branch information...
commit c42fc82ad19156a37173b26655d8a7f1a5a4ab2a 1 parent 5bfe654
TJ Holowaychuk visionmedia authored

Showing 2 changed files with 1,364 additions and 1 deletion. Show diff stats Hide diff stats

  1. +13 1 Makefile
  2. +1,351 0 index.html
14 Makefile
... ... @@ -1,6 +1,8 @@
1 1
2 2 TESTS = test/*.test.js
3 3
  4 +SRC = $(shell find lib -type f)
  5 +
4 6 test:
5 7 @./support/expresso/bin/expresso \
6 8 --serial \
@@ -15,4 +17,14 @@ test:
15 17 test-cov:
16 18 @$(MAKE) TEST_FLAGS=--cov
17 19
18   -.PHONY: test test-cov
  20 +docs: index.html
  21 +
  22 +index.html: $(SRC)
  23 + dox \
  24 + --title "Tobi" \
  25 + --desc "Expressive server-side functional testing with jQuery and jsdom." \
  26 + --ribbon "http://github.com/learnboost/tobi" \
  27 + --private \
  28 + $^ > $@
  29 +
  30 +.PHONY: test test-cov docs
1,351 index.html
... ... @@ -0,0 +1,1351 @@
  1 +<a href="http://github.com/learnboost/tobi"><img alt="Fork me on GitHub" id="ribbon" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a><html>
  2 + <head>
  3 + <title>Tobi</title>
  4 + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  5 + <style>body {
  6 + margin: 0;
  7 + padding: 0;
  8 + font: 14px/1.5 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
  9 + color: #252519;
  10 +}
  11 +a {
  12 + color: #252519;
  13 +}
  14 +a:hover {
  15 + text-decoration: underline;
  16 + color: #19469D;
  17 +}
  18 +p {
  19 + margin: 12px 0;
  20 +}
  21 +h1, h2, h3 {
  22 + margin: 0;
  23 + padding: 0;
  24 +}
  25 +table#source {
  26 + width: 100%;
  27 + border-collapse: collapse;
  28 +}
  29 +table#source td:first-child {
  30 + padding: 30px 40px 30px 40px;
  31 + vertical-align: top;
  32 +}
  33 +table#source td:first-child,
  34 +table#source td:first-child pre {
  35 + width: 450px;
  36 +}
  37 +table#source td:last-child {
  38 + padding: 30px 0 30px 40px;
  39 + border-left: 1px solid #E5E5EE;
  40 + background: #F5F5FF;
  41 +}
  42 +table#source tr {
  43 + border-bottom: 1px solid #E5E5EE;
  44 +}
  45 +table#source tr.filename {
  46 + padding-top: 40px;
  47 + border-top: 1px solid #E5E5EE;
  48 +}
  49 +table#source tr.filename td:first-child {
  50 + text-transform: capitalize;
  51 +}
  52 +table#source tr.filename td:last-child {
  53 + font-size: 12px;
  54 +}
  55 +table#source tr.filename h2 {
  56 + margin: 0;
  57 + padding: 0;
  58 + cursor: pointer;
  59 +}
  60 +table#source tr.code h1,
  61 +table#source tr.code h2,
  62 +table#source tr.code h3 {
  63 + margin-top: 30px;
  64 + font-family: "Lucida Grande", "Helvetica Nueue", Arial, sans-serif;
  65 + font-size: 18px;
  66 +}
  67 +table#source tr.code h2 {
  68 + font-size: 16px;
  69 +}
  70 +table#source tr.code h3 {
  71 + font-size: 14px;
  72 +}
  73 +table#source tr.code ul {
  74 + margin: 15px 0 15px 35px;
  75 + padding: 0;
  76 +}
  77 +table#source tr.code ul li {
  78 + margin: 0;
  79 + padding: 1px 0;
  80 +}
  81 +table#source tr.code ul li p {
  82 + margin: 0;
  83 + padding: 0;
  84 +}
  85 +table#source tr.code td:first-child pre {
  86 + padding: 20px;
  87 +}
  88 +#ribbon {
  89 + position: fixed;
  90 + top: 0;
  91 + right: 0;
  92 +}
  93 +code .string { color: #219161; }
  94 +code .regexp { color: #219161; }
  95 +code .keyword { color: #954121; }
  96 +code .number { color: #19469D; }
  97 +code .comment { color: #bbb; }
  98 +code .this { color: #19469D; }</style>
  99 + <script>
  100 + $(function(){
  101 + $('tr.code').hide();
  102 + $('tr.filename').toggle(function(){
  103 + $(this).nextUntil('.filename').fadeIn();
  104 + }, function(){
  105 + $(this).nextUntil('.filename').fadeOut();
  106 + });
  107 + });
  108 + </script>
  109 + </head>
  110 + <body>
  111 +<table id="source"><tbody><tr><td><h1>Tobi</h1><p>Expressive server-side functional testing with jQuery and jsdom.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/assertions/should.js"><a href="#">should</a></h2></td><td>lib/assertions/should.js</td></tr><tr class="code">
  112 +<td class="docs">
  113 +<p>Module dependencies.
  114 + </p>
  115 +</td>
  116 +<td class="code">
  117 +<pre><code><span class="keyword">var</span> <span class="class">Assertion</span> = <span class="variable">require</span>(<span class="string">'should'</span>).<span class="class">Assertion</span>
  118 + , <span class="variable">statusCodes</span> = <span class="variable">require</span>(<span class="string">'http'</span>).<span class="class">STATUS_CODES</span>
  119 + , <span class="variable">j</span> = <span class="keyword">function</span>(<span class="variable">elem</span>){ <span class="keyword">return</span> <span class="string">'[jQuery '</span> + <span class="variable">i</span>(<span class="variable">elem</span>.<span class="variable">selector</span>.<span class="variable">replace</span>(<span class="regexp">/^ *\* */</span>, <span class="string">''</span>)) + <span class="string">']'</span>; }
  120 + , <span class="variable">i</span> = <span class="variable">require</span>(<span class="string">'sys'</span>).<span class="variable">inspect</span>;</code></pre>
  121 +</td>
  122 +</tr>
  123 +<tr class="code">
  124 +<td class="docs">
  125 +<p>Number strings.
  126 + </p>
  127 +</td>
  128 +<td class="code">
  129 +<pre><code><span class="keyword">var</span> <span class="variable">nums</span> = { <span class="number integer">0</span>: <span class="string">'none'</span>, <span class="number integer">1</span>: <span class="string">'one'</span>, <span class="number integer">2</span>: <span class="string">'two'</span>, <span class="number integer">3</span>: <span class="string">'three'</span> };</code></pre>
  130 +</td>
  131 +</tr>
  132 +<tr class="code">
  133 +<td class="docs">
  134 +<p>Return string representation for <code>n</code>.</p>
  135 +
  136 +<h2></h2>
  137 +
  138 +<ul><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
  139 +</td>
  140 +<td class="code">
  141 +<pre><code><span class="keyword">function</span> <span class="variable">n</span>(<span class="variable">n</span>) { <span class="keyword">return</span> <span class="variable">nums</span>[<span class="variable">n</span>] || <span class="variable">n</span>; }</code></pre>
  142 +</td>
  143 +</tr>
  144 +<tr class="code">
  145 +<td class="docs">
  146 +<p>Assert text as <code>str</code> or a <code>RegExp</code>.</p>
  147 +
  148 +<h2></h2>
  149 +
  150 +<ul><li><p><strong>param</strong>: <em>String | RegExp</em> str</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  151 +</td>
  152 +<td class="code">
  153 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">text</span> = <span class="keyword">function</span>(<span class="variable">str</span>){
  154 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  155 + , <span class="variable">text</span> = <span class="variable">elem</span>.<span class="variable">text</span>();
  156 +
  157 + <span class="keyword">if</span> (<span class="variable">str</span> <span class="variable">instanceof</span> <span class="class">RegExp</span>) {
  158 + <span class="this">this</span>.<span class="variable">assert</span>(
  159 + <span class="variable">str</span>.<span class="variable">test</span>(<span class="variable">text</span>)
  160 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>)+ <span class="string">' to have text matching '</span> + <span class="variable">i</span>(<span class="variable">str</span>)
  161 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' text '</span> + <span class="variable">i</span>(<span class="variable">text</span>) + <span class="string">' to not match '</span> + <span class="variable">i</span>(<span class="variable">str</span>));
  162 + } <span class="keyword">else</span> {
  163 + <span class="this">this</span>.<span class="variable">assert</span>(
  164 + <span class="variable">str</span> == <span class="variable">text</span>
  165 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have text '</span> + <span class="variable">i</span>(<span class="variable">str</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">text</span>)
  166 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have text '</span> + <span class="variable">i</span>(<span class="variable">str</span>));
  167 + }
  168 +
  169 + <span class="keyword">return</span> <span class="this">this</span>;
  170 +};</code></pre>
  171 +</td>
  172 +</tr>
  173 +<tr class="code">
  174 +<td class="docs">
  175 +<p>Assert that many child elements are present via <code>selector</code>.
  176 +When negated, &lt;= 1 is a valid length.</p>
  177 +
  178 +<h2></h2>
  179 +
  180 +<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  181 +</td>
  182 +<td class="code">
  183 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">many</span> = <span class="keyword">function</span>(<span class="variable">selector</span>){
  184 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  185 + , <span class="variable">elems</span> = <span class="variable">elem</span>.<span class="variable">find</span>(<span class="variable">selector</span>)
  186 + , <span class="variable">len</span> = <span class="variable">elems</span>.<span class="variable">length</span>;
  187 +
  188 + <span class="this">this</span>.<span class="variable">assert</span>(
  189 + <span class="this">this</span>.<span class="variable">negate</span> ? <span class="variable">len</span> &<span class="variable">gt</span>; <span class="number integer">1</span> : <span class="variable">len</span>
  190 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have many '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tags, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>)
  191 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have many '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tags, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>));
  192 +
  193 + <span class="keyword">return</span> <span class="this">this</span>;
  194 +};</code></pre>
  195 +</td>
  196 +</tr>
  197 +<tr class="code">
  198 +<td class="docs">
  199 +<p>Assert that one child element is present via <code>selector</code>
  200 +with optional <code>text</code> assertion..</p>
  201 +
  202 +<h2></h2>
  203 +
  204 +<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>String</em> text</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  205 +</td>
  206 +<td class="code">
  207 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">one</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">text</span>){
  208 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  209 + , <span class="variable">elems</span> = <span class="variable">elem</span>.<span class="variable">find</span>(<span class="variable">selector</span>)
  210 + , <span class="variable">len</span> = <span class="variable">elems</span>.<span class="variable">length</span>;
  211 +
  212 + <span class="this">this</span>.<span class="variable">assert</span>(
  213 + <span class="number integer">1</span> == <span class="variable">len</span>
  214 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have one '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tag, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>)
  215 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have one '</span> + <span class="variable">i</span>(<span class="variable">selector</span>) + <span class="string">' tag, but has '</span> + <span class="variable">n</span>(<span class="variable">len</span>));
  216 +
  217 + <span class="keyword">if</span> (<span class="variable">undefined</span> != <span class="variable">text</span>) {
  218 + <span class="variable">elems</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">text</span>(<span class="variable">text</span>);
  219 + }
  220 +
  221 + <span class="keyword">return</span> <span class="this">this</span>;
  222 +};</code></pre>
  223 +</td>
  224 +</tr>
  225 +<tr class="code">
  226 +<td class="docs">
  227 +<p>Assert existance attr <code>key</code> with optional <code>val</code>.</p>
  228 +
  229 +<h2></h2>
  230 +
  231 +<ul><li><p><strong>param</strong>: <em>String</em> key</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  232 +</td>
  233 +<td class="code">
  234 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">attr</span> = <span class="keyword">function</span>(<span class="variable">key</span>, <span class="variable">val</span>){
  235 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  236 + , <span class="variable">attr</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">key</span>);
  237 +
  238 + <span class="keyword">if</span> (!<span class="variable">val</span> || (<span class="variable">val</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; !<span class="this">this</span>.<span class="variable">negate</span>)) {
  239 + <span class="this">this</span>.<span class="variable">assert</span>(
  240 + <span class="variable">attr</span>.<span class="variable">length</span>
  241 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>)
  242 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">attr</span>));
  243 + }
  244 +
  245 + <span class="keyword">if</span> (<span class="variable">val</span>) {
  246 + <span class="this">this</span>.<span class="variable">assert</span>(
  247 + <span class="variable">val</span> == <span class="variable">attr</span>
  248 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">' with '</span> + <span class="variable">i</span>(<span class="variable">val</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">attr</span>)
  249 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have attribute '</span> + <span class="variable">i</span>(<span class="variable">key</span>) + <span class="string">' with '</span> + <span class="variable">i</span>(<span class="variable">val</span>));
  250 + }
  251 +
  252 + <span class="keyword">return</span> <span class="this">this</span>;
  253 +};</code></pre>
  254 +</td>
  255 +</tr>
  256 +<tr class="code">
  257 +<td class="docs">
  258 +<p>Assert presence of the given class <code>name</code>.</p>
  259 +
  260 +<h2></h2>
  261 +
  262 +<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  263 +</td>
  264 +<td class="code">
  265 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="keyword">class</span> = <span class="keyword">function</span>(<span class="variable">name</span>){
  266 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>;
  267 +
  268 + <span class="this">this</span>.<span class="variable">assert</span>(
  269 + <span class="variable">elem</span>.<span class="variable">hasClass</span>(<span class="variable">name</span>)
  270 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have class '</span> + <span class="variable">i</span>(<span class="variable">name</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'class'</span>))
  271 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have class '</span> + <span class="variable">i</span>(<span class="variable">name</span>));
  272 +
  273 + <span class="keyword">return</span> <span class="this">this</span>;
  274 +};</code></pre>
  275 +</td>
  276 +</tr>
  277 +<tr class="code">
  278 +<td class="docs">
  279 +<p>Assert that header <code>field</code> has the given <code>val</code>. </p>
  280 +
  281 +<h2></h2>
  282 +
  283 +<ul><li><p><strong>param</strong>: <em>String</em> field</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  284 +</td>
  285 +<td class="code">
  286 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">header</span> = <span class="keyword">function</span>(<span class="variable">field</span>, <span class="variable">val</span>){
  287 + <span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="string">'headers'</span>);
  288 + <span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">headers</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="variable">field</span>.<span class="variable">toLowerCase</span>(), <span class="variable">val</span>);
  289 + <span class="keyword">return</span> <span class="this">this</span>;
  290 +};</code></pre>
  291 +</td>
  292 +</tr>
  293 +<tr class="code">
  294 +<td class="docs">
  295 +<p>Assert <code>.statusCode</code> of <code>code</code>.</p>
  296 +
  297 +<h2></h2>
  298 +
  299 +<ul><li><p><strong>param</strong>: <em>Number</em> code</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  300 +</td>
  301 +<td class="code">
  302 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">status</span> = <span class="keyword">function</span>(<span class="variable">code</span>){
  303 + <span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">should</span>.<span class="variable">have</span>.<span class="variable">property</span>(<span class="string">'statusCode'</span>);
  304 + <span class="keyword">var</span> <span class="variable">status</span> = <span class="this">this</span>.<span class="variable">obj</span>.<span class="variable">statusCode</span>;
  305 +
  306 + <span class="this">this</span>.<span class="variable">assert</span>(
  307 + <span class="variable">code</span> == <span class="variable">status</span>
  308 + , <span class="string">'expected response code of '</span> + <span class="variable">code</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">code</span>])
  309 + + <span class="string">', but got '</span> + <span class="variable">status</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">status</span>])
  310 + , <span class="string">'expected to not respond with '</span> + <span class="variable">code</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">statusCodes</span>[<span class="variable">code</span>]));
  311 +
  312 + <span class="keyword">return</span> <span class="this">this</span>;
  313 +};</code></pre>
  314 +</td>
  315 +</tr>
  316 +<tr class="code">
  317 +<td class="docs">
  318 +<p>Assert id attribute.</p>
  319 +
  320 +<h2></h2>
  321 +
  322 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  323 +</td>
  324 +<td class="code">
  325 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">id</span> = <span class="variable">attr</span>(<span class="string">'id'</span>);</code></pre>
  326 +</td>
  327 +</tr>
  328 +<tr class="code">
  329 +<td class="docs">
  330 +<p>Assert title attribute.</p>
  331 +
  332 +<h2></h2>
  333 +
  334 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  335 +</td>
  336 +<td class="code">
  337 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">title</span> = <span class="variable">attr</span>(<span class="string">'title'</span>);</code></pre>
  338 +</td>
  339 +</tr>
  340 +<tr class="code">
  341 +<td class="docs">
  342 +<p>Assert alt attribute.</p>
  343 +
  344 +<h2></h2>
  345 +
  346 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  347 +</td>
  348 +<td class="code">
  349 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">alt</span> = <span class="variable">attr</span>(<span class="string">'alt'</span>);</code></pre>
  350 +</td>
  351 +</tr>
  352 +<tr class="code">
  353 +<td class="docs">
  354 +<p>Assert href attribute.</p>
  355 +
  356 +<h2></h2>
  357 +
  358 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  359 +</td>
  360 +<td class="code">
  361 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">href</span> = <span class="variable">attr</span>(<span class="string">'href'</span>);</code></pre>
  362 +</td>
  363 +</tr>
  364 +<tr class="code">
  365 +<td class="docs">
  366 +<p>Assert src attribute.</p>
  367 +
  368 +<h2></h2>
  369 +
  370 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  371 +</td>
  372 +<td class="code">
  373 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">src</span> = <span class="variable">attr</span>(<span class="string">'src'</span>);</code></pre>
  374 +</td>
  375 +</tr>
  376 +<tr class="code">
  377 +<td class="docs">
  378 +<p>Assert rel attribute.</p>
  379 +
  380 +<h2></h2>
  381 +
  382 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  383 +</td>
  384 +<td class="code">
  385 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">rel</span> = <span class="variable">attr</span>(<span class="string">'rel'</span>);</code></pre>
  386 +</td>
  387 +</tr>
  388 +<tr class="code">
  389 +<td class="docs">
  390 +<p>Assert media attribute.</p>
  391 +
  392 +<h2></h2>
  393 +
  394 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  395 +</td>
  396 +<td class="code">
  397 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">media</span> = <span class="variable">attr</span>(<span class="string">'media'</span>);</code></pre>
  398 +</td>
  399 +</tr>
  400 +<tr class="code">
  401 +<td class="docs">
  402 +<p>Assert name attribute.</p>
  403 +
  404 +<h2></h2>
  405 +
  406 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  407 +</td>
  408 +<td class="code">
  409 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">name</span> = <span class="variable">attr</span>(<span class="string">'name'</span>);</code></pre>
  410 +</td>
  411 +</tr>
  412 +<tr class="code">
  413 +<td class="docs">
  414 +<p>Assert action attribute.</p>
  415 +
  416 +<h2></h2>
  417 +
  418 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  419 +</td>
  420 +<td class="code">
  421 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">action</span> = <span class="variable">attr</span>(<span class="string">'action'</span>);</code></pre>
  422 +</td>
  423 +</tr>
  424 +<tr class="code">
  425 +<td class="docs">
  426 +<p>Assert method attribute.</p>
  427 +
  428 +<h2></h2>
  429 +
  430 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  431 +</td>
  432 +<td class="code">
  433 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">method</span> = <span class="variable">attr</span>(<span class="string">'method'</span>);</code></pre>
  434 +</td>
  435 +</tr>
  436 +<tr class="code">
  437 +<td class="docs">
  438 +<p>Assert value attribute.</p>
  439 +
  440 +<h2></h2>
  441 +
  442 +<ul><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  443 +</td>
  444 +<td class="code">
  445 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">value</span> = <span class="variable">attr</span>(<span class="string">'value'</span>);</code></pre>
  446 +</td>
  447 +</tr>
  448 +<tr class="code">
  449 +<td class="docs">
  450 +<p>Assert enabled.</p>
  451 +
  452 +<h2></h2>
  453 +
  454 +<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  455 +</td>
  456 +<td class="code">
  457 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'enabled'</span>, <span class="keyword">function</span>(){
  458 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  459 + , <span class="variable">disabled</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'disabled'</span>);
  460 +
  461 + <span class="this">this</span>.<span class="variable">assert</span>(
  462 + !<span class="variable">disabled</span>
  463 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be enabled'</span>
  464 + , <span class="string">'&lt;not implemented, use .disabled&gt;'</span>);
  465 +
  466 + <span class="keyword">return</span> <span class="this">this</span>;
  467 +});</code></pre>
  468 +</td>
  469 +</tr>
  470 +<tr class="code">
  471 +<td class="docs">
  472 +<p>Assert disabled.</p>
  473 +
  474 +<h2></h2>
  475 +
  476 +<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  477 +</td>
  478 +<td class="code">
  479 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'disabled'</span>, <span class="keyword">function</span>(){
  480 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  481 + , <span class="variable">disabled</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'disabled'</span>);
  482 +
  483 + <span class="this">this</span>.<span class="variable">assert</span>(
  484 + <span class="variable">disabled</span>
  485 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be disabled'</span>
  486 + , <span class="string">'&lt;not implemented, use .enabled&gt;'</span>);
  487 +
  488 + <span class="keyword">return</span> <span class="this">this</span>;
  489 +});</code></pre>
  490 +</td>
  491 +</tr>
  492 +<tr class="code">
  493 +<td class="docs">
  494 +<p>Assert checked.</p>
  495 +
  496 +<h2></h2>
  497 +
  498 +<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  499 +</td>
  500 +<td class="code">
  501 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'checked'</span>, <span class="variable">bool</span>(<span class="string">'checked'</span>));</code></pre>
  502 +</td>
  503 +</tr>
  504 +<tr class="code">
  505 +<td class="docs">
  506 +<p>Assert selected.</p>
  507 +
  508 +<h2></h2>
  509 +
  510 +<ul><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  511 +</td>
  512 +<td class="code">
  513 +<pre><code><span class="class">Assertion</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'selected'</span>, <span class="variable">bool</span>(<span class="string">'selected'</span>));</code></pre>
  514 +</td>
  515 +</tr>
  516 +<tr class="code">
  517 +<td class="docs">
  518 +<p>Generate a boolean assertion function for the given attr <code>name</code>.</p>
  519 +
  520 +<h2></h2>
  521 +
  522 +<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Function</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
  523 +</td>
  524 +<td class="code">
  525 +<pre><code><span class="keyword">function</span> <span class="variable">bool</span>(<span class="variable">name</span>) {
  526 + <span class="keyword">return</span> <span class="keyword">function</span>(){
  527 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>;
  528 +
  529 + <span class="this">this</span>.<span class="variable">assert</span>(
  530 + <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">name</span>)
  531 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to be '</span> + <span class="variable">name</span>
  532 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not be '</span> + <span class="variable">name</span>);
  533 +
  534 + <span class="keyword">return</span> <span class="this">this</span>;
  535 + }
  536 +}</code></pre>
  537 +</td>
  538 +</tr>
  539 +<tr class="code">
  540 +<td class="docs">
  541 +<p>Generate an attr assertion function for the given attr <code>name</code>.</p>
  542 +
  543 +<h2></h2>
  544 +
  545 +<ul><li><p><strong>param</strong>: <em>String</em> name</p></li><li><p><strong>return</strong>: <em>Function</em> </p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
  546 +</td>
  547 +<td class="code">
  548 +<pre><code><span class="keyword">function</span> <span class="variable">attr</span>(<span class="variable">name</span>) {
  549 + <span class="keyword">return</span> <span class="keyword">function</span>(<span class="variable">expected</span>){
  550 + <span class="keyword">var</span> <span class="variable">elem</span> = <span class="this">this</span>.<span class="variable">obj</span>
  551 + , <span class="variable">val</span> = <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="variable">name</span>);
  552 +
  553 + <span class="this">this</span>.<span class="variable">assert</span>(
  554 + <span class="variable">expected</span> == <span class="variable">val</span>
  555 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to have '</span> + <span class="variable">name</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">expected</span>) + <span class="string">', but has '</span> + <span class="variable">i</span>(<span class="variable">val</span>)
  556 + , <span class="string">'expected '</span> + <span class="variable">j</span>(<span class="variable">elem</span>) + <span class="string">' to not have '</span> + <span class="variable">name</span> + <span class="string">' '</span> + <span class="variable">i</span>(<span class="variable">expected</span>));
  557 +
  558 + <span class="keyword">return</span> <span class="this">this</span>;
  559 + }
  560 +}
  561 +</code></pre>
  562 +</td>
  563 +</tr><tr class="filename"><td><h2 id="lib/browser.js"><a href="#">browser</a></h2></td><td>lib/browser.js</td></tr><tr class="code">
  564 +<td class="docs">
  565 +<p>Module dependencies.
  566 + </p>
  567 +</td>
  568 +<td class="code">
  569 +<pre><code><span class="keyword">var</span> <span class="class">EventEmitter</span> = <span class="variable">require</span>(<span class="string">'events'</span>).<span class="class">EventEmitter</span>
  570 + , <span class="class">Cookie</span> = <span class="variable">require</span>(<span class="string">'./cookie'</span>)
  571 + , <span class="class">CookieJar</span> = <span class="variable">require</span>(<span class="string">'./cookie/jar'</span>)
  572 + , <span class="variable">jsdom</span> = <span class="variable">require</span>(<span class="string">'jsdom'</span>)
  573 + , <span class="variable">jQuery</span> = <span class="variable">require</span>(<span class="string">'../support/jquery'</span>)
  574 + , <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>);</code></pre>
  575 +</td>
  576 +</tr>
  577 +<tr class="code">
  578 +<td class="docs">
  579 +<p>Starting portno.
  580 + </p>
  581 +</td>
  582 +<td class="code">
  583 +<pre><code><span class="keyword">var</span> <span class="variable">port</span> = <span class="number integer">8888</span>;</code></pre>
  584 +</td>
  585 +</tr>
  586 +<tr class="code">
  587 +<td class="docs">
  588 +<p>Initialize a new <code>Browser</code> with the given <code>html</code> or <code>server</code>.</p>
  589 +
  590 +<h2></h2>
  591 +
  592 +<ul><li><p><strong>param</strong>: <em>String | http.Server</em> html</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  593 +</td>
  594 +<td class="code">
  595 +<pre><code><span class="keyword">var</span> <span class="class">Browser</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Browser</span>(<span class="variable">html</span>) {
  596 + <span class="this">this</span>.<span class="variable">history</span> = [];
  597 + <span class="this">this</span>.<span class="variable">cookieJar</span> = <span class="keyword">new</span> <span class="class">CookieJar</span>;
  598 + <span class="keyword">if</span> (<span class="string">'string'</span> == <span class="keyword">typeof</span> <span class="variable">html</span>) {
  599 + <span class="this">this</span>.<span class="variable">parse</span>(<span class="variable">html</span>);
  600 + } <span class="keyword">else</span> {
  601 + <span class="this">this</span>.<span class="variable">server</span> = <span class="variable">html</span>;
  602 + <span class="this">this</span>.<span class="variable">server</span>.<span class="variable">pending</span> = <span class="number integer">0</span>;
  603 + <span class="this">this</span>.<span class="variable">server</span>.<span class="variable">port</span> = <span class="number integer">8888</span>;
  604 + }
  605 +};</code></pre>
  606 +</td>
  607 +</tr>
  608 +<tr class="code">
  609 +<td class="docs">
  610 +<p>Inherit from <code>EventEmitter.prototype</code>.
  611 + </p>
  612 +</td>
  613 +<td class="code">
  614 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">__proto__</span> = <span class="class">EventEmitter</span>.<span class="variable">prototype</span>;</code></pre>
  615 +</td>
  616 +</tr>
  617 +<tr class="code">
  618 +<td class="docs">
  619 +<p>Parse the given <code>html</code> and populate:</p>
  620 +
  621 +<ul><li><code>.source</code></li><li><code>.window</code></li><li><code>.jQuery</code></li></ul>
  622 +
  623 +<h2></h2>
  624 +
  625 +<ul><li><p><strong>param</strong>: <em>String</em> html</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  626 +</td>
  627 +<td class="code">
  628 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">parse</span> = <span class="keyword">function</span>(<span class="variable">html</span>){
  629 + <span class="this">this</span>.<span class="variable">source</span> = <span class="variable">html</span>;
  630 + <span class="this">this</span>.<span class="variable">window</span> = <span class="variable">jsdom</span>.<span class="variable">jsdom</span>(<span class="variable">wrap</span>(<span class="variable">html</span>)).<span class="variable">createWindow</span>();
  631 + <span class="this">this</span>.<span class="variable">jQuery</span> = <span class="variable">jQuery</span>.<span class="variable">create</span>(<span class="this">this</span>.<span class="variable">window</span>);
  632 + <span class="this">this</span>.<span class="variable">jQuery</span>.<span class="variable">browser</span> = <span class="this">this</span>.<span class="variable">jQuery</span>.<span class="variable">fn</span>.<span class="variable">browser</span> = <span class="this">this</span>;
  633 + <span class="variable">require</span>(<span class="string">'./jquery'</span>)(<span class="this">this</span>, <span class="this">this</span>.<span class="variable">jQuery</span>);
  634 + <span class="this">this</span>.<span class="variable">context</span> = <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="string">'*'</span>);
  635 +};</code></pre>
  636 +</td>
  637 +</tr>
  638 +<tr class="code">
  639 +<td class="docs">
  640 +<p>Set the jQuery context for the duration of <code>fn()</code> to <code>selector</code>.</p>
  641 +
  642 +<h2></h2>
  643 +
  644 +<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  645 +</td>
  646 +<td class="code">
  647 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">within</span> =
  648 +<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">context</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">fn</span>){
  649 + <span class="keyword">var</span> <span class="variable">prev</span> = <span class="this">this</span>.<span class="variable">context</span>;
  650 + <span class="this">this</span>.<span class="variable">context</span> = <span class="this">this</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>);
  651 + <span class="variable">fn</span>();
  652 + <span class="this">this</span>.<span class="variable">context</span> = <span class="variable">prev</span>;
  653 + <span class="keyword">return</span> <span class="this">this</span>;
  654 +};</code></pre>
  655 +</td>
  656 +</tr>
  657 +<tr class="code">
  658 +<td class="docs">
  659 +<p>Request <code>path</code> with <code>method</code> and callback <code>fn(jQuery)</code>.</p>
  660 +
  661 +<h2></h2>
  662 +
  663 +<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>String</em> method</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  664 +</td>
  665 +<td class="code">
  666 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">request</span> = <span class="keyword">function</span>(<span class="variable">method</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
  667 + <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>
  668 + , <span class="variable">server</span> = <span class="this">this</span>.<span class="variable">server</span>
  669 + , <span class="variable">host</span> = <span class="string">'127.0.0.1'</span>
  670 + , <span class="variable">headers</span> = <span class="variable">options</span>.<span class="variable">headers</span> || {};
  671 +
  672 + <span class="comment">// Ensure server</span>
  673 + <span class="keyword">if</span> (!<span class="variable">server</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'no .server present'</span>);
  674 + ++<span class="variable">server</span>.<span class="variable">pending</span>;
  675 +
  676 + <span class="comment">// HTTP client</span>
  677 + <span class="comment">// TODO: options for headers, request body etc</span>
  678 + <span class="keyword">if</span> (!<span class="variable">server</span>.<span class="variable">fd</span>) {
  679 + <span class="variable">server</span>.<span class="variable">listen</span>(++<span class="variable">port</span>, <span class="variable">host</span>);
  680 + <span class="variable">server</span>.<span class="variable">client</span> = <span class="variable">http</span>.<span class="variable">createClient</span>(<span class="variable">port</span>);
  681 + }
  682 +
  683 + <span class="comment">// Save history</span>
  684 + <span class="keyword">if</span> (<span class="variable">false</span> !== <span class="variable">saveHistory</span>) <span class="this">this</span>.<span class="variable">history</span>.<span class="variable">push</span>(<span class="variable">path</span>);
  685 +
  686 + <span class="comment">// Cookies</span>
  687 + <span class="keyword">var</span> <span class="variable">cookies</span> = <span class="this">this</span>.<span class="variable">cookieJar</span>.<span class="variable">get</span>({ <span class="variable">url</span>: <span class="variable">path</span> });
  688 + <span class="keyword">if</span> (<span class="variable">cookies</span>.<span class="variable">length</span>) {
  689 + <span class="variable">headers</span>.<span class="class">Cookie</span> = <span class="variable">cookies</span>.<span class="variable">map</span>(<span class="keyword">function</span>(<span class="variable">cookie</span>){
  690 + <span class="keyword">return</span> <span class="variable">cookie</span>.<span class="variable">name</span> + <span class="string">'='</span> + <span class="variable">cookie</span>.<span class="variable">value</span>;
  691 + }).<span class="variable">join</span>(<span class="string">'; '</span>);
  692 + }
  693 +
  694 + <span class="comment">// Request</span>
  695 + <span class="variable">headers</span>.<span class="class">Host</span> = <span class="variable">host</span>;
  696 + <span class="keyword">var</span> <span class="variable">req</span> = <span class="variable">server</span>.<span class="variable">client</span>.<span class="variable">request</span>(<span class="variable">method</span>, <span class="variable">path</span>, <span class="variable">headers</span>);
  697 + <span class="variable">req</span>.<span class="variable">on</span>(<span class="string">'response'</span>, <span class="keyword">function</span>(<span class="variable">res</span>){
  698 + <span class="keyword">var</span> <span class="variable">status</span> = <span class="variable">res</span>.<span class="variable">statusCode</span>
  699 + , <span class="variable">buf</span> = <span class="string">''</span>;
  700 +
  701 + <span class="comment">// Cookies</span>
  702 + <span class="keyword">if</span> (<span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'set-cookie'</span>]) {
  703 + <span class="variable">self</span>.<span class="variable">cookieJar</span>.<span class="variable">add</span>(<span class="keyword">new</span> <span class="class">Cookie</span>(<span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'set-cookie'</span>]));
  704 + }
  705 +
  706 + <span class="comment">// Success</span>
  707 + <span class="keyword">if</span> (<span class="variable">status</span> &<span class="variable">gt</span>;= <span class="number integer">200</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">status</span> &<span class="variable">lt</span>; <span class="number integer">300</span>) {
  708 + <span class="keyword">var</span> <span class="variable">contentType</span> = <span class="variable">res</span>.<span class="variable">headers</span>[<span class="string">'content-type'</span>];
  709 +
  710 + <span class="comment">// JSON support</span>
  711 + <span class="keyword">if</span> (~<span class="variable">contentType</span>.<span class="variable">indexOf</span>(<span class="string">'json'</span>)) {
  712 + <span class="variable">res</span>.<span class="variable">body</span> = <span class="string">''</span>;
  713 + <span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">res</span>.<span class="variable">body</span> += <span class="variable">chunk</span>; });
  714 + <span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
  715 + <span class="keyword">try</span> {
  716 + <span class="variable">res</span>.<span class="variable">body</span> = <span class="class">JSON</span>.<span class="variable">parse</span>(<span class="variable">res</span>.<span class="variable">body</span>);
  717 + <span class="variable">fn</span>(<span class="variable">res</span>);
  718 + } <span class="keyword">catch</span> (<span class="variable">err</span>) {
  719 + <span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'error'</span>, <span class="variable">err</span>);
  720 + }
  721 + });
  722 + <span class="keyword">return</span>;
  723 + }
  724 +
  725 + <span class="comment">// Ensure html</span>
  726 + <span class="keyword">if</span> (!~<span class="variable">contentType</span>.<span class="variable">indexOf</span>(<span class="string">'text/html'</span>)) {
  727 + <span class="keyword">return</span> <span class="variable">fn</span>(<span class="variable">res</span>);
  728 + }
  729 +
  730 + <span class="comment">// Buffer html</span>
  731 + <span class="variable">res</span>.<span class="variable">setEncoding</span>(<span class="string">'utf8'</span>);
  732 + <span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'data'</span>, <span class="keyword">function</span>(<span class="variable">chunk</span>){ <span class="variable">buf</span> += <span class="variable">chunk</span>; });
  733 + <span class="variable">res</span>.<span class="variable">on</span>(<span class="string">'end'</span>, <span class="keyword">function</span>(){
  734 + <span class="variable">self</span>.<span class="variable">parse</span>(<span class="variable">buf</span>);
  735 + <span class="variable">fn</span>(<span class="variable">res</span>, <span class="keyword">function</span>(<span class="variable">selector</span>){
  736 + <span class="keyword">return</span> <span class="variable">self</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>);
  737 + });
  738 + });
  739 +
  740 + <span class="comment">// Redirect</span>
  741 + } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">status</span> &<span class="variable">gt</span>;= <span class="number integer">300</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">status</span> &<span class="variable">lt</span>; <span class="number integer">400</span>) {
  742 + <span class="keyword">var</span> <span class="variable">location</span> = <span class="variable">res</span>.<span class="variable">headers</span>.<span class="variable">location</span>;
  743 + <span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'redirect'</span>, <span class="variable">location</span>);
  744 + <span class="variable">self</span>.<span class="variable">request</span>(<span class="string">'GET'</span>, <span class="variable">location</span>, <span class="variable">options</span>, <span class="variable">fn</span>);
  745 +
  746 + <span class="comment">// Error</span>
  747 + } <span class="keyword">else</span> {
  748 + <span class="keyword">var</span> <span class="variable">err</span> = <span class="keyword">new</span> <span class="class">Error</span>(
  749 + <span class="variable">method</span> + <span class="string">' '</span> + <span class="variable">path</span>
  750 + + <span class="string">' responded with '</span>
  751 + + <span class="variable">status</span> + <span class="string">' &quot;'</span> + <span class="variable">http</span>.<span class="class">STATUS_CODES</span>[<span class="variable">status</span>] + <span class="string">'&quot;'</span>);
  752 + <span class="variable">self</span>.<span class="variable">emit</span>(<span class="string">'error'</span>, <span class="variable">err</span>);
  753 + }
  754 + });
  755 +
  756 + <span class="variable">req</span>.<span class="variable">end</span>(<span class="variable">options</span>.<span class="variable">body</span>);
  757 +
  758 + <span class="keyword">return</span> <span class="this">this</span>;
  759 +};</code></pre>
  760 +</td>
  761 +</tr>
  762 +<tr class="code">
  763 +<td class="docs">
  764 +<p>GET <code>path</code> and callback <code>fn(jQuery)</code>.</p>
  765 +
  766 +<h2></h2>
  767 +
  768 +<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>Object | Function</em> options or fn</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  769 +</td>
  770 +<td class="code">
  771 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">get</span> =
  772 +<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">visit</span> =
  773 +<span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">open</span> = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
  774 + <span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">options</span>) {
  775 + <span class="variable">saveHistory</span> = <span class="variable">fn</span>;
  776 + <span class="variable">fn</span> = <span class="variable">options</span>;
  777 + <span class="variable">options</span> = {};
  778 + }
  779 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">request</span>(<span class="string">'GET'</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>);
  780 +};</code></pre>
  781 +</td>
  782 +</tr>
  783 +<tr class="code">
  784 +<td class="docs">
  785 +<p>POST <code>path</code> and callback <code>fn(jQuery)</code>.</p>
  786 +
  787 +<h2></h2>
  788 +
  789 +<ul><li><p><strong>param</strong>: <em>String</em> path</p></li><li><p><strong>param</strong>: <em>Object | Function</em> options or fn</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  790 +</td>
  791 +<td class="code">
  792 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">post</span> = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>){
  793 + <span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">options</span>) {
  794 + <span class="variable">saveHistory</span> = <span class="variable">fn</span>;
  795 + <span class="variable">fn</span> = <span class="variable">options</span>;
  796 + <span class="variable">options</span> = {};
  797 + }
  798 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">request</span>(<span class="string">'POST'</span>, <span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>, <span class="variable">saveHistory</span>);
  799 +};</code></pre>
  800 +</td>
  801 +</tr>
  802 +<tr class="code">
  803 +<td class="docs">
  804 +<p>GET the last page visited, or the nth previous page.</p>
  805 +
  806 +<h2></h2>
  807 +
  808 +<ul><li><p><strong>param</strong>: <em>Number</em> n</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  809 +</td>
  810 +<td class="code">
  811 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">back</span> = <span class="keyword">function</span>(<span class="variable">n</span>, <span class="variable">fn</span>){
  812 + <span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">n</span>) <span class="variable">fn</span> = <span class="variable">n</span>, <span class="variable">n</span> = <span class="number integer">1</span>;
  813 + <span class="keyword">while</span> (<span class="variable">n</span>--) <span class="this">this</span>.<span class="variable">history</span>.<span class="variable">pop</span>();
  814 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">get</span>(<span class="this">this</span>.<span class="variable">path</span>, <span class="variable">fn</span>, <span class="variable">false</span>);
  815 +};</code></pre>
  816 +</td>
  817 +</tr>
  818 +<tr class="code">
  819 +<td class="docs">
  820 +<p>Locate elements via the given <code>selector</code> and <code>locator</code> supporting:</p>
  821 +
  822 +<ul><li>element text</li><li>element name attribute</li><li>css selector</li></ul>
  823 +
  824 +<h2></h2>
  825 +
  826 +<ul><li><p><strong>param</strong>: <em>String</em> selector</p></li><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>jQuery</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  827 +</td>
  828 +<td class="code">
  829 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">locate</span> = <span class="keyword">function</span>(<span class="variable">selector</span>, <span class="variable">locator</span>){
  830 + <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>
  831 + , $ = <span class="this">this</span>.<span class="variable">jQuery</span>;
  832 + <span class="keyword">var</span> <span class="variable">elems</span> = <span class="this">this</span>.<span class="variable">context</span>.<span class="variable">find</span>(<span class="variable">selector</span>).<span class="variable">filter</span>(<span class="keyword">function</span>(){
  833 + <span class="keyword">var</span> <span class="variable">elem</span> = $(<span class="this">this</span>);
  834 + <span class="keyword">return</span> <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">text</span>()
  835 + || <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'id'</span>)
  836 + || <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'value'</span>)
  837 + || <span class="variable">locator</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'name'</span>)
  838 + || <span class="variable">elem</span>.<span class="variable">is</span>(<span class="variable">locator</span>);
  839 + });
  840 + <span class="keyword">if</span> (<span class="variable">elems</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; !<span class="variable">elems</span>.<span class="variable">length</span>) <span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'failed to locate &quot;'</span> + <span class="variable">locator</span> + <span class="string">'&quot; in context of selector &quot;'</span> + <span class="variable">selector</span> + <span class="string">'&quot;'</span>);
  841 + <span class="keyword">return</span> <span class="variable">elems</span>;
  842 +};</code></pre>
  843 +</td>
  844 +</tr>
  845 +<tr class="code">
  846 +<td class="docs">
  847 +<p>Return the current path.</p>
  848 +
  849 +<h2></h2>
  850 +
  851 +<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  852 +</td>
  853 +<td class="code">
  854 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">__defineGetter__</span>(<span class="string">'path'</span>, <span class="keyword">function</span>(){
  855 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">history</span>[<span class="this">this</span>.<span class="variable">history</span>.<span class="variable">length</span> - <span class="number integer">1</span>];
  856 +});</code></pre>
  857 +</td>
  858 +</tr>
  859 +<tr class="code">
  860 +<td class="docs">
  861 +<p>Click the given <code>locator</code> and callback <code>fn(res)</code>.</p>
  862 +
  863 +<h2></h2>
  864 +
  865 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  866 +</td>
  867 +<td class="code">
  868 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">click</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fn</span>){
  869 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':submit, :button, a'</span>, <span class="variable">locator</span>)).<span class="variable">click</span>(<span class="variable">fn</span>, <span class="variable">locator</span>);
  870 +};</code></pre>
  871 +</td>
  872 +</tr>
  873 +<tr class="code">
  874 +<td class="docs">
  875 +<p>Assign <code>val</code> to the given <code>locator</code>.</p>
  876 +
  877 +<h2></h2>
  878 +
  879 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>String</em> val</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  880 +</td>
  881 +<td class="code">
  882 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">type</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">val</span>){
  883 + <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'input, textarea'</span>, <span class="variable">locator</span>)).<span class="variable">val</span>(<span class="variable">val</span>);
  884 + <span class="keyword">return</span> <span class="this">this</span>;
  885 +};</code></pre>
  886 +</td>
  887 +</tr>
  888 +<tr class="code">
  889 +<td class="docs">
  890 +<p>Uncheck the checkbox with the given <code>locator</code>.</p>
  891 +
  892 +<h2></h2>
  893 +
  894 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  895 +</td>
  896 +<td class="code">
  897 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">uncheck</span> = <span class="keyword">function</span>(<span class="variable">locator</span>){
  898 + <span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':checkbox'</span>, <span class="variable">locator</span>)[<span class="number integer">0</span>].<span class="variable">removeAttribute</span>(<span class="string">'checked'</span>);
  899 + <span class="keyword">return</span> <span class="this">this</span>;
  900 +};</code></pre>
  901 +</td>
  902 +</tr>
  903 +<tr class="code">
  904 +<td class="docs">
  905 +<p>Check the checkbox with the given <code>locator</code>.</p>
  906 +
  907 +<h2></h2>
  908 +
  909 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  910 +</td>
  911 +<td class="code">
  912 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">check</span> = <span class="keyword">function</span>(<span class="variable">locator</span>){
  913 + <span class="this">this</span>.<span class="variable">locate</span>(<span class="string">':checkbox'</span>, <span class="variable">locator</span>)[<span class="number integer">0</span>].<span class="variable">setAttribute</span>(<span class="string">'checked'</span>, <span class="string">'checked'</span>);
  914 + <span class="keyword">return</span> <span class="this">this</span>;
  915 +};</code></pre>
  916 +</td>
  917 +</tr>
  918 +<tr class="code">
  919 +<td class="docs">
  920 +<p>Select <code>options</code> at <code>locator</code>.</p>
  921 +
  922 +<h2></h2>
  923 +
  924 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>String | Array</em> select</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  925 +</td>
  926 +<td class="code">
  927 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">select</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">options</span>){
  928 + <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'select'</span>, <span class="variable">locator</span>)).<span class="variable">select</span>(<span class="variable">options</span>);
  929 + <span class="keyword">return</span> <span class="this">this</span>;
  930 +};</code></pre>
  931 +</td>
  932 +</tr>
  933 +<tr class="code">
  934 +<td class="docs">
  935 +<p>Submit form at the optional <code>locator</code> and callback <code>fn(res)</code>.</p>
  936 +
  937 +<h2></h2>
  938 +
  939 +<ul><li><p><strong>param</strong>: <em>String | Function</em> locator</p></li><li><p><strong>param</strong>: <em>Function</em> fn</p></li><li><p><strong>return</strong>: <em>Browser</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  940 +</td>
  941 +<td class="code">
  942 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">submit</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fn</span>){
  943 + <span class="keyword">if</span> (<span class="string">'function'</span> == <span class="keyword">typeof</span> <span class="variable">locator</span>) {
  944 + <span class="variable">fn</span> = <span class="variable">locator</span>;
  945 + <span class="variable">locator</span> = <span class="string">'*'</span>;
  946 + }
  947 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'form'</span>, <span class="variable">locator</span>)).<span class="variable">submit</span>(<span class="variable">fn</span>, <span class="variable">locator</span>);
  948 +};</code></pre>
  949 +</td>
  950 +</tr>
  951 +<tr class="code">
  952 +<td class="docs">
  953 +<p>Fill the given form <code>fields</code> and optional <code>locator</code>.</p>
  954 +
  955 +<h2></h2>
  956 +
  957 +<ul><li><p><strong>param</strong>: <em>String</em> locator</p></li><li><p><strong>param</strong>: <em>Object</em> fields</p></li><li><p><strong>return</strong>: <em>Assertion</em> for chaining</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  958 +</td>
  959 +<td class="code">
  960 +<pre><code><span class="class">Browser</span>.<span class="variable">prototype</span>.<span class="variable">fill</span> = <span class="keyword">function</span>(<span class="variable">locator</span>, <span class="variable">fields</span>){
  961 + <span class="keyword">if</span> (<span class="string">'object'</span> == <span class="keyword">typeof</span> <span class="variable">locator</span>) {
  962 + <span class="variable">fields</span> = <span class="variable">locator</span>;
  963 + <span class="variable">locator</span> = <span class="string">'*'</span>;
  964 + }
  965 + <span class="this">this</span>.<span class="variable">jQuery</span>(<span class="this">this</span>.<span class="variable">locate</span>(<span class="string">'form'</span>, <span class="variable">locator</span>)).<span class="variable">fill</span>(<span class="variable">fields</span>);
  966 + <span class="keyword">return</span> <span class="this">this</span>;
  967 +};</code></pre>
  968 +</td>
  969 +</tr>
  970 +<tr class="code">
  971 +<td class="docs">
  972 +<p>Ensure <code>html</code> / <code>body</code> tags exist.</p>
  973 +
  974 +<h2></h2>
  975 +
  976 +<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  977 +</td>
  978 +<td class="code">
  979 +<pre><code><span class="keyword">function</span> <span class="variable">wrap</span>(<span class="variable">html</span>) {
  980 + <span class="comment">// body</span>
  981 + <span class="keyword">if</span> (!~<span class="variable">html</span>.<span class="variable">indexOf</span>(<span class="string">'&lt;body'</span>)) {
  982 + <span class="variable">html</span> = <span class="string">'&lt;body&gt;'</span> + <span class="variable">html</span> + <span class="string">'&lt;/body&gt;'</span>;
  983 + }
  984 +
  985 + <span class="comment">// html</span>
  986 + <span class="keyword">if</span> (!~<span class="variable">html</span>.<span class="variable">indexOf</span>(<span class="string">'&lt;html'</span>)) {
  987 + <span class="variable">html</span> = <span class="string">'&lt;html&gt;'</span> + <span class="variable">html</span> + <span class="string">'&lt;/html&gt;'</span>;
  988 + }
  989 +
  990 + <span class="keyword">return</span> <span class="variable">html</span>;
  991 +}</code></pre>
  992 +</td>
  993 +</tr><tr class="filename"><td><h2 id="lib/cookie/index.js"><a href="#">index</a></h2></td><td>lib/cookie/index.js</td></tr><tr class="code">
  994 +<td class="docs">
  995 +<p>Module dependencies.
  996 + </p>
  997 +</td>
  998 +<td class="code">
  999 +<pre><code><span class="keyword">var</span> <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>);</code></pre>
  1000 +</td>
  1001 +</tr>
  1002 +<tr class="code">
  1003 +<td class="docs">
  1004 +<p>Initialize a new <code>Cookie</code> with the given cookie <code>str</code> and <code>req</code>.</p>
  1005 +
  1006 +<h2></h2>
  1007 +
  1008 +<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>IncomingRequest</em> req</p></li><li><p><strong>api</strong>: <em>private</em></p></li></ul>
  1009 +</td>
  1010 +<td class="code">
  1011 +<pre><code><span class="keyword">var</span> <span class="class">Cookie</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">Cookie</span>(<span class="variable">str</span>, <span class="variable">req</span>) {
  1012 + <span class="this">this</span>.<span class="variable">str</span> = <span class="variable">str</span>;
  1013 +
  1014 + <span class="comment">// First key is the name</span>
  1015 + <span class="this">this</span>.<span class="variable">name</span> = <span class="variable">str</span>.<span class="variable">substr</span>(<span class="number integer">0</span>, <span class="variable">str</span>.<span class="variable">indexOf</span>(<span class="string">'='</span>));
  1016 +
  1017 + <span class="comment">// Map the key/val pairs</span>
  1018 + <span class="variable">str</span>.<span class="variable">split</span>(<span class="regexp">/ *; */</span>).<span class="variable">reduce</span>(<span class="keyword">function</span>(<span class="variable">obj</span>, <span class="variable">pair</span>){
  1019 + <span class="variable">pair</span> = <span class="variable">pair</span>.<span class="variable">split</span>(<span class="regexp">/ *= */</span>);
  1020 + <span class="variable">obj</span>[<span class="variable">pair</span>[<span class="number integer">0</span>]] = <span class="variable">pair</span>[<span class="number integer">1</span>] || <span class="variable">true</span>;
  1021 + <span class="keyword">return</span> <span class="variable">obj</span>;
  1022 + }, <span class="this">this</span>);
  1023 +
  1024 + <span class="comment">// Assign value</span>
  1025 + <span class="this">this</span>.<span class="variable">value</span> = <span class="this">this</span>[<span class="this">this</span>.<span class="variable">name</span>];
  1026 +
  1027 + <span class="comment">// Expires</span>
  1028 + <span class="this">this</span>.<span class="variable">expires</span> = <span class="this">this</span>.<span class="variable">expires</span>
  1029 + ? <span class="keyword">new</span> <span class="class">Date</span>(<span class="this">this</span>.<span class="variable">expires</span>)
  1030 + : <span class="class">Infinity</span>;
  1031 +
  1032 + <span class="comment">// Default or trim path</span>
  1033 + <span class="this">this</span>.<span class="variable">path</span> = <span class="this">this</span>.<span class="variable">path</span>
  1034 + ? <span class="this">this</span>.<span class="variable">path</span>.<span class="variable">trim</span>()
  1035 + : <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">pathname</span>;
  1036 +};</code></pre>
  1037 +</td>
  1038 +</tr>
  1039 +<tr class="code">
  1040 +<td class="docs">
  1041 +<p>Return the original cookie string.</p>
  1042 +
  1043 +<h2></h2>
  1044 +
  1045 +<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  1046 +</td>
  1047 +<td class="code">
  1048 +<pre><code><span class="class">Cookie</span>.<span class="variable">prototype</span>.<span class="variable">toString</span> = <span class="keyword">function</span>(){
  1049 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">str</span>;
  1050 +};
  1051 +</code></pre>
  1052 +</td>
  1053 +</tr><tr class="filename"><td><h2 id="lib/cookie/jar.js"><a href="#">jar</a></h2></td><td>lib/cookie/jar.js</td></tr><tr class="code">
  1054 +<td class="docs">
  1055 +<p>Module dependencies.
  1056 + </p>
  1057 +</td>
  1058 +<td class="code">
  1059 +<pre><code><span class="keyword">var</span> <span class="variable">url</span> = <span class="variable">require</span>(<span class="string">'url'</span>);</code></pre>
  1060 +</td>
  1061 +</tr>
  1062 +<tr class="code">
  1063 +<td class="docs">
  1064 +<p>Initialize a new <code>CookieJar</code>.</p>
  1065 +
  1066 +<ul><li><p><strong>api</strong>: <em>private</em></p></li></ul>
  1067 +</td>
  1068 +<td class="code">
  1069 +<pre><code><span class="keyword">var</span> <span class="class">CookieJar</span> = <span class="variable">exports</span> = <span class="variable">module</span>.<span class="variable">exports</span> = <span class="keyword">function</span> <span class="class">CookieJar</span>() {
  1070 + <span class="this">this</span>.<span class="variable">cookies</span> = [];
  1071 +};</code></pre>
  1072 +</td>
  1073 +</tr>
  1074 +<tr class="code">
  1075 +<td class="docs">
  1076 +<p>Add the given <code>cookie</code> to the jar.</p>
  1077 +
  1078 +<h2></h2>
  1079 +
  1080 +<ul><li><p><strong>param</strong>: <em>Cookie</em> cookie</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
  1081 +</td>
  1082 +<td class="code">
  1083 +<pre><code><span class="class">CookieJar</span>.<span class="variable">prototype</span>.<span class="variable">add</span> = <span class="keyword">function</span>(<span class="variable">cookie</span>){
  1084 + <span class="this">this</span>.<span class="variable">cookies</span>.<span class="variable">push</span>(<span class="variable">cookie</span>);
  1085 +};
  1086 +
  1087 +<span class="class">CookieJar</span>.<span class="variable">prototype</span>.<span class="variable">get</span> = <span class="keyword">function</span>(<span class="variable">req</span>){
  1088 + <span class="keyword">var</span> <span class="variable">path</span> = <span class="variable">url</span>.<span class="variable">parse</span>(<span class="variable">req</span>.<span class="variable">url</span>).<span class="variable">pathname</span>
  1089 + , <span class="variable">now</span> = <span class="keyword">new</span> <span class="class">Date</span>;
  1090 + <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">cookies</span>.<span class="variable">filter</span>(<span class="keyword">function</span>(<span class="variable">cookie</span>){
  1091 + <span class="keyword">return</span> <span class="number integer">0</span> == <span class="variable">path</span>.<span class="variable">indexOf</span>(<span class="variable">cookie</span>.<span class="variable">path</span>)
  1092 + &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">now</span> &<span class="variable">lt</span>; <span class="variable">cookie</span>.<span class="variable">expires</span>;
  1093 + });
  1094 +};
  1095 +
  1096 +</code></pre>
  1097 +</td>
  1098 +</tr><tr class="filename"><td><h2 id="lib/jquery/fill.js"><a href="#">fill</a></h2></td><td>lib/jquery/fill.js</td></tr><tr class="code">
  1099 +<td class="docs">
  1100 +<p>Select options.
  1101 + </p>
  1102 +</td>
  1103 +<td class="code">
  1104 +<pre><code><span class="variable">exports</span>.<span class="variable">select</span> = <span class="keyword">function</span>($, <span class="variable">elems</span>, <span class="variable">val</span>){
  1105 + <span class="variable">elems</span>.<span class="variable">select</span>(<span class="variable">val</span>);
  1106 +};</code></pre>
  1107 +</td>
  1108 +</tr>
  1109 +<tr class="code">
  1110 +<td class="docs">
  1111 +<p>Fill inputs:</p>
  1112 +
  1113 +<ul><li>toggle radio buttons</li><li>check checkboxes</li><li><p>default to .val(val)</p></li></ul>
  1114 +</td>
  1115 +<td class="code">
  1116 +<pre><code><span class="variable">exports</span>.<span class="variable">input</span> = <span class="keyword">function</span>($, <span class="variable">elems</span>, <span class="variable">val</span>){
  1117 + <span class="keyword">switch</span> (<span class="variable">elems</span>.<span class="variable">attr</span>(<span class="string">'type'</span>)) {
  1118 + <span class="keyword">case</span> <span class="string">'radio'</span>:
  1119 + <span class="variable">elems</span>.<span class="variable">each</span>(<span class="keyword">function</span>(){
  1120 + <span class="keyword">var</span> <span class="variable">elem</span> = $(<span class="this">this</span>);
  1121 + <span class="variable">val</span> == <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'value'</span>)
  1122 + ? <span class="variable">elem</span>.<span class="variable">attr</span>(<span class="string">'checked'</span>, <span class="variable">true</span>)
  1123 + : <span class="variable">elem</span>.<span class="variable">removeAttr</span>(<span class="string">'checked'</span>);
  1124 + });
  1125 + <span class="keyword">break</span>;
  1126 + <span class="keyword">case</span> <span class="string">'checkbox'</span>:
  1127 + <span class="variable">val</span>
  1128 + ? <span class="variable">elems</span>.<span class="variable">attr</span>(<span class="string">'checked'</span>, <span class="variable">true</span>)
  1129 + : <span class="variable">elems</span>.<span class="variable">removeAttr</span>(<span class="string">'checked'</span>);
  1130 + <span class="keyword">break</span>;
  1131 + <span class="keyword">default</span>:
  1132 + <span class="variable">elems</span>.<span class="variable">val</span>(<span class="variable">val</span>);
  1133 + }
  1134 +};</code></pre>
  1135 +</td>
  1136 +</tr>
  1137 +<tr class="code">
  1138 +<td class="docs">
  1139 +<p>Fill textarea.
  1140 + </p>
  1141 +</td>
  1142 +<td class="code">