Class: HamlCoffee
Defined in: | node_modules/grunt-codo/node_modules/codo/node_modules/haml-coffee/src/haml-coffee.coffee |
Overview
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.
Variables Summary
- VERSION =
-
require('../package.json')
The current version number.
Instance Method Summary
- # (Boolean) indentChanged() Test if the indention level has changed, either increased or decreased.
- # (Boolean) isIndent() Test if the indention levels has been increased.
- # (void) updateTabSize() Calculate the indention size
- # (void) updateBlockLevel() Update the current block level indention.
- # (void) updateCodeBlockLevel(node) Update the indention level for a code block.
- # (void) updateParent() Update the parent node.
-
#
(void)
pushParent()
Indention level has been increased: Push the current parent node to the stack and make the current node the parent node.
- # (void) popParent() Indention level has been decreased: Make the grand parent the current parent.
- # (Object) getNodeOptions(override = {}) Get the options for creating a node
- # (Node) nodeFactory(expression = '') Get the matching node type for the given expression.
- # (void) parse(source = '') Parse the given source and create the nested node structure.
- # (void) evaluate(node) Evaluate the parsed tree
- # (void) render() Render the parsed source code as CoffeeScript template.
- # (void) renderStandalone() Render a standalone version
- # (String) renderAmd() Private Render the parsed source code as CoffeeScript template wrapped in a define() statement for AMD.
- # (String) renderGlobal() Private Render the parsed source code as CoffeeScript template to a global window.HAML variable.
- # (String) precompile() Pre-compiles the parsed source and generates the function source code.
- # (String) createCode() Create the CoffeeScript code for the template.
- # (void) getBuffer(level) Get the code buffer identifer
- # (Array<Object>) combineText(lines) Optimize the lines to be rendered by combining subsequent text nodes that are on the same code line indention into a single line.
- # (String) convertBooleans(code) Adds a boolean convert logic that changes boolean attribute values depending on the output format.
- # (String) removeEmptyIDAndClass(code) Remove empty ID and class attribute from the final template.
- # (String) cleanupWhitespace(code) Adds whitespace cleanup function when needed by the template.
- # (Object) findDependencies(code) Searches for AMD require statements to find all template dependencies.
Constructor Details
#
(void)
constructor(options = {})
Construct the HAML Coffee compiler.
Instance Method Details
#
(Boolean)
indentChanged()
Test if the indention level has changed, either increased or decreased.
#
(Boolean)
isIndent()
Test if the indention levels has been increased.
#
(void)
updateTabSize()
Calculate the indention size
#
(void)
updateBlockLevel()
Update the current block level indention.
#
(void)
updateCodeBlockLevel(node)
Update the indention level for a code block.
#
(void)
updateParent()
Update the parent node. This depends on the indention if stays the same, goes one down or on up.
#
(void)
pushParent()
Indention level has been increased: Push the current parent node to the stack and make the current node the parent node.
#
(void)
popParent()
Indention level has been decreased: Make the grand parent the current parent.
#
(Object)
getNodeOptions(override = {})
Get the options for creating a node
#
(Node)
nodeFactory(expression = '')
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.
#
(void)
parse(source = '')
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.
Parsing does not create an output, it creates the syntax tree in the
compiler. To get the template, use #render
.
#
(void)
evaluate(node)
Evaluate the parsed tree
#
(void)
render()
Render the parsed source code as CoffeeScript template.
#
(void)
renderStandalone()
Render a standalone version
#
(String)
renderAmd()
Private
Render the parsed source code as CoffeeScript template wrapped in a
define() statement for AMD. If the global modules list contains a module
that starts with hamlcoffee
and is assigned to the hc
param, then
all known helper functions will be taken from the hamlcoffee
helper
module.
#
(String)
renderGlobal()
Private
Render the parsed source code as CoffeeScript template to a global window.HAML variable.
#
(String)
precompile()
Pre-compiles the parsed source and generates the function source code.
#
(String)
createCode()
Create the CoffeeScript code for the template.
This gets an array of all lines to be rendered in the correct sequence.
#
(void)
getBuffer(level)
Get the code buffer identifer
#
(Array<Object>)
combineText(lines)
Optimize the lines to be rendered by combining subsequent text nodes that are on the same code line indention into a single line.
#
(String)
convertBooleans(code)
Adds a boolean convert logic that changes boolean attribute values depending on the output format. This works only when the clean value function add a hint marker (\u0093) to each boolean value, so that the conversion logic can disinguish between dynamic, real boolean values and string values like 'false' and 'true' or compile time attributes.
With the XHTML format, an attribute checked='true'
will be
converted to checked='checked'
and checked='false'
will
be completely removed.
With the HTML4 and HTML5 format, an attribute checked='true'
will be converted to checked
and checked='false'
will
be completely removed.
#
(String)
removeEmptyIDAndClass(code)
Remove empty ID and class attribute from the final template. In case of the ID this is required in order to generate valid HTML.
#
(String)
cleanupWhitespace(code)
Adds whitespace cleanup function when needed by the template. The cleanup must be done AFTER the template has been rendered.
The detection is based on hidden unicode characters that are placed as marker into the template:
\u0091
Cleanup surrounding whitespace to the left\u0092
Cleanup surrounding whitespace to the right
#
(Object)
findDependencies(code)
Searches for AMD require statements to find all template dependencies.
Examples:
CST source code
$o.push "" + $c require('assets/templates/test')() => { test: 'assets/templates/test' }