1bbmustache 2=========== 3[![Build Status](https://travis-ci.org/soranoba/bbmustache.svg?branch=master)](https://travis-ci.org/soranoba/bbmustache) 4[![hex.pm version](https://img.shields.io/hexpm/v/bbmustache.svg)](https://hex.pm/packages/bbmustache) 5 6Binary pattern match Based Mustache template engine for Erlang/OTP. 7 8## Overview 9- Binary pattern match based mustache template engine for Erlang/OTP. 10 - Do not use a regular expression !! 11- Support maps and associative arrays. 12 13### What is Mustach ? 14A logic-less templates. 15- [{{mustache}}](http://mustache.github.io/) 16 17## Usage 18### Quick start 19 20```bash 21$ git clone git://github.com/soranoba/bbmustache.git 22$ cd bbmustache 23$ make start 24Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:true] 25 26Eshell V6.3 (abort with ^G) 271> {ok,[bbmustache]} 281> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}). 29<<"hoge">> 302> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]). 31<<"hoge">> 32``` 33 34### Use as a library 35Add the following settings. 36 37```erlang 38%% rebar (rebar.config) 39 40{deps, 41 [ 42 {bbmustache, ".*", {git, "git://github.com/soranoba/bbmustache.git", {branch, "master"}}} 43 ]}. 44 45%% rebar3 (rebar.config) 46 47{deps, [bbmustache]}. 48``` 49 50If you don't use the rebar and use the OTP17 or later, this library should be compile with `-Dnamespaced_types`. 51 52### How to use simple Mustache 53 54Map (R17 or later) 55```erlang 561> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}). 57<<"hoge">> 58 592> Template1 = bbmustache:parse_binary(<<"{{name}}">>). 60... 613> bbmustache:compile(Template1, #{"name" => "hoge"}). 62<<"hoge">> 63 644> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>). 65... 665> bbmustache:compile(Template2, #{"name" => "hoge"}). 67<<"hoge">> 68``` 69 70Associative array 71```erlang 721> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]). 73<<"hoge">> 74 752> Template1 = bbmustache:parse_binary(<<"{{name}}">>). 76... 773> bbmustache:compile(Template1, [{"name", "hoge"}]). 78<<"hoge">> 79 804> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>). 81... 825> bbmustache:compile(Template2, [{"name", "hoge"}]). 83<<"hoge">> 84``` 85 86### More information 87Please refer to [the man page](http://mustache.github.io/mustache.5.html) and [the spec](https://github.com/mustache/spec) of mustache as the need arises.<br /> 88 89Please see [this](benchmarks/README.md) for a list of features that bbmustache supports. 90 91## FAQ 92 93### Avoid http escaping 94 95```erlang 96%% please use {{{tag}}} 971> bbmustache:render(<<"<h1>{{{tag}}}</h1>">>, #{"tag" => "I like Erlang & mustache"}). 98<<"<h1>I like Erlang & mustache</h1>">> 99``` 100 101### Want to use symbol of tag 102 103```erlang 1041> bbmustache:render(<<"{{=<< >>=}} <<tag>>, <<={{ }}=>> {{tag}}">>, #{"tag" => "hi"}). 105<<" hi, hi">> 106``` 107 108### Want to change the type of the key 109 110```erlang 1111> bbmustache:render(<<"{{tag}}">>, #{tag => "hi"}, [{key_type, atom}]). 112<<"hi">> 113``` 114 115## Attention 116- Lambda expression is included wasted processing. 117 - Because it is optimized to `parse_string/1` + `compile/2`. 118 119## Comparison with other libraries 120[Benchmarks and check the reference implementation](benchmarks/README.md) 121 122## Contribute 123Pull request is welcome =D 124 125## License 126[MIT License](LICENSE) 127