<commit_before># Haml Coffee Templates [![Build Status](https://secure.travis-ci.org/netzpirat/haml-coffee.png)](http://travis-ci.org/netzpirat/haml-coffee)

Haml Coffee is a JavaScript templating solution that uses [Haml](http://haml-lang.com/) as markup, understands inline
[CoffeeScript](http://jashkenas.github.com/coffee-script/) and generates a JavaScript function that renders to HTML. It
can be used in client-side JavaScript applications that are using
[Backbone.js](http://documentcloud.github.com/backbone/), [Spine.js](http://spinejs.com/),
[JavaScriptMVC](http://javascriptmvc.com/), [KnockoutJS](http://knockoutjs.com/) and others, or on the server-side in
frameworks like [Express](http://expressjs.com/).

You can try Haml Coffee online by visiting [Haml Coffee Online](http://haml-coffee-online.herokuapp.com/).

## Installation

Haml Coffee is available in NPM and can be installed with:

```bash
$ npm install haml-coffee
```

Please have a look at the [CHANGELOG](https://github.com/netzpirat/haml-coffee/blob/master/CHANGELOG.md) when upgrading to a
newer Codo version with `npm update`.

## Integration

If you're using [Hem](https://github.com/maccman/hem) to manage your CommonJS modules,
use [hem-haml-coffee](https://github.com/vojto/hem-haml-coffee). This is excellent for
developing your [Spine](http://spinejs.com/) application.

If you like to integrate Haml Coffee seamless into the Rails asset pipeline, check out
[haml_coffee_assets](https://github.com/netzpirat/haml_coffee_assets).

For using the Haml Coffee compiler in the browser, a [browserified](https://github.com/substack/node-browserify) version
is provided in the `dist/compiler` directory:
[Haml Coffee compiler](https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.js)
([minified](https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.min.js))

## Compile Haml Coffee

### Using the API

You can compile a Haml Coffee template to a JavaScript function and execute the function with the locals to render the
HTML. The following code

```coffee-script
hamlc = require 'haml-coffee'
tmpl = hamlc.compile '%h1= @title'
html = tmpl title: 'Haml Coffee rocks!'
```

will create the HTML `<h1>Haml Coffee rocks!</h1>`.

The `compile` function can take the compiler options as second parameter to customize the template function:

```coffee-script
hamlc.compile '%h1= @title'
  cleanValue: false
  escapeHtml: false
```

See the [compiler options](#compiler-options) for detailed information about all the available options and browse
the [codo](https://github.com/netzpirat/codo) generated
[Haml-Coffee API documentation](http://netzpirat.github.com/haml-coffee/).

### Using with Express

You can configure [Express](http://expressjs.com/) to use Haml Coffee as template engine.

#### Express 3

Starting with version 1.4.0, Haml Coffee has support for Express 3 and can be registered as view engine as follows:

```coffee-script
express = require 'express'
cons    = require 'consolidate'

app = express.createServer()
app.engine '.hamlc', require('haml-coffee').__express
```

Alternatively you can also use [consolidate.js](https://github.com/visionmedia/consolidate.js) to register the engine:

```coffee-script
express = require 'express'

app = express.createServer()
app.engine '.hamlc', cons['haml-coffee']
```

Until [consolidate.js pull request #49](https://github.com/visionmedia/consolidate.js/pull/49) is merged, it's
recommended to directly use the Haml Coffee `__express` function over consolidate.js to have improved render speed.

#### Express 2

Starting with version 0.5.0, Haml Coffee has support for Express 2 and can be registered as view engine as follows:

```coffee-script
express = require 'express'

app = express.createServer()
app.register '.hamlc', require('haml-coffee')
```

Alternatively you can also use [consolidate.js](https://github.com/visionmedia/consolidate.js) to register the engine:

```coffee-script
express = require 'express'

app = express.createServer()
app.register '.hamlc', cons['haml-coffee']
```

#### Usage

Express uses a layout file `layout.hamlc` by default and you have to insert the rendered view body into the layout like
this:

```haml
!!!<commit_msg>Remove consolidate.js explanation. [ci skip]<commit_after># Haml Coffee Templates [![Build Status](https://secure.travis-ci.org/netzpirat/haml-coffee.png)](http://travis-ci.org/netzpirat/haml-coffee)

Haml Coffee is a JavaScript templating solution that uses [Haml](http://haml-lang.com/) as markup, understands inline
[CoffeeScript](http://jashkenas.github.com/coffee-script/) and generates a JavaScript function that renders to HTML. It
can be used in client-side JavaScript applications that are using
[Backbone.js](http://documentcloud.github.com/backbone/), [Spine.js](http://spinejs.com/),
[JavaScriptMVC](http://javascriptmvc.com/), [KnockoutJS](http://knockoutjs.com/) and others, or on the server-side in
frameworks like [Express](http://expressjs.com/).

You can try Haml Coffee online by visiting [Haml Coffee Online](http://haml-coffee-online.herokuapp.com/).

## Installation

Haml Coffee is available in NPM and can be installed with:

```bash
$ npm install haml-coffee
```

Please have a look at the [CHANGELOG](https://github.com/netzpirat/haml-coffee/blob/master/CHANGELOG.md) when upgrading to a
newer Codo version with `npm update`.

## Integration

If you're using [Hem](https://github.com/maccman/hem) to manage your CommonJS modules,
use [hem-haml-coffee](https://github.com/vojto/hem-haml-coffee). This is excellent for
developing your [Spine](http://spinejs.com/) application.

If you like to integrate Haml Coffee seamless into the Rails asset pipeline, check out
[haml_coffee_assets](https://github.com/netzpirat/haml_coffee_assets).

For using the Haml Coffee compiler in the browser, a [browserified](https://github.com/substack/node-browserify) version
is provided in the `dist/compiler` directory:
[Haml Coffee compiler](https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.js)
([minified](https://raw.github.com/netzpirat/haml-coffee/master/dist/compiler/hamlcoffee.min.js))

## Compile Haml Coffee

### Using the API

You can compile a Haml Coffee template to a JavaScript function and execute the function with the locals to render the
HTML. The following code

```coffee-script
hamlc = require 'haml-coffee'
tmpl = hamlc.compile '%h1= @title'
html = tmpl title: 'Haml Coffee rocks!'
```

will create the HTML `<h1>Haml Coffee rocks!</h1>`.

The `compile` function can take the compiler options as second parameter to customize the template function:

```coffee-script
hamlc.compile '%h1= @title'
  cleanValue: false
  escapeHtml: false
```

See the [compiler options](#compiler-options) for detailed information about all the available options and browse
the [codo](https://github.com/netzpirat/codo) generated
[Haml-Coffee API documentation](http://netzpirat.github.com/haml-coffee/).

### Using with Express

You can configure [Express](http://expressjs.com/) to use Haml Coffee as template engine.

#### Express 3

Starting with version 1.4.0, Haml Coffee has support for Express 3 and can be registered as view engine as follows:

```coffee-script
express = require 'express'
cons    = require 'consolidate'

app = express.createServer()
app.engine '.hamlc', require('haml-coffee').__express
```

Alternatively you can also use [consolidate.js](https://github.com/visionmedia/consolidate.js) to register the engine:

```coffee-script
express = require 'express'

app = express.createServer()
app.engine '.hamlc', cons['haml-coffee']
```

#### Express 2

Starting with version 0.5.0, Haml Coffee has support for Express 2 and can be registered as view engine as follows:

```coffee-script
express = require 'express'

app = express.createServer()
app.register '.hamlc', require('haml-coffee')
```

Alternatively you can also use [consolidate.js](https://github.com/visionmedia/consolidate.js) to register the engine:

```coffee-script
express = require 'express'

app = express.createServer()
app.register '.hamlc', cons['haml-coffee']
```

#### Usage

Express uses a layout file `layout.hamlc` by default and you have to insert the rendered view body into the layout like
this:

```haml
!!!
{'fraction_non_alphanumeric': 0.12637031682929767, 'fraction_numerical': 0.0038549572340681845, 'mean_word_length': 5.020304568527918, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 23, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '35118', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2541, 'n_words': 816}