Class: Haml
Defined in: | node_modules/grunt-codo/node_modules/codo/node_modules/haml-coffee/src/nodes/haml.coffee |
Inherits: | Node |
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>
Variables Summary
Variable 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.
-
#
(Object)
parseAttributes(exp)
Parse attributes either in Ruby style
%tag{ :attr => 'value' }
or HTML style%tag(attr='value)
. - # (String) buildHtmlTagPrefix(tokens) Build the HTML tag prefix by concatenating all the tag information together.
- # (String) interpolateCodeAttribute(text, unwrap = false) Wrap plain attributes into an interpolation for execution.
- # (String) quoteAndEscapeAttributeValue(value, code = false) Quote the attribute value, depending on its content.
- # (Array<String>) splitInterpolations(value) Split expression by its interpolations.
-
#
(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.
Inherited Method Summary
Methods inherited from
Node
#addChild #getOpener #getCloser #isPreserved #isCommented #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 >
.
It detects an object reference [
and attributes (
/ {
.
#
(Object)
parseAttributes(exp)
Parse attributes either in Ruby style %tag{ :attr => 'value' }
or HTML style %tag(attr='value)
. Both styles can be mixed:
%tag(attr='value){ :attr => 'value' }
.
This takes also care of proper attribute interpolation, unwrapping
quoted keys and value, e.g. 'a' => 'hello'
becomes a => hello
.
#
(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.
If both an object reference and an id or class attribute is defined, then the attribute will be ignored.
Examples:
Prefix tag
<a id='id' class='class' attr='value'
Template render time sorting
<p class='#{ [@user.name(), 'show'].sort().join(' ') }'>
#
(String)
interpolateCodeAttribute(text, unwrap = false)
Wrap plain attributes into an interpolation for execution. In addition wrap it into escaping and cleaning function, depending on the options.
#
(String)
quoteAndEscapeAttributeValue(value, code = false)
Quote the attribute value, depending on its content. If the attribute contains an interpolation, each interpolation will be cleaned and/or escaped, depending on the compiler options.
#
(Array<String>)
splitInterpolations(value)
Split expression by its interpolations.
Examples:
'Hello #{ "#{ soso({}) }" } Interpol') => ["Hello ", "#{ "#{ soso({}) }" }", " Interpol"]
'Hello #{ "#{ soso }" } Interpol') => ["Hello ", "#{ "#{ soso }" }", " Interpol"]
'Hello #{ int } Interpol') => ["Hello ", "#{ int }", " Interpol"]
'Hello Interpol') => ["Hello Interpol"]
'#{ int } Interpol') => ["#{ int }", " Interpol"]
'Hello #{ int }') => ["Hello ", "#{ int }"]
'#{ int }') => ["#{ int }"]
#
(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.