haml-coffee
Version:
Haml templates where you can write inline CoffeeScript.
586 lines (546 loc) • 16.3 kB
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>
»
<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 => <footer></footer></code></pre>
<h4>
Haml id
</h4>
<pre><code class='coffee'>#content => <div id='content'></div>
%span#status{ :id => @user.status } => <span id='status_#{ @user.status }'></span></code></pre>
<h4>
Haml classes
</h4>
<pre><code class='coffee'>.hidden => <div class='hidden'></div>
%span.large.hidden => <span class='large hidden'></span>
.large{ :class => @user.role } => <div class='large #{ @user.role }'></div></code></pre>
<h4>
Haml HTML attributes
</h4>
<pre><code class='coffee'>%p(class='hidden') => <p class='hidden'><p>
#account(class=@status) => <div id='account' class='#{ status }'></div>
.logout(title="Logout #{ user.name }") => <div class='logout' title='Logout #{ user.name }'></div></code></pre>
<h4>
Haml Ruby attributes
</h4>
<pre><code class='coffee'>%p{ :class => App.user.get('role') } => <p class='#{ App.user.get('role') }'></p></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<String, Array>) <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 => @user.id } => <div id='user_#{ @user.id }'></div></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>
—
<span class='desc'>the HAML expression</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>Object</tt>)
</span>
—
<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><</code> and <code>></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>
—
<span class='desc'>the HAML expression</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>Object</tt>)
</span>
—
<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 => 'value' '>undefined</a></code>
or HTML style <code>%tag(attr='value)</code>. Both styles can be mixed:
<code>%tag(attr='value)<a href=' :attr => 'value' '>undefined</a></code>.
</p>
<p>This takes also care of proper attribute interpolation, unwrapping
quoted keys and value, e.g. <code>'a' => 'hello'</code> becomes <code>a => 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>
—
<span class='desc'>the HAML expression</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>Array</tt>)
</span>
—
<span class='desc'>the parsed attribute tokens</span>
</li>
</ul>
</div>
</div>
<div class='method_details'>
<p class='signature' id='getDataAttributes-instance'>
- (Array<String, Array>) <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 => { :test => '123' }`</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>
—
<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>
—
<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'><a id='id' class='class' attr='value'</code></pre>
<h4>
Template render time sorting
</h4>
<pre><code class='coffee'><p class='#{ [@user.name(), 'show'].sort().join(' ') }'></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>
—
<span class='desc'>all parsed tag tokens</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>String</tt>)
</span>
—
<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>
—
<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>
—
<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>
—
<span class='desc'>the HAML doctype</span>
</li>
</ul>
<h3>Returns:</h3>
<ul class='return'>
<li>
<span class='type'>
(<tt>String</tt>)
</span>
—
<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>
—
<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>
—
<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).
✲
<a href='http://twitter.com/#!/netzpirat'>@netzpirat</a>
✲
<a href='https://mksoft.ch'>mksoft.ch</a>
</div>
</body>
</html>