<commit_before># Mustache templates

A Dart library to parse and render [mustache templates](http://mustache.github.com/mustache.5.html).

[![Build Status](https://drone.io/github.com/xxgreg/mustache/status.png)](https://drone.io/github.com/xxgreg/mustache/latest)

## Example
```dart
	import 'package:mustache/mustache.dart' as mustache;

	main() {
		var source = '{{#names}}<div>{{lastname}}, {{firstname}}</div>{{/names}}';
		var template = mustache.parse(source);
		var output = template.renderString({'names': [
			{'firstname': 'Greg', 'lastname': 'Lowe'},
			{'firstname': 'Bob', 'lastname': 'Johnson'}
		]});
		print(output);
	}
```

## API

```dart

abstract class Template {
	
	Template(String source, 
	    {bool lenient : false,
       bool htmlEscapeValues : true,
       String name,
       PartialResolver partialResolver});

	String renderString(values);
	void render(values, StringSink sink);
}

```

Once a template has been created it can be rendered any number of times.

Both parsing and render throw a TemplateException if there is a problem with the template or rendering the values.

When lenient mode is enabled tag names may use any characters, otherwise only a-z, A-Z, 0-9, underscore and minus. Lenient mode will also silently ignore nulls passed as values.

By default all variables are html escaped, this behaviour can be changed by passing htmlEscapeValues : false.


## Supported 
```
 Variables             {{var-name}}
 
 Sections              {{#section}}Blah{{/section}}
 
 Inverse sections      {{^section}}Blah{{/section}}
 
 Comments              {{! Not output. }}
 
 Unescaped variables   {{{var-name}}} and {{&var-name}}
 
 Partials              {{>include-other-file}}

 Lambdas               new Template('{{# foo }}oi{{/ foo }}')
                          .renderString({'foo': (s) => '<b>${s.toUpperCase()}</b>'});
```
See the [mustache templates tutorial](http://mustache.github.com/mustache.5.html) for more information.

Passing all [mustache specification](https://github.com/mustache/spec/tree/master/specs) tests for interpolation, sections, inverted, comments.

Lambdas are implemented differently from the specification. In this implementation, a lambda is provided with a String containing the rendered body of the template, and the output of the lambda is not re-interpolated. However this is sufficient for common use cases such as:

    new Template('{{# foo }}oi{{/ foo }}')
	     .renderString({'foo': (s) => '<b>${s.toUpperCase()}</b>'}); // <b>OI</b>

## To do
```
Implement auto-indenting for partials
Set Delimiter tags
```
<commit_msg>Add mirrors note.<commit_after># Mustache templates

A Dart library to parse and render [mustache templates](http://mustache.github.com/mustache.5.html).

[![Build Status](https://drone.io/github.com/xxgreg/mustache/status.png)](https://drone.io/github.com/xxgreg/mustache/latest)

## Dart2js

This library uses mirrors. When compiling with dart2js you will need to pass the experimental mirrors flag. You also need to mark any objects which will be rendered with the @mustache annotation.

## Example
```dart
	import 'package:mustache/mustache.dart';

	main() {
		var source = '{{#names}}<div>{{lastname}}, {{firstname}}</div>{{/names}}';
		var template = new Template(source);
		var output = template.renderString({'names': [
			{'firstname': 'Greg', 'lastname': 'Lowe'},
			{'firstname': 'Bob', 'lastname': 'Johnson'}
		]});
		print(output);
	}
```

## API

```dart

abstract class Template {
	
	Template(String source, 
	    {bool lenient : false,
       bool htmlEscapeValues : true,
       String name,
       PartialResolver partialResolver});

	String renderString(values);
	void render(values, StringSink sink);
}

```

Once a template has been created it can be rendered any number of times.

Both parsing and render throw a TemplateException if there is a problem with the template or rendering the values.

When lenient mode is enabled tag names may use any characters, otherwise only a-z, A-Z, 0-9, underscore and minus. Lenient mode will also silently ignore nulls passed as values.

By default all variables are html escaped, this behaviour can be changed by passing htmlEscapeValues : false.


## Supported 
```
 Variables             {{var-name}}
 
 Sections              {{#section}}Blah{{/section}}
 
 Inverse sections      {{^section}}Blah{{/section}}
 
 Comments              {{! Not output. }}
 
 Unescaped variables   {{{var-name}}} and {{&var-name}}
 
 Partials              {{>include-other-file}}

 Lambdas               new Template('{{# foo }}oi{{/ foo }}')
                          .renderString({'foo': (s) => '<b>${s.toUpperCase()}</b>'});
```
See the [mustache templates tutorial](http://mustache.github.com/mustache.5.html) for more information.

Passing all [mustache specification](https://github.com/mustache/spec/tree/master/specs) tests for interpolation, sections, inverted, comments.

Lambdas are implemented differently from the specification. In this implementation, a lambda is provided with a String containing the rendered body of the template, and the output of the lambda is not re-interpolated. However this is sufficient for common use cases such as:

    new Template('{{# foo }}oi{{/ foo }}')
	     .renderString({'foo': (s) => '<b>${s.toUpperCase()}</b>'}); // <b>OI</b>

## To do
```
Implement auto-indenting for partials
Set Delimiter tags
```

{'fraction_non_alphanumeric': 0.13854417484719392, 'fraction_numerical': 0.0018521948508983144, 'mean_word_length': 3.7161572052401746, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 6, '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': '30053', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1525, 'n_words': 528}