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

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

Returns:

  • ( String ) — the CoffeeScript template source code

# (String) renderGlobal() Private

Render the parsed source code as CoffeeScript template to a global window.HAML variable.

Returns:

  • ( String ) — the CoffeeScript template source code

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

    Control the navigation frame:

    You can focus and blur the search input: