Class: Haml
Defined in: | node_modules/haml-coffee/src/nodes/haml.coffee |
Inherits: | Node |
Overview
HAML node that contains Haml a haml tag that can have attributes
@example Haml tag %footer =>
@example Haml id
content =>
%span#status{ :id => @user.status } =>
@example Haml classes .hidden =>
%span.large.hidden => .large{ :class => @user.role } =>Haml HTML attributes are very limited and allows only simple string (with interpolation) or variable assignment to an attribute.
@example Haml HTML attributes %p(class='hidden') =>
account(class=@status) =>
.logout(title="Logout #{ user.name }") =>
Ruby HTML attributes are more powerful and allows in addition to the HTML attributes function calls:
@example Haml Ruby attributes %p{ :class => App.user.get('role') } =>
Constant Summary
Constants inherited from Node
CLEAR_WHITESPACE_LEFT, CLEAR_WHITESPACE_RIGHT
Instance Method Summary
-
.buildDocType(doctype)
Build the DocType string depending on the
!!!
token @param [String] doctype the HAML doctype @return [String] the HTML doctype -
.buildHtmlTagPrefix(tokens)
Build the HTML tag prefix by concatenating all the @example Prefix tag <a id='id' class='class' attr='value' The Haml spec sorts the
class
names, even when they contain interpolated classes. - .evaluate() Evaluate the node content and store the opener tag
- .interpolateCodeAttribute(text, unwrap = false) Wrap plain attributes into an interpolation for execution.
- .isNotSelfClosing(tag) Test if the given tag is a non-self enclosing tag, by @param [String] tag the tag name without brackets @return [Boolean] true when a non self closing tag
-
.parseAttributes(exp)
Parse attributes either in Ruby style
%tag{ :attr => 'value' }
This takes also care of proper attribute interpolation, unwrapping quoted keys and value, e.g. - .parseExpression(exp) Parses the expression and detect the tag, attributes Classes are merged together When multiple ids are provided, the last one is taken, except they are defined in shortcut notation and attribute notation.
- .parseTag(exp) Parse a tag line.
- .quoteAndEscapeAttributeValue(value, code = false) Quote the attribute value, depending on its @param [String] value the without start and end quote @param [String] code if we are in a code block @return [String] the quoted value
- .splitInterpolations(value) Split expression by its interpolations.
Inherited Method Summary
Methods inherited from Node
.constructor, .addChild, .getOpener, .getCloser, .isPreserved, .isCommented, .markText, .markRunningCode, .markInsertingCode, .evaluate, .render
Instance Method Details
.buildDocType(doctype)
Build the DocType string depending on the !!!
token
@param [String] doctype the HAML doctype @return [String] the HTML doctype
.buildHtmlTagPrefix(tokens)
Build the HTML tag prefix by concatenating all the
@example Prefix tag <a id='id' class='class' attr='value'
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.
@example Template render time sorting
@param [Object] tokens all parsed tag tokens @return [String] the tag prefix
.evaluate()
Evaluate the node content and store the opener tag
.interpolateCodeAttribute(text, unwrap = false)
Wrap plain attributes into an interpolation for execution.
@param [String] text the possible code @param [Boolean] unwrap unwrap static text from quotes @return [String] the text of the wrapped code
.isNotSelfClosing(tag)
Test if the given tag is a non-self enclosing tag, by
@param [String] tag the tag name without brackets @return [Boolean] true when a non self closing tag
.parseAttributes(exp)
Parse attributes either in Ruby style %tag{ :attr => 'value' }
This takes also care of proper attribute interpolation, unwrapping
quoted keys and value, e.g. 'a' => 'hello'
becomes a => hello
.
@param [String] exp the HAML expression @return [Object] the parsed attributes
.parseExpression(exp)
Parses the expression and detect the tag, attributes
- 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.
@example Id merging
user{ :id => @user.id } =>
@param [String] exp the HAML expression @return [Object] the parsed tag and options tokens
.parseTag(exp)
Parse a tag line. This recognizes DocType tags !!!
and
It also parses the code assignment =
, }=
and )=
or
inline text and the whitespace removal markers <
and >
.
It detects an object reference [
and attributes (
/ {
.
@param [String] exp the HAML expression @return [Object] the parsed tag tokens
.quoteAndEscapeAttributeValue(value, code = false)
Quote the attribute value, depending on its
@param [String] value the without start and end quote @param [String] code if we are in a code block @return [String] the quoted value
.splitInterpolations(value)
Split expression by its interpolations.
@example '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 }"]
@param [String] value the attribute value
@return [Array