UNPKG

haml-coffee

Version:

Haml templates where you can write inline CoffeeScript.

586 lines (546 loc) 16.3 kB
<!DOCTYPE html> <html> <head> <title>Haml Coffee Documentation</title> <link rel='stylesheet' href='../assets/codo.css' type='text/css'> <script src='../assets/codo.js'></script> </head> <body> <div id='header'> <div id='menu'> <a href='../class_index.html' title='Index'>Index</a> &raquo; <span class='title'>Haml</span> <nav> <ul> <li class='frames'> (<a class='frames' href='../frames.html'>frames</a>) </li> <li class='noframes'> (<a class='noframes' href='#'>no frames</a>) </li> </ul> </nav> <div id='search'> <a id='class_list_link' href='../class_list.html'>Class List</a> <a id='method_list_link' href='../method_list.html'>Method List</a> <a id='file_list_link' href='../file_list.html'>File List</a> </div> </div> <iframe id='search_frame'></iframe> </div> <div id='content'> <h1> Class: Haml </h1> <table class='box'> <tr> <td>Inherits:</td> <td> <a href="../classes/Node.html">Node</a> </td> </tr> <tr> <td>Defined in:</td> <td>src/nodes/haml.coffee</td> </tr> </table> <h2>Overview</h2> <div class='docstring'> <p>HAML node that contains Haml a haml tag that can have attributes and a text or code assignment. There are shortcuts for id and class generation and some special logic for merging attributes into existing ids and classes. </p> <p>Haml HTML attributes are very limited and allows only simple string (with interpolation) or variable assignment to an attribute. </p> <p>Ruby HTML attributes are more powerful and allows in addition to the HTML attributes function calls: </p> <div class='examples'> <h3>Examples:</h3> <h4> Haml tag </h4> <pre><code class='coffee'>%footer =&gt; &lt;footer&gt;&lt;/footer&gt;</code></pre> <h4> Haml id </h4> <pre><code class='coffee'>#content =&gt; &lt;div id=&apos;content&apos;&gt;&lt;/div&gt; %span#status{ :id =&gt; @user.status } =&gt; &lt;span id=&apos;status_#{ @user.status }&apos;&gt;&lt;/span&gt;</code></pre> <h4> Haml classes </h4> <pre><code class='coffee'>.hidden =&gt; &lt;div class=&apos;hidden&apos;&gt;&lt;/div&gt; %span.large.hidden =&gt; &lt;span class=&apos;large hidden&apos;&gt;&lt;/span&gt; .large{ :class =&gt; @user.role } =&gt; &lt;div class=&apos;large #{ @user.role }&apos;&gt;&lt;/div&gt;</code></pre> <h4> Haml HTML attributes </h4> <pre><code class='coffee'>%p(class=&apos;hidden&apos;) =&gt; &lt;p class=&apos;hidden&apos;&gt;&lt;p&gt; #account(class=@status) =&gt; &lt;div id=&apos;account&apos; class=&apos;#{ status }&apos;&gt;&lt;/div&gt; .logout(title=&quot;Logout #{ user.name }&quot;) =&gt; &lt;div class=&apos;logout&apos; title=&apos;Logout #{ user.name }&apos;&gt;&lt;/div&gt;</code></pre> <h4> Haml Ruby attributes </h4> <pre><code class='coffee'>%p{ :class =&gt; App.user.get(&apos;role&apos;) } =&gt; &lt;p class=&apos;#{ App.user.get(&apos;role&apos;) }&apos;&gt;&lt;/p&gt;</code></pre> </div> </div> <div class='tags'> </div> <h2>Constant Summary</h2> <h3 class='inherited'> Constants inherited from <a href="../classes/Node.html">Node</a> </h3> <p class='inherited'> <a href="undefinedclasses/Node.html#CLEAR_WHITESPACE_LEFT-constant">CLEAR_WHITESPACE_LEFT</a>, <a href="../classes/Node.html#CLEAR_WHITESPACE_RIGHT-constant">CLEAR_WHITESPACE_RIGHT</a> </p> <h2>Instance Method Summary</h2> <ul class='summary'> <li> <span class='signature'> <a href='#evaluate-instance'> - (void) <strong>evaluate</strong>() </a> </span> <span class='desc'> Evaluate the node content and store the opener tag and the closer tag if applicable. </span> </li> <li> <span class='signature'> <a href='#parseExpression-instance'> - (Object) <strong>parseExpression</strong>(exp) </a> </span> <span class='desc'> Parses the expression and detect the tag, attributes and any assignment. </span> </li> <li> <span class='signature'> <a href='#parseTag-instance'> - (Object) <strong>parseTag</strong>(exp) </a> </span> <span class='desc'> Parse a tag line. </span> </li> <li> <span class='signature'> <a href='#parseAttributes-instance'> - (Array) <strong>parseAttributes</strong>(exp) </a> </span> <span class='desc'> Parse attributes either in Ruby style `%tag{ :attr => 'value' }` or HTML style `%tag(attr='value)`. </span> </li> <li> <span class='signature'> <a href='#getDataAttributes-instance'> - (Array&lt;String, Array&gt;) <strong>getDataAttributes</strong>(exp) </a> </span> <span class='desc'> Extracts the data attributes. </span> </li> <li> <span class='signature'> <a href='#buildHtmlTagPrefix-instance'> - (String) <strong>buildHtmlTagPrefix</strong>(tokens) </a> </span> <span class='desc'> Build the HTML tag prefix by concatenating all the tag information together. </span> </li> <li> <span class='signature'> <a href='#quoteAttributeValue-instance'> - (String) <strong>quoteAttributeValue</strong>(value) </a> </span> <span class='desc'> Quote the attribute value, depending on its content. </span> </li> <li> <span class='signature'> <a href='#buildDocType-instance'> - (String) <strong>buildDocType</strong>(doctype) </a> </span> <span class='desc'> Build the DocType string depending on the `!!!` token and the currently used HTML format. </span> </li> <li> <span class='signature'> <a href='#isNotSelfClosing-instance'> - (Boolean) <strong>isNotSelfClosing</strong>(tag) </a> </span> <span class='desc'> Test if the given tag is a non-self enclosing tag, by matching against a fixed tag list or parse for the self closing slash `/` at the end. </span> </li> </ul> <h3 class='inherited'> Methods inherited from <a href="../classes/Node.html">Node</a> </h3> <p class='inherited'> <a href="undefinedclasses/Node.html#constructor-instance">#constructor</a>, <a href="undefinedclasses/Node.html#addChild-instance">#addChild</a>, <a href="undefinedclasses/Node.html#getOpener-instance">#getOpener</a>, <a href="undefinedclasses/Node.html#getCloser-instance">#getCloser</a>, <a href="undefinedclasses/Node.html#isPreserved-instance">#isPreserved</a>, <a href="undefinedclasses/Node.html#markText-instance">#markText</a>, <a href="undefinedclasses/Node.html#markRunningCode-instance">#markRunningCode</a>, <a href="undefinedclasses/Node.html#markInsertingCode-instance">#markInsertingCode</a>, <a href="undefinedclasses/Node.html#evaluate-instance">#evaluate</a>, <a href="../classes/Node.html#render-instance">#render</a> </p> <h2>Instance Method Details</h2> <div class='methods'> <div class='method_details'> <p class='signature' id='evaluate-instance'> - (void) <strong>evaluate</strong>() </p> <div class='docstring'> <p>Evaluate the node content and store the opener tag and the closer tag if applicable. </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='parseExpression-instance'> - (Object) <strong>parseExpression</strong>(exp) </p> <div class='docstring'> <p>Parses the expression and detect the tag, attributes and any assignment. In addition class and id cleanup is performed according the the Haml spec: </p> <ul> <li>Classes are merged together</li> <li>When multiple ids are provided, the last one is taken, except they are defined in shortcut notation and attribute notation. In this case, they will be combined, separated by underscore.</li> </ul> <div class='examples'> <h3>Examples:</h3> <h4> Id merging </h4> <pre><code class='coffee'>#user{ :id =&gt; @user.id } =&gt; &lt;div id=&apos;user_#{ @user.id }&apos;&gt;&lt;/div&gt;</code></pre> </div> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>exp</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HAML expression</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>the parsed tag and options tokens</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='parseTag-instance'> - (Object) <strong>parseTag</strong>(exp) </p> <div class='docstring'> <p>Parse a tag line. This recognizes DocType tags <code>!!!</code> and HAML tags like <code>#id.class text</code>. </p> <p>It also parses the code assignment <code>=</code>, <code>}=</code> and <code>)=</code> or inline text and the whitespace removal markers <code>&lt;</code> and <code>&gt;</code>. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>exp</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HAML expression</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>the parsed tag tokens</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='parseAttributes-instance'> - (Array) <strong>parseAttributes</strong>(exp) </p> <div class='docstring'> <p>Parse attributes either in Ruby style <code>%tag<a href=' :attr =&gt; &#39;value&#39; '>undefined</a></code> or HTML style <code>%tag(attr=&#39;value)</code>. Both styles can be mixed: <code>%tag(attr=&#39;value)<a href=' :attr =&gt; &#39;value&#39; '>undefined</a></code>. </p> <p>This takes also care of proper attribute interpolation, unwrapping quoted keys and value, e.g. <code>&#39;a&#39; =&gt; &#39;hello&#39;</code> becomes <code>a =&gt; hello</code>. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>exp</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HAML expression</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Array</tt>) </span> &mdash; <span class='desc'>the parsed attribute tokens</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='getDataAttributes-instance'> - (Array&lt;String, Array&gt;) <strong>getDataAttributes</strong>(exp) </p> <div class='docstring'> <p>Extracts the data attributes. </p> <div class='examples'> <h3>Examples:</h3> <h4> data attribute </h4> <pre><code class='coffee'>`:data =&gt; { :test =&gt; &apos;123&apos; }`</code></pre> </div> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>exp</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the expression to check</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Array<String, Array></tt>) </span> &mdash; <span class='desc'>the expressions and data attributes</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='buildHtmlTagPrefix-instance'> - (String) <strong>buildHtmlTagPrefix</strong>(tokens) </p> <div class='docstring'> <p>Build the HTML tag prefix by concatenating all the tag information together. The result is an unfinished html tag that must be further processed: </p> <p>The Haml spec sorts the <code>class</code> names, even when they contain interpolated classes. This is supported by sorting classes at template render time. </p> <div class='examples'> <h3>Examples:</h3> <h4> Prefix tag </h4> <pre><code class='coffee'>&lt;a id=&apos;id&apos; class=&apos;class&apos; attr=&apos;value&apos;</code></pre> <h4> Template render time sorting </h4> <pre><code class='coffee'>&lt;p class=&apos;#{ [@user.name(), &apos;show&apos;].sort().join(&apos; &apos;) }&apos;&gt;</code></pre> </div> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>tokens</span> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>all parsed tag tokens</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the tag prefix</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='quoteAttributeValue-instance'> - (String) <strong>quoteAttributeValue</strong>(value) </p> <div class='docstring'> <p>Quote the attribute value, depending on its content. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>value</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the without start and end quote</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the quoted value</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='buildDocType-instance'> - (String) <strong>buildDocType</strong>(doctype) </p> <div class='docstring'> <p>Build the DocType string depending on the <code>!!!</code> token and the currently used HTML format. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>doctype</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HAML doctype</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HTML doctype</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='isNotSelfClosing-instance'> - (Boolean) <strong>isNotSelfClosing</strong>(tag) </p> <div class='docstring'> <p>Test if the given tag is a non-self enclosing tag, by matching against a fixed tag list or parse for the self closing slash <code>/</code> at the end. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>tag</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the tag name without brackets</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>true when a non self closing tag</span> </li> </ul> </div> </div> </div> </div> <div id='footer'> Generated on Sun Feb 26 2012 12:33:24 GMT+0100 (CET) by <a href='https://github.com/netzpirat/codo' title='CoffeeScript API documentation generator'>codo</a> v0.4.1 (Node.js v0.6.11). &#10034; <a href='http://twitter.com/#!/netzpirat'>@netzpirat</a> &#10034; <a href='https://mksoft.ch'>mksoft.ch</a> </div> </body> </html>