Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rebuilt docs

  • Loading branch information...
commit 43412a227ae158b643b66423831808ea3eaab102 1 parent 88630cb
@tj tj authored
Showing with 197 additions and 142 deletions.
  1. +197 −142 api.html
View
339 api.html
@@ -1,6 +1,7 @@
<html>
<head>
<title>Jade</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style>body {
margin: 0;
padding: 0;
@@ -21,45 +22,6 @@
margin: 0;
padding: 0;
}
-ul#menu {
- opacity: 0;
- position: fixed;
- top: 0;
- right: 0;
- list-style: none;
- margin: 0;
- padding: 10px 2px;
- text-align: right;
- background: rgba(255,255,255,0.7);
- -webkit-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
- -moz-box-shadow: -1px 2px 2px rgba(0,0,0,0.3);
- -webkit-border-bottom-left-radius: 5px;
- -moz-border-bottom-left-radius: 5px;
- -webkit-transition-properties: opacity;
- -webkit-transition-duration: 0.6s;
-}
-ul#menu:hover {
- opacity: 1;
-}
-ul#menu li {
- padding: 2px 10px;
- border-bottom: 1px solid #eee;
-}
-ul#menu li:hover {
- background: rgba(0,0,0,0.03);
-}
-ul#menu li:last-child {
- border-bottom: none;
-}
-ul#menu li a {
- text-decoration: none;
- font-size: 12px;
- color: rgba(0,0,0,0.5);
-}
-ul#menu li a strong {
- font-weight: normal;
- color: #252519;
-}
table#source {
width: 100%;
border-collapse: collapse;
@@ -93,6 +55,7 @@
table#source tr.filename h2 {
margin: 0;
padding: 0;
+ cursor: pointer;
}
table#source tr.code h1,
table#source tr.code h2,
@@ -123,7 +86,7 @@
padding: 20px;
}
#ribbon {
- position: absolute;
+ position: fixed;
top: 0;
right: 0;
}
@@ -133,19 +96,31 @@
code .number { color: #19469D; }
code .comment { color: #bbb; }
code .this { color: #19469D; }</style>
+ <script>
+ $(function(){
+ $('tr.code').hide();
+ $('tr.filename').toggle(function(){
+ $(this).nextUntil('.filename').fadeIn();
+ }, function(){
+ $(this).nextUntil('.filename').fadeOut();
+ });
+ });
+ </script>
</head>
<body>
-<ul id="menu"><li><a href="#lib/jade.js">lib/<strong>jade</strong></a></li></ul><table id="source"><tbody><tr><td><h1>Jade</h1><p>Jade is a high performance template engine for <a href="http://nodejs.org">node</a>, inspired by <a href="http://haml-lang.com/">haml</a>, created by <a href="http://github.com/visionmedia">TJ Holowaychuk</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/jade.js">jade</h2></td><td>lib/jade.js</td></tr><tr class="code">
+<table id="source"><tbody><tr><td><h1>Jade</h1><p>Jade is a high performance template engine for <a href="http://nodejs.org">node</a>, inspired by <a href="http://haml-lang.com/">haml</a>, created by <a href="http://github.com/visionmedia">TJ Holowaychuk</a>.</p></td><td></td></tr><tr class="filename"><td><h2 id="lib/jade.js"><a href="#">jade</a></h2></td><td>lib/jade.js</td></tr><tr class="code">
<td class="docs">
-<p>Library version.</p>
+<p>Library version.
+ </p>
</td>
<td class="code">
-<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.0.1'</span>;</code></pre>
+<pre><code><span class="variable">exports</span>.<span class="variable">version</span> = <span class="string">'0.2.2'</span>;</code></pre>
</td>
</tr>
<tr class="code">
<td class="docs">
-<p>Module dependencies.</p>
+<p>Module dependencies.
+ </p>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">sys</span> = <span class="variable">require</span>(<span class="string">'sys'</span>),
@@ -156,10 +131,7 @@
<td class="docs">
<p>Intermediate JavaScript cache.</p>
-<ul>
-<li><strong>type</strong>: <em>Object</em></li>
-</ul>
-
+<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">cache</span> = <span class="variable">exports</span>.<span class="variable">cache</span> = {};</code></pre>
@@ -169,10 +141,7 @@
<td class="docs">
<p>Self closing tags.</p>
-<ul>
-<li><strong>type</strong>: <em>Object</em></li>
-</ul>
-
+<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">selfClosing</span> = <span class="variable">exports</span>.<span class="variable">selfClosing</span> = [
@@ -191,10 +160,7 @@
<td class="docs">
<p>Default supported doctypes.</p>
-<ul>
-<li><strong>type</strong>: <em>Object</em></li>
-</ul>
-
+<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">doctypes</span> = <span class="variable">exports</span>.<span class="variable">doctypes</span> = {
@@ -214,10 +180,7 @@
<td class="docs">
<p>Filters.</p>
-<ul>
-<li><strong>type</strong>: <em>Object</em></li>
-</ul>
-
+<ul><li><p><strong>type</strong>: <em>Object</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">var</span> <span class="variable">filters</span> = <span class="variable">exports</span>.<span class="variable">filters</span> = {</code></pre>
@@ -225,7 +188,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Wrap text with CDATA block.</p>
+<p>Wrap text with CDATA block.
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">cdata</span>: <span class="keyword">function</span>(<span class="variable">str</span>){
@@ -235,7 +199,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Wrap text with script and CDATA tags.</p>
+<p>Wrap text with script and CDATA tags.
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">javascript</span>: <span class="keyword">function</span>(<span class="variable">str</span>){
@@ -245,7 +210,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Transform sass to css, wrapped in style tags.</p>t and CDAT
+<p>Transform sass to css, wrapped in style tags.
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">sass</span>: <span class="keyword">function</span>(<span class="variable">str</span>){
@@ -257,12 +223,32 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Transform markdown to html.</p>in style tags.
+<p>Transform sass to css, wrapped in style tags.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="variable">less</span>: <span class="keyword">function</span>(<span class="variable">str</span>){
+ <span class="keyword">var</span> <span class="variable">less</span>;
+ <span class="variable">str</span> = <span class="variable">str</span>.<span class="variable">replace</span>(<span class="regexp">/\\n/g</span>, <span class="string">'\n'</span>);
+ <span class="variable">require</span>(<span class="string">'less'</span>).<span class="variable">render</span>(<span class="variable">str</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">css</span>){
+ <span class="variable">less</span> = <span class="string">'&lt;style&gt;'</span> + <span class="variable">css</span>.<span class="variable">replace</span>(<span class="regexp">/\n/g</span>, <span class="string">'\\n'</span>) + <span class="string">'&lt;/style&gt;'</span>;
+ });
+ <span class="keyword">return</span> <span class="variable">less</span>;
+ },</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>Transform markdown to html.
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">markdown</span>: <span class="keyword">function</span>(<span class="variable">str</span>){
+ <span class="keyword">var</span> <span class="variable">md</span> = <span class="variable">require</span>(<span class="string">'markdown'</span>);
<span class="variable">str</span> = <span class="variable">str</span>.<span class="variable">replace</span>(<span class="regexp">/\\n/g</span>, <span class="string">'\n'</span>);
- <span class="keyword">return</span> <span class="variable">require</span>(<span class="string">'markdown'</span>).<span class="variable">parse</span>(<span class="variable">str</span>).<span class="variable">replace</span>(<span class="regexp">/\n/g</span>, <span class="string">'\\n'</span>);
+ <span class="keyword">return</span> (<span class="variable">md</span>.<span class="variable">toHTML</span>
+ ? <span class="variable">md</span>.<span class="variable">toHTML</span>(<span class="variable">str</span>)
+ : <span class="variable">md</span>.<span class="variable">parse</span>(<span class="variable">str</span>)).<span class="variable">replace</span>(<span class="regexp">/\n/g</span>, <span class="string">'\\n'</span>).<span class="variable">replace</span>(<span class="regexp">/'/g</span>,<span class="string">'&amp;#39;'</span>);
}
};</code></pre>
</td>
@@ -273,12 +259,7 @@
<h2></h2>
-<ul>
-<li><p><strong>param</strong>: <em>String</em> str</p></li>
-<li><p><strong>param</strong>: <em>String</em> filename</p></li>
-<li><p><strong>api</strong>: <em>public</em></p></li>
-</ul>
-
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>String</em> filename</p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="class">Parser</span>(<span class="variable">str</span>, <span class="variable">filename</span>){
@@ -292,7 +273,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Parser prototype.</p>
+<p>Parser prototype.
+ </p>
</td>
<td class="code">
<pre><code><span class="class">Parser</span>.<span class="variable">prototype</span> = {</code></pre>
@@ -300,7 +282,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>Generate token object.</p>
+<p>Generate token object.
+ </p>
</td>
<td class="code">
<pre><code><span class="keyword">function</span> <span class="variable">token</span>(<span class="variable">type</span>){
@@ -330,6 +313,15 @@
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^:(\w+)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">input</span>)) {
<span class="keyword">return</span> <span class="variable">token</span>(<span class="string">'filter'</span>);
}
+
+ <span class="comment">// Each</span>
+ <span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^- *each *(\w+)(?: *, *(\w+))? * in *([^\n]+)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">input</span>)) {
+ <span class="keyword">var</span> <span class="variable">tok</span> = <span class="variable">token</span>(<span class="string">'each'</span>);
+ <span class="variable">tok</span>.<span class="variable">val</span> = <span class="variable">captures</span>[<span class="number integer">1</span>];
+ <span class="variable">tok</span>.<span class="variable">key</span> = <span class="variable">captures</span>[<span class="number integer">2</span>] || <span class="string">'index'</span>;
+ <span class="variable">tok</span>.<span class="variable">code</span> = <span class="variable">captures</span>[<span class="number integer">3</span>];
+ <span class="keyword">return</span> <span class="variable">tok</span>;
+ }
<span class="comment">// Code</span>
<span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^(!?=|-)([^\n]+)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">input</span>)) {
@@ -357,13 +349,31 @@
}
<span class="comment">// Attributes</span>
- <span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^\(([^\)]+)\)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">input</span>)) {
+ <span class="keyword">if</span> (<span class="variable">captures</span> = <span class="regexp">/^\( *(.+) *\)/</span>.<span class="variable">exec</span>(<span class="this">this</span>.<span class="variable">input</span>)) {
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="variable">token</span>(<span class="string">'attrs'</span>),
- <span class="variable">attrs</span> = <span class="variable">tok</span>.<span class="variable">val</span>.<span class="variable">split</span>(<span class="regexp">/ *, */</span>);
+ <span class="variable">attrs</span> = <span class="variable">tok</span>.<span class="variable">val</span>.<span class="variable">split</span>(<span class="regexp">/ *, *(?=[\w-]+ *[:=]|[\w-]+ *$)/</span>);
<span class="variable">tok</span>.<span class="variable">attrs</span> = {};
<span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">attrs</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
- <span class="keyword">var</span> <span class="variable">pair</span> = <span class="variable">attrs</span>[<span class="variable">i</span>].<span class="variable">split</span>(<span class="regexp">/ *[:=] */</span>);
- <span class="variable">tok</span>.<span class="variable">attrs</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="keyword">var</span> <span class="variable">pair</span> = <span class="variable">attrs</span>[<span class="variable">i</span>];
+
+ <span class="comment">// Support = and :</span>
+ <span class="keyword">var</span> <span class="variable">colon</span> = <span class="variable">pair</span>.<span class="variable">indexOf</span>(<span class="string">':'</span>),
+ <span class="variable">equal</span> = <span class="variable">pair</span>.<span class="variable">indexOf</span>(<span class="string">'='</span>);
+
+ <span class="comment">// Boolean</span>
+ <span class="keyword">if</span> (<span class="variable">colon</span> &<span class="variable">lt</span>; <span class="number integer">0</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">equal</span> &<span class="variable">lt</span>; <span class="number integer">0</span>) {
+ <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">pair</span>,
+ <span class="variable">val</span> = <span class="variable">true</span>;
+ } <span class="keyword">else</span> {
+ <span class="comment">// Split on first = or :</span>
+ <span class="keyword">var</span> <span class="variable">split</span> = <span class="variable">equal</span> &<span class="variable">gt</span>;= <span class="number integer">0</span>
+ ? <span class="variable">equal</span>
+ : <span class="variable">colon</span>;
+ <span class="keyword">if</span> (<span class="variable">colon</span> &<span class="variable">gt</span>;= <span class="number integer">0</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">colon</span> &<span class="variable">lt</span>; <span class="variable">equal</span>) <span class="variable">split</span> = <span class="variable">colon</span>;
+ <span class="keyword">var</span> <span class="variable">key</span> = <span class="variable">pair</span>.<span class="variable">substr</span>(<span class="number integer">0</span>, <span class="variable">split</span>),
+ <span class="variable">val</span> = <span class="variable">pair</span>.<span class="variable">substr</span>(++<span class="variable">split</span>, <span class="variable">pair</span>.<span class="variable">length</span>);
+ }
+ <span class="variable">tok</span>.<span class="variable">attrs</span>[<span class="variable">key</span>.<span class="variable">trim</span>().<span class="variable">replace</span>(<span class="regexp">/^['&quot;]|['&quot;]$/g</span>, <span class="string">''</span>)] = <span class="variable">val</span>;
}
<span class="keyword">return</span> <span class="variable">tok</span>;
}
@@ -373,7 +383,10 @@
++<span class="this">this</span>.<span class="variable">lineno</span>;
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="variable">token</span>(<span class="string">'indent'</span>),
<span class="variable">indents</span> = <span class="variable">tok</span>.<span class="variable">val</span>.<span class="variable">length</span> / <span class="number integer">2</span>;
- <span class="keyword">if</span> (<span class="variable">indents</span> % <span class="number integer">1</span> !== <span class="number integer">0</span>) {
+ <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">input</span>[<span class="number integer">0</span>] === <span class="string">'\n'</span>) {
+ <span class="variable">tok</span>.<span class="variable">type</span> = <span class="string">'newline'</span>;
+ <span class="keyword">return</span> <span class="variable">tok</span>;
+ } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="variable">indents</span> % <span class="number integer">1</span> !== <span class="number integer">0</span>) {
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'Invalid indentation, got '</span>
+ <span class="variable">tok</span>.<span class="variable">val</span>.<span class="variable">length</span> + <span class="string">' space'</span>
+ (<span class="variable">tok</span>.<span class="variable">val</span>.<span class="variable">length</span> &<span class="variable">gt</span>; <span class="number integer">1</span> ? <span class="string">'s'</span> : <span class="string">''</span>)
@@ -411,11 +424,7 @@
<h2></h2>
-<ul>
-<li><p><strong>return</strong>: <em>String</em></p></li>
-<li><p><strong>api</strong>: <em>public</em></p></li>
-</ul>
-
+<ul><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p><p> </p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">parse</span>: <span class="keyword">function</span>(){
@@ -436,8 +445,10 @@
| text
| filter
| doctype
+| each block
| code block?
-| expr newline</p>
+| expr newline
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseExpr</span>: <span class="keyword">function</span>(){
@@ -460,6 +471,8 @@
});
<span class="this">this</span>.<span class="variable">deferredTokens</span>.<span class="variable">push</span>(<span class="variable">tok</span>);
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">parseExpr</span>();
+ <span class="keyword">case</span> <span class="string">'each'</span>:
+ <span class="keyword">return</span> <span class="this">this</span>.<span class="variable">parseEach</span>();
<span class="keyword">case</span> <span class="string">'code'</span>:
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="this">this</span>.<span class="variable">advance</span>,
<span class="variable">val</span> = <span class="variable">tok</span>.<span class="variable">val</span>;
@@ -469,7 +482,7 @@
: <span class="variable">val</span>) + <span class="string">')'</span>
: <span class="variable">val</span>;
<span class="keyword">return</span> <span class="this">this</span>.<span class="variable">peek</span>.<span class="variable">type</span> === <span class="string">'indent'</span>
- ? <span class="variable">buf</span> + <span class="string">'\n(function(){'</span> + <span class="this">this</span>.<span class="variable">parseBlock</span>() + <span class="string">'})();'</span>
+ ? <span class="variable">buf</span> + <span class="string">'\n(function(){'</span> + <span class="this">this</span>.<span class="variable">parseBlock</span>() + <span class="string">'}).call(this);'</span>
: <span class="variable">buf</span> + <span class="string">';'</span>;
<span class="keyword">case</span> <span class="string">'newline'</span>:
<span class="this">this</span>.<span class="variable">advance</span>;
@@ -480,7 +493,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>doctype</p>
+<p>doctype
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseDoctype</span>: <span class="keyword">function</span>(){
@@ -492,14 +506,16 @@
</tr>
<tr class="code">
<td class="docs">
-<p>filter text</p>
+<p>filter text
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseFilter</span>: <span class="keyword">function</span>(){
<span class="keyword">var</span> <span class="variable">name</span> = <span class="this">this</span>.<span class="variable">expect</span>(<span class="string">'filter'</span>).<span class="variable">val</span>,
<span class="variable">filter</span> = <span class="variable">filters</span>[<span class="variable">name</span>];
<span class="keyword">if</span> (<span class="variable">filter</span>) {
- <span class="keyword">return</span> &<span class="variable">quot</span>;<span class="variable">buf</span>.<span class="variable">push</span>(<span class="string">'&quot; + filter(interpolate(this.parseTextBlock())) + &quot;'</span>);&<span class="variable">quot</span>;;
+ <span class="keyword">var</span> <span class="variable">text</span> = <span class="variable">interpolate</span>(<span class="this">this</span>.<span class="variable">parseTextBlock</span>().<span class="variable">replace</span>(<span class="regexp">/'/g</span>, &<span class="variable">quot</span>;\\'&<span class="variable">quot</span>;));
+ <span class="keyword">return</span> &<span class="variable">quot</span>;<span class="variable">buf</span>.<span class="variable">push</span>(<span class="string">'&quot; + filter(text) + &quot;'</span>);&<span class="variable">quot</span>;;
} <span class="keyword">else</span> {
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'unknown filter &quot;:'</span> + <span class="variable">name</span> + <span class="string">'&quot;'</span>);
}
@@ -508,7 +524,25 @@
</tr>
<tr class="code">
<td class="docs">
-<p>indent (text | newline)* outdent</p>
+<p>each block
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="variable">parseEach</span>: <span class="keyword">function</span>(){
+ <span class="keyword">var</span> <span class="variable">each</span> = <span class="this">this</span>.<span class="variable">expect</span>(<span class="string">'each'</span>);
+ <span class="keyword">var</span> <span class="variable">fn</span> = <span class="string">'('</span> + <span class="variable">iterate</span>
+ .<span class="variable">replace</span>(<span class="regexp">/__obj__/</span>, <span class="variable">each</span>.<span class="variable">code</span>)
+ .<span class="variable">replace</span>(<span class="regexp">/__val__/g</span>, <span class="variable">each</span>.<span class="variable">val</span>)
+ .<span class="variable">replace</span>(<span class="regexp">/__key__/g</span>, <span class="variable">each</span>.<span class="variable">key</span>)
+ .<span class="variable">replace</span>(<span class="regexp">/__block__/g</span>, <span class="this">this</span>.<span class="variable">parseBlock</span>()) + <span class="string">').call(this);'</span>;
+ <span class="keyword">return</span> <span class="variable">fn</span>;
+ },</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
+<p>indent (text | newline)* outdent
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseTextBlock</span>: <span class="keyword">function</span>(){
@@ -529,7 +563,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>indent expr* outdent</p>
+<p>indent expr* outdent
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseBlock</span>: <span class="keyword">function</span>(){
@@ -545,7 +580,8 @@
</tr>
<tr class="code">
<td class="docs">
-<p>tag (attrs | class | id)* (text | code | block)</p>
+<p>tag (attrs | class | id)* text? (code | block)
+ </p>
</td>
<td class="code">
<pre><code><span class="variable">parseTag</span>: <span class="keyword">function</span>(){
@@ -592,11 +628,13 @@
}
}
- <span class="comment">// (text | code | block)</span>
+ <span class="comment">// text?</span>
+ <span class="keyword">if</span> (<span class="this">this</span>.<span class="variable">peek</span>.<span class="variable">type</span> === <span class="string">'text'</span>) {
+ <span class="variable">buf</span>.<span class="variable">push</span>(&<span class="variable">quot</span>;<span class="variable">buf</span>.<span class="variable">push</span>(<span class="string">'&quot; + interpolate(this.advance.val.replace(/^ */, '</span><span class="string">').replace(/'</span>/<span class="variable">g</span>, &<span class="variable">quot</span>;\\<span class="string">'&quot;)) + &quot;'</span>);&<span class="variable">quot</span>;);
+ }
+
+ <span class="comment">// (code | block)</span>
<span class="keyword">switch</span> (<span class="this">this</span>.<span class="variable">peek</span>.<span class="variable">type</span>) {
- <span class="keyword">case</span> <span class="string">'text'</span>:
- <span class="variable">buf</span>.<span class="variable">push</span>(&<span class="variable">quot</span>;<span class="variable">buf</span>.<span class="variable">push</span>(<span class="string">'&quot; + interpolate(this.advance.val.trim().replace(/'</span>/<span class="variable">g</span>, &<span class="variable">quot</span>;\\<span class="string">'&quot;)) + &quot;'</span>);&<span class="variable">quot</span>;);
- <span class="keyword">break</span>;
<span class="keyword">case</span> <span class="string">'code'</span>:
<span class="keyword">var</span> <span class="variable">tok</span> = <span class="this">this</span>.<span class="variable">advance</span>;
<span class="keyword">if</span> (<span class="variable">tok</span>.<span class="variable">buffer</span>) {
@@ -658,38 +696,47 @@
</tr>
<tr class="code">
<td class="docs">
+<p>Dummy iteration template.
+ </p>
+</td>
+<td class="code">
+<pre><code><span class="keyword">var</span> <span class="variable">iterate</span> = (<span class="keyword">function</span>(){
+ <span class="keyword">var</span> <span class="variable">__vals</span> = <span class="variable">__obj__</span>;
+ <span class="keyword">if</span> (<span class="variable">__vals</span> <span class="variable">instanceof</span> <span class="class">Array</span>) {
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">__vals</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
+ <span class="keyword">var</span> <span class="variable">__key__</span> = <span class="variable">i</span>;
+ <span class="keyword">var</span> <span class="variable">__val__</span> = <span class="variable">__vals</span>[<span class="variable">i</span>];
+ <span class="variable">__block__</span>
+ }
+ } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="variable">__vals</span> === <span class="string">'object'</span>) {
+ <span class="keyword">var</span> <span class="variable">keys</span> = <span class="class">Object</span>.<span class="variable">keys</span>(<span class="variable">__vals</span>);
+ <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">keys</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {
+ <span class="keyword">var</span> <span class="variable">__key__</span> = <span class="variable">keys</span>[<span class="variable">i</span>];
+ <span class="keyword">var</span> <span class="variable">__val__</span> = <span class="variable">__vals</span>[<span class="variable">__key__</span>];
+ <span class="variable">__block__</span>
+ }
+ } <span class="keyword">else</span> {
+ <span class="keyword">var</span> <span class="variable">__val__</span> = <span class="variable">__vals</span>;
+ <span class="variable">__block__</span>
+ }
+}).<span class="variable">toString</span>();</code></pre>
+</td>
+</tr>
+<tr class="code">
+<td class="docs">
<p>Render the given <code>str</code> of jade.</p>
<h2>Options</h2>
-<ul>
-<li><code>scope</code> Evaluation scope (<code>this</code>)</li>
-<li><code>locals</code> Local variable object</li>
-<li><code>filename</code> Used in exceptions, and required by <code>cache</code></li>
-<li><code>cache</code> Cache intermediate JavaScript in memory keyed by <code>filename</code></li>
-</ul>
-
-
-<h2>Examples</h2>
-
-<pre><code>jade.render('h1= title', {
- title: 'Jade rules!'
-});
-</code></pre>
+<ul><li><code>scope</code> Evaluation scope (<code>this</code>). Also referred to as <code>context</code></li><li><code>locals</code> Local variable object</li><li><code>filename</code> Used in exceptions, and required by <code>cache</code></li><li><code>cache</code> Cache intermediate JavaScript in memory keyed by <code>filename</code></li></ul>
<h2></h2>
-<ul>
-<li><p><strong>param</strong>: <em>String</em> str</p></li>
-<li><p><strong>param</strong>: <em>Object</em> options</p></li>
-<li><p><strong>return</strong>: <em>String</em></p></li>
-<li><p><strong>api</strong>: <em>public</em></p></li>
-</ul>
-
+<ul><li><p><strong>param</strong>: <em>String</em> str</p></li><li><p><strong>param</strong>: <em>Object</em> options</p></li><li><p><strong>return</strong>: <em>String</em> </p></li><li><p><strong>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">str</span>, <span class="variable">options</span>){
- <span class="keyword">var</span> <span class="variable">js</span>,
+ <span class="keyword">var</span> <span class="variable">fn</span>,
<span class="variable">options</span> = <span class="variable">options</span> || {},
<span class="variable">filename</span> = <span class="variable">options</span>.<span class="variable">filename</span>;
@@ -701,9 +748,14 @@
<span class="variable">parser</span>.<span class="variable">debug</span>();
<span class="variable">parser</span> = <span class="keyword">new</span> <span class="class">Parser</span>(<span class="variable">str</span>, <span class="variable">filename</span>);
}
- <span class="keyword">var</span> <span class="variable">js</span> = <span class="variable">parser</span>.<span class="variable">parse</span>()
+ <span class="keyword">var</span> <span class="variable">js</span> = <span class="variable">parser</span>.<span class="variable">parse</span>();
<span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">debug</span>) <span class="variable">sys</span>.<span class="variable">puts</span>(<span class="string">'\nfunction:'</span>, <span class="variable">js</span>.<span class="variable">replace</span>(<span class="regexp">/^/gm</span>, <span class="string">' '</span>));
- <span class="keyword">return</span> <span class="variable">js</span>;
+ <span class="keyword">try</span> {
+ <span class="keyword">return</span> <span class="keyword">new</span> <span class="class">Function</span>(<span class="string">'locals, attrs, escape, _'</span>, <span class="string">'with (locals) {'</span> + <span class="variable">js</span> + <span class="string">'}'</span>);
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ <span class="variable">process</span>.<span class="variable">compile</span>(<span class="variable">js</span>, <span class="variable">filename</span> || <span class="string">'Jade'</span>);
+ <span class="keyword">return</span>;
+ }
} <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="variable">rethrow</span>(<span class="variable">err</span>, <span class="variable">parser</span>.<span class="variable">lineno</span>);
}
@@ -730,24 +782,23 @@
<span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">cache</span>) {
<span class="keyword">if</span> (<span class="variable">filename</span>) {
<span class="keyword">if</span> (<span class="variable">cache</span>[<span class="variable">filename</span>]) {
- <span class="variable">js</span> = <span class="variable">cache</span>[<span class="variable">filename</span>];
+ <span class="variable">fn</span> = <span class="variable">cache</span>[<span class="variable">filename</span>];
} <span class="keyword">else</span> {
- <span class="variable">js</span> = <span class="variable">cache</span>[<span class="variable">filename</span>] = <span class="variable">parse</span>();
+ <span class="variable">fn</span> = <span class="variable">cache</span>[<span class="variable">filename</span>] = <span class="variable">parse</span>();
}
} <span class="keyword">else</span> {
<span class="keyword">throw</span> <span class="keyword">new</span> <span class="class">Error</span>(<span class="string">'filename is required when using the cache option'</span>);
}
} <span class="keyword">else</span> {
- <span class="variable">js</span> = <span class="variable">parse</span>();
+ <span class="variable">fn</span> = <span class="variable">parse</span>();
}
- <span class="comment">// Generate function</span>
- <span class="keyword">var</span> <span class="variable">fn</span> = <span class="class">Function</span>(<span class="string">'locals, attrs, escape, _'</span>, <span class="string">'with (locals) {'</span> + <span class="variable">js</span> + <span class="string">'}'</span>);
-
<span class="keyword">try</span> {
+ <span class="variable">options</span>.<span class="variable">locals</span> = <span class="variable">options</span>.<span class="variable">locals</span> || {};
+ <span class="variable">options</span>.<span class="variable">locals</span>.<span class="variable">sys</span> = <span class="variable">sys</span>;
<span class="keyword">var</span> <span class="variable">_</span> = { <span class="variable">lineno</span>: <span class="number integer">1</span> };
- <span class="keyword">return</span> <span class="variable">fn</span>.<span class="variable">call</span>(<span class="variable">options</span>.<span class="variable">scope</span>,
- <span class="variable">options</span>.<span class="variable">locals</span> || {},
+ <span class="keyword">return</span> <span class="variable">fn</span>.<span class="variable">call</span>(<span class="variable">options</span>.<span class="variable">scope</span> || <span class="variable">options</span>.<span class="variable">context</span>,
+ <span class="variable">options</span>.<span class="variable">locals</span>,
<span class="variable">attrs</span>,
<span class="variable">escape</span>,
<span class="variable">_</span>);
@@ -763,13 +814,7 @@
<h2></h2>
-<ul>
-<li><p><strong>param</strong>: <em>String</em> path</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>api</strong>: <em>public</em></p></li>
-</ul>
-
+<ul><li><p><strong>param</strong>: <em>String</em> path</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>api</strong>: <em>public</em></p></li></ul>
</td>
<td class="code">
<pre><code><span class="variable">exports</span>.<span class="variable">renderFile</span> = <span class="keyword">function</span>(<span class="variable">path</span>, <span class="variable">options</span>, <span class="variable">fn</span>){
@@ -778,17 +823,27 @@
<span class="variable">options</span> = {};
}
<span class="variable">options</span>.<span class="variable">filename</span> = <span class="variable">path</span>;
- <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">path</span>, <span class="string">'utf8'</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">str</span>){
- <span class="keyword">if</span> (<span class="variable">err</span>) {
+
+ <span class="comment">// Primed cache</span>
+ <span class="keyword">if</span> (<span class="variable">options</span>.<span class="variable">cache</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">cache</span>[<span class="variable">path</span>]) {
+ <span class="keyword">try</span> {
+ <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">exports</span>.<span class="variable">render</span>(<span class="string">''</span>, <span class="variable">options</span>));
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
<span class="variable">fn</span>(<span class="variable">err</span>);
- } <span class="keyword">else</span> {
- <span class="keyword">try</span> {
- <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">exports</span>.<span class="variable">render</span>(<span class="variable">str</span>, <span class="variable">options</span>));
- } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ }
+ } <span class="keyword">else</span> {
+ <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">path</span>, <span class="string">'utf8'</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">str</span>){
+ <span class="keyword">if</span> (<span class="variable">err</span>) {
<span class="variable">fn</span>(<span class="variable">err</span>);
+ } <span class="keyword">else</span> {
+ <span class="keyword">try</span> {
+ <span class="variable">fn</span>(<span class="keyword">null</span>, <span class="variable">exports</span>.<span class="variable">render</span>(<span class="variable">str</span>, <span class="variable">options</span>));
+ } <span class="keyword">catch</span> (<span class="variable">err</span>) {
+ <span class="variable">fn</span>(<span class="variable">err</span>);
+ }
}
- }
- });
+ });
+ }
};</code></pre>
</td>
</tr> </body>
Please sign in to comment.
Something went wrong with that request. Please try again.