Class: Haml
Inherits: | Node |
Defined in: | src/nodes/haml.coffee |
Overview
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.
Haml HTML attributes are very limited and allows only simple string (with interpolation) or variable assignment to an attribute.
Ruby HTML attributes are more powerful and allows in addition to the HTML attributes function calls:
Examples:
Haml tag
%footer => <footer></footer>
Haml id
#content => <div id='content'></div>
%span#status{ :id => @user.status } => <span id='status_#{ @user.status }'></span>
Haml classes
.hidden => <div class='hidden'></div>
%span.large.hidden => <span class='large hidden'></span>
.large{ :class => @user.role } => <div class='large #{ @user.role }'></div>
Haml HTML attributes
%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>
Haml Ruby attributes
%p{ :class => App.user.get('role') } => <p class='#{ App.user.get('role') }'></p>
Constant Summary
Constants inherited from Node
CLEAR_WHITESPACE_LEFT, CLEAR_WHITESPACE_RIGHT
Instance Method Summary
- - (void) evaluate() Evaluate the node content and store the opener tag and the closer tag if applicable.
- - (Object) parseExpression(exp) Parses the expression and detect the tag, attributes and any assignment.
- - (Object) parseTag(exp) Parse a tag line.
- - (Array) parseAttributes(exp) Parse attributes either in Ruby style `%tag{ :attr => 'value' }` or HTML style `%tag(attr='value)`.
- - (Array<String, Array>) getDataAttributes(exp) Extracts the data attributes.
- - (String) buildHtmlTagPrefix(tokens) Build the HTML tag prefix by concatenating all the tag information together.
- - (String) quoteAttributeValue(value) Quote the attribute value, depending on its content.
- - (String) buildDocType(doctype) Build the DocType string depending on the `!!!` token and the currently used HTML format.
- - (Boolean) isNotSelfClosing(tag) 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.
Methods inherited from Node
#constructor, #addChild, #getOpener, #getCloser, #isPreserved, #markText, #markRunningCode, #markInsertingCode, #evaluate, #render
Instance Method Details
- (void) evaluate()
Evaluate the node content and store the opener tag and the closer tag if applicable.
- (Object) parseExpression(exp)
Parses the expression and detect the tag, attributes and any assignment. In addition class and id cleanup is performed according the the Haml spec:
- Classes are merged together
- 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.
Examples:
Id merging
#user{ :id => @user.id } => <div id='user_#{ @user.id }'></div>
- (Object) parseTag(exp)
Parse a tag line. This recognizes DocType tags !!!
and
HAML tags like #id.class text
.
It also parses the code assignment =
, }=
and )=
or
inline text and the whitespace removal markers <
and >
.
- (Array) parseAttributes(exp)
- (Array<String, Array>) getDataAttributes(exp)
Extracts the data attributes.
Examples:
data attribute
`:data => { :test => '123' }`
- (String) buildHtmlTagPrefix(tokens)
Build the HTML tag prefix by concatenating all the tag information together. The result is an unfinished html tag that must be further processed:
The Haml spec sorts the class
names, even when they
contain interpolated classes. This is supported by
sorting classes at template render time.
Examples:
Prefix tag
<a id='id' class='class' attr='value'
Template render time sorting
<p class='#{ [@user.name(), 'show'].sort().join(' ') }'>
- (String) quoteAttributeValue(value)
Quote the attribute value, depending on its content.
- (String) buildDocType(doctype)
Build the DocType string depending on the !!!
token
and the currently used HTML format.
- (Boolean) isNotSelfClosing(tag)
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.