UNPKG

haml-coffee

Version:

Haml templates where you can write inline CoffeeScript.

898 lines (837 loc) 21.8 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'>HamlCoffee</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: HamlCoffee </h1> <table class='box'> <tr> <td>Defined in:</td> <td>src/haml-coffee.coffee</td> </tr> </table> <h2>Overview</h2> <div class='docstring'> <p>The HamlCoffee class is the compiler that parses the source code and creates an syntax tree. In a second step the created tree can be rendered into either a JavaScript function or a CoffeeScript template. </p> </div> <div class='tags'> </div> <h2>Instance Method Summary</h2> <ul class='summary'> <li> <span class='signature'> <a href='#constructor-instance'> - (void) <strong>constructor</strong>(options = {}) </a> </span> <span class='constructor note title'>Constructor</span> <span class='desc'> Construct the HAML Coffee compiler. </span> </li> <li> <span class='signature'> <a href='#indentChanged-instance'> - (Boolean) <strong>indentChanged</strong>() </a> </span> <span class='desc'> Test if the indention level has changed, either increased or decreased. </span> </li> <li> <span class='signature'> <a href='#isIndent-instance'> - (Boolean) <strong>isIndent</strong>() </a> </span> <span class='desc'> Test if the indention levels has been increased. </span> </li> <li> <span class='signature'> <a href='#updateTabSize-instance'> - (void) <strong>updateTabSize</strong>() </a> </span> <span class='desc'> Calculate the indention size </span> </li> <li> <span class='signature'> <a href='#updateBlockLevel-instance'> - (void) <strong>updateBlockLevel</strong>() </a> </span> <span class='desc'> Update the current block level indention. </span> </li> <li> <span class='signature'> <a href='#updateCodeBlockLevel-instance'> - (void) <strong>updateCodeBlockLevel</strong>(node) </a> </span> <span class='desc'> Update the indention level for a code block. </span> </li> <li> <span class='signature'> <a href='#updateParent-instance'> - (void) <strong>updateParent</strong>() </a> </span> <span class='desc'> Update the parent node. </span> </li> <li> <span class='signature'> <a href='#pushParent-instance'> - (void) <strong>pushParent</strong>() </a> </span> <span class='desc'> Indention level has been increased: Push the current parent node to the stack and make the current node the parent node. </span> </li> <li> <span class='signature'> <a href='#popParent-instance'> - (void) <strong>popParent</strong>() </a> </span> <span class='desc'> Indention level has been decreased: Make the grand parent the current parent. </span> </li> <li> <span class='signature'> <a href='#getNodeOptions-instance'> - (Object) <strong>getNodeOptions</strong>(override = {}) </a> </span> <span class='desc'> Get the options for creating a node </span> </li> <li> <span class='signature'> <a href='#nodeFactory-instance'> - (Node) <strong>nodeFactory</strong>(expression = '') </a> </span> <span class='desc'> Get the matching node type for the given expression. </span> </li> <li> <span class='signature'> <a href='#parse-instance'> - (void) <strong>parse</strong>(source = '') </a> </span> <span class='desc'> Parse the given source and create the nested node structure. </span> </li> <li> <span class='signature'> <a href='#evaluate-instance'> - (void) <strong>evaluate</strong>(node) </a> </span> <span class='desc'> Evaluate the parsed tree </span> </li> <li> <span class='signature'> <a href='#render-instance'> - (void) <strong>render</strong>(templateName, namespace = 'window.HAML') </a> </span> <span class='desc'> Render the parsed source code as CoffeeScript template. </span> </li> <li> <span class='signature'> <a href='#precompile-instance'> - (String) <strong>precompile</strong>() </a> </span> <span class='desc'> Pre-compiles the parsed source and generates the function source code. </span> </li> <li> <span class='signature'> <a href='#createCode-instance'> - (String) <strong>createCode</strong>() </a> </span> <span class='desc'> Create the CoffeeScript code for the template. </span> </li> <li> <span class='signature'> <a href='#getBuffer-instance'> - (void) <strong>getBuffer</strong>(level) </a> </span> <span class='desc'> Get the code buffer identifer </span> </li> <li> <span class='signature'> <a href='#combineText-instance'> - (Array&lt;Object&gt;) <strong>combineText</strong>(lines) </a> </span> <span class='desc'> Optimize the lines to be rendered by combining subsequent text nodes that are on the same code line indention into a single line. </span> </li> <li> <span class='signature'> <a href='#convertBooleans-instance'> - (String) <strong>convertBooleans</strong>(code) </a> </span> <span class='desc'> Adds a boolean convert logic that changes boolean attribute values depending on the output format. </span> </li> <li> <span class='signature'> <a href='#cleanupWhitespace-instance'> - (String) <strong>cleanupWhitespace</strong>(code) </a> </span> <span class='desc'> Adds whitespace cleanup function when needed by the template. </span> </li> </ul> <h2>Constructor Details</h2> <div class='methods'> <div class='method_details'> <p class='signature' id='constructor-instance'> - (void) <strong>constructor</strong>(options = {}) </p> <div class='docstring'> <p>Construct the HAML Coffee compiler. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>options</span> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>the compiler options</span> </li> </ul> <h3> Options Hash: (options): </h3> <ul class='options'> <li> <span class='name'>escapeHtml</span> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>escape the output when true</span> </li> <li> <span class='name'>escapeAttributes</span> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>escape the tag attributes when true</span> </li> <li> <span class='name'>cleanValue</span> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>clean CoffeeScript values before inserting</span> </li> <li> <span class='name'>uglify</span> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>don't indent generated HTML when true</span> </li> <li> <span class='name'>format</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the template format, either `xhtml`, `html4` or `html5`</span> </li> <li> <span class='name'>preserveTags</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>a comma separated list of tags to preserve content whitespace</span> </li> <li> <span class='name'>selfCloseTags</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>a comma separated list of self closing HTML tags</span> </li> <li> <span class='name'>customHtmlEscape</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the name of the function for HTML escaping</span> </li> <li> <span class='name'>customCleanValue</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the name of the function to clean code insertion values before output</span> </li> <li> <span class='name'>customFindAndPreserve</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the name of the function used to find and preserve whitespace</span> </li> <li> <span class='name'>customPreserve</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the name of the function used to preserve the whitespace</span> </li> </ul> </div> </div> </div> <h2>Instance Method Details</h2> <div class='methods'> <div class='method_details'> <p class='signature' id='indentChanged-instance'> - (Boolean) <strong>indentChanged</strong>() </p> <div class='docstring'> <p>Test if the indention level has changed, either increased or decreased. </p> </div> <div class='tags'> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>true when indention changed</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='isIndent-instance'> - (Boolean) <strong>isIndent</strong>() </p> <div class='docstring'> <p>Test if the indention levels has been increased. </p> </div> <div class='tags'> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Boolean</tt>) </span> &mdash; <span class='desc'>true when increased</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='updateTabSize-instance'> - (void) <strong>updateTabSize</strong>() </p> <div class='docstring'> <p>Calculate the indention size </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='updateBlockLevel-instance'> - (void) <strong>updateBlockLevel</strong>() </p> <div class='docstring'> <p>Update the current block level indention. </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='updateCodeBlockLevel-instance'> - (void) <strong>updateCodeBlockLevel</strong>(node) </p> <div class='docstring'> <p>Update the indention level for a code block. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>node</span> <span class='type'> (<tt><a href='../classes/Node.html'>Node</a></tt>) </span> &mdash; <span class='desc'>the node to update</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='updateParent-instance'> - (void) <strong>updateParent</strong>() </p> <div class='docstring'> <p>Update the parent node. This depends on the indention if stays the same, goes one down or on up. </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='pushParent-instance'> - (void) <strong>pushParent</strong>() </p> <div class='docstring'> <p>Indention level has been increased: Push the current parent node to the stack and make the current node the parent node. </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='popParent-instance'> - (void) <strong>popParent</strong>() </p> <div class='docstring'> <p>Indention level has been decreased: Make the grand parent the current parent. </p> </div> <div class='tags'> </div> </div> <div class='method_details'> <p class='signature' id='getNodeOptions-instance'> - (Object) <strong>getNodeOptions</strong>(override = {}) </p> <div class='docstring'> <p>Get the options for creating a node </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>override</span> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>the options to override</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Object</tt>) </span> &mdash; <span class='desc'>the node options</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='nodeFactory-instance'> - (Node) <strong>nodeFactory</strong>(expression = '') </p> <div class='docstring'> <p>Get the matching node type for the given expression. This is also responsible for creating the nested tree structure, since there is an exception for creating the node tree: Within a filter expression, any empty line without indention is added as child to the previous filter expression. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>expression</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><a href='../classes/Node.html'>Node</a></tt>) </span> &mdash; <span class='desc'>the parser node</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='parse-instance'> - (void) <strong>parse</strong>(source = '') </p> <div class='docstring'> <p>Parse the given source and create the nested node structure. This parses the source code line be line, but looks ahead to find lines that should be merged into the current line. This is needed for splitting Haml attributes over several lines and also for the different types of filters. </p> <p>Parsing does not create an output, it creates the syntax tree in the compiler. To get the template, use <code>#render</code>. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>source</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the HAML source code</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='evaluate-instance'> - (void) <strong>evaluate</strong>(node) </p> <div class='docstring'> <p>Evaluate the parsed tree </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>node</span> <span class='type'> (<tt><a href='../classes/Node.html'>Node</a></tt>) </span> &mdash; <span class='desc'>the node to evaluate</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='render-instance'> - (void) <strong>render</strong>(templateName, namespace = 'window.HAML') </p> <div class='docstring'> <p>Render the parsed source code as CoffeeScript template. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>templateName</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the name to register the template</span> </li> <li> <span class='name'>namespace</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the namespace to register the template</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='precompile-instance'> - (String) <strong>precompile</strong>() </p> <div class='docstring'> <p>Pre-compiles the parsed source and generates the function source code. </p> </div> <div class='tags'> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the template function source code</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='createCode-instance'> - (String) <strong>createCode</strong>() </p> <div class='docstring'> <p>Create the CoffeeScript code for the template. </p> <p>This gets an array of all lines to be rendered in the correct sequence. </p> </div> <div class='tags'> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the CoffeeScript code</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='getBuffer-instance'> - (void) <strong>getBuffer</strong>(level) </p> <div class='docstring'> <p>Get the code buffer identifer </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>level</span> <span class='type'> (<tt>Number</tt>) </span> &mdash; <span class='desc'>the block indention level</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='combineText-instance'> - (Array&lt;Object&gt;) <strong>combineText</strong>(lines) </p> <div class='docstring'> <p>Optimize the lines to be rendered by combining subsequent text nodes that are on the same code line indention into a single line. </p> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>lines</span> <span class='type'> (<tt>Array<Object></tt>) </span> &mdash; <span class='desc'>the code lines</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>Array<Object></tt>) </span> &mdash; <span class='desc'>the optimized lines</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='convertBooleans-instance'> - (String) <strong>convertBooleans</strong>(code) </p> <div class='docstring'> <p>Adds a boolean convert logic that changes boolean attribute values depending on the output format. </p> <p>With the XHTML format, an attribute <code>checked=&#39;true&#39;</code> will be converted to <code>checked=&#39;checked&#39;</code> and <code>checked=&#39;false&#39;</code> will be completely removed. </p> <p>With the HTML4 and HTML5 format, an attribute <code>checked=&#39;true&#39;</code> will be converted to <code>checked</code> and <code>checked=&#39;false&#39;</code> will be completely removed. </p> </div> <div class='tags'> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the clean up whitespace code if necessary</span> </li> </ul> </div> </div> <div class='method_details'> <p class='signature' id='cleanupWhitespace-instance'> - (String) <strong>cleanupWhitespace</strong>(code) </p> <div class='docstring'> <p>Adds whitespace cleanup function when needed by the template. The cleanup must be done AFTER the template has been rendered. </p> <p>The detection is based on hidden unicode characters that are placed as marker into the template: </p> <ul> <li><code>\u0091</code> Cleanup surrounding whitespace to the left</li> <li><code>\u0092</code> Cleanup surrounding whitespace to the right</li> </ul> </div> <div class='tags'> <h3>Parameters:</h3> <ul class='param'> <li> <span class='name'>code</span> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the template code</span> </li> </ul> <h3>Returns:</h3> <ul class='return'> <li> <span class='type'> (<tt>String</tt>) </span> &mdash; <span class='desc'>the clean up whitespace code if necessary</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>