# Class: HamlCoffee

Defined in: | 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.

## 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) 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.

### Parameters:

- options ( `Object` ) — the compiler options

### Options Hash: (options):

- placement ( `String` ) — where to place the resultant function
- dependencies ( `Array<String>` ) — dependencies for the amd module
- escapeHtml ( `Boolean` ) — escape the output when true
- escapeAttributes ( `Boolean` ) — escape the tag attributes when true
- cleanValue ( `Boolean` ) — clean CoffeeScript values before inserting
- uglify ( `Boolean` ) — don't indent generated HTML when true
- basename ( `Boolean` ) — ignore file path when generate the template name
- extendScope ( `Boolean` ) — extend the template scope with the context
- format ( `String` ) — the template format, either `xhtml`, `html4` or `html5`
- hyphenateDataAttrs ( `String` ) — whether to convert underscores to hyphens in data attributes
- preserveTags ( `String` ) — a comma separated list of tags to preserve content whitespace
- selfCloseTags ( `String` ) — a comma separated list of self closing HTML tags
- customHtmlEscape ( `String` ) — the name of the function for HTML escaping
- customCleanValue ( `String` ) — the name of the function to clean code insertion values before output
- customFindAndPreserve ( `String` ) — the name of the function used to find and preserve whitespace
- customPreserve ( `String` ) — the name of the function used to preserve the whitespace
- customReference ( `String` ) — the name of the function used to create the id from object references

## Instance Method Details

# (Boolean) indentChanged()

Test if the indention level has changed, either increased or decreased.

### Returns:

- ( `Boolean` ) — true when indention changed

# (Boolean) isIndent()

Test if the indention levels has been increased.

### Returns:

- ( `Boolean` ) — true when 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.

### Parameters:

- node ( `Node` ) — the node to update

# (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

### Parameters:

- override ( `Object` ) — the options to override

### Returns:

- ( `Object` ) — the node options

# (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.

### Parameters:

- expression ( `String` ) — the HAML expression

### Returns:

- ( `Node` ) — the parser node

# (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`.

### Parameters:

- source ( `String` ) — the HAML source code

# (void) evaluate(node)

Evaluate the parsed tree

### Parameters:

- node ( `Node` ) — the node to evaluate

# (void) render()

Render the parsed source code as CoffeeScript template.

# (void) renderStandalone()

Render a standalone version

# (String) precompile()

Pre-compiles the parsed source and generates the function source code.

### Returns:

- ( `String` ) — the template 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.

### Returns:

- ( `String` ) — the CoffeeScript code

# (void) getBuffer(level)

Get the code buffer identifer

### Parameters:

- level ( `Number` ) — the block indention level

# (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.

### Parameters:

- lines ( `Array<Object>` ) — the code lines

### Returns:

- ( `Array<Object>` ) — the optimized lines

# (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.

### Parameters:

- code ( `String` ) — the CoffeeScript template code

### Returns:

- ( `String` ) — the clean up whitespace code if necessary

# (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.

### Parameters:

- code ( `String` ) — the CoffeeScript template code

### Returns:

- ( `String` ) — the template code with the code added

# (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

### Parameters:

- code ( `String` ) — the CoffeeScript template code

### Returns:

- ( `String` ) — the clean up whitespace code if necessary

# (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' }

### Parameters:

- code ( `String` ) — the CoffeeScript template source code

### Returns:

- ( `Object` ) — the module dependencies

Quickly fuzzy find classes, mixins, methods, file:

- T Open fuzzy finder dialog

Control the navigation frame:

- L Toggle list view
- C Show class list
- I Show mixin list
- F Show file list
- M Show method list
- E Show extras list

You can focus and blur the search input:

- S Focus search input
- Esc Blur search input