Skip to content

Commit

Permalink
Merge branch 'bbmustache'
Browse files Browse the repository at this point in the history
  • Loading branch information
soranoba committed Jun 21, 2015
2 parents acbbe29 + 4023cf5 commit 4753677
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP=mustache
APP=bbmustache
DIALYZER_OPTS=-Werror_handling -Wrace_conditions -Wunmatched_returns

LIBS=$(ERL_LIBS):_build/dev/lib
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mustache
bbmustache
===========
Mustache template engine for Erlang/OTP.
Binary pattern match Based Mustache template engine for Erlang/OTP.

## What is Mustach ?
A logic-less templates.
Expand All @@ -15,16 +15,16 @@ A logic-less templates.
### Quick start

```bash
$ git clone git://github.com/soranoba/mustache.git
$ cd mustache
$ git clone git://github.com/soranoba/bbmustache.git
$ cd bbmustache
$ make start
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:true]

Eshell V6.3 (abort with ^G)
1> {ok,[mustache]}
1> mustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
1> {ok,[bbmustache]}
1> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
<<"hoge">>
2> mustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
2> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
<<"hoge">>
```
Expand All @@ -36,45 +36,45 @@ Add the following settings.
{deps,
[
{mustache, ".*", {git, "git://github.com/soranoba/mustache.git", {branch, "master"}}}
{bbmustache, ".*", {git, "git://github.com/soranoba/bbmustache.git", {branch, "master"}}}
]}.
```
If you don't use the rebar and use the after OTP17, this library should be compile with `-Dnamespaced_types`.
If you don't use the rebar and use the OTP17 or later, this library should be compile with `-Dnamespaced_types`.
### How to use simple Mustache
- [Mastache Manual](http://mustache.github.io/mustache.5.html)
- Support all of syntax !
Map (R17 or later)
```erlang
1> mustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
1> bbmustache:render(<<"{{name}}">>, #{"name" => "hoge"}).
<<"hoge">>
2> Template1 = mustache:parse_binary(<<"{{name}}">>).
2> Template1 = bbmustache:parse_binary(<<"{{name}}">>).
...
3> mustache:compile(Template1, #{"name" => "hoge"}).
3> bbmustache:compile(Template1, #{"name" => "hoge"}).
<<"hoge">>
4> Template2 = mustache:parse_file(<<"./hoge.mustache">>).
4> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>).
...
5> mustache:compile(Template2, #{"name" => "hoge"}).
5> bbmustache:compile(Template2, #{"name" => "hoge"}).
<<"hoge">>
```
Associative array
```erlang
1> mustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
1> bbmustache:render(<<"{{name}}">>, [{"name", "hoge"}]).
<<"hoge">>
2> Template1 = mustache:parse_binary(<<"{{name}}">>).
2> Template1 = bbmustache:parse_binary(<<"{{name}}">>).
...
3> mustache:compile(Template1, [{"name", "hoge"}]).
3> bbmustache:compile(Template1, [{"name", "hoge"}]).
<<"hoge">>
4> Template2 = mustache:parse_file(<<"./hoge.mustache">>).
4> Template2 = bbmustache:parse_file(<<"./hoge.mustache">>).
...
5> mustache:compile(Template2, [{"name", "hoge"}]).
5> bbmustache:compile(Template2, [{"name", "hoge"}]).
<<"hoge">>
```
Expand All @@ -87,7 +87,7 @@ You want more information, see the [doc](doc).
## Simple Benchmark
||[moyombo/mustache.erl](https://github.com/mojombo/mustache.erl)|[soranoba/mustache](https://github.com/soranoba/mustache)|
||[moyombo/mustache.erl](https://github.com/mojombo/mustache.erl)|[soranoba/bbmustache](https://github.com/soranoba/bbmustache)|
|:--|:---|:---|
|score (time) |1016414 |33001|
Expand Down
38 changes: 19 additions & 19 deletions ct/mustache_SUITE.erl → ct/bbmustache_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%% @copyright 2015 Hinagiku Soranoba All Rights Reserved.

-module(mustache_SUITE).
-module(bbmustache_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

Expand Down Expand Up @@ -72,71 +72,71 @@ end_per_group(_, _) ->
%%----------------------------------------------------------------------------------------------------------------------

variables_ct(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"variables.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"variables.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"variables.result">>])),

Data = [{"name", "Chris"}, {"company", "<b>GitHub</b>"}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

sections_ct1(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"false_values.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"false_values.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"false_values.result">>])),

Data1 = [{"person", false}],
Data2 = [{"person", []}],
Data3 = [],
[?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(X)))
[?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(X)))
|| X <- [Data1, Data2, Data3]].

sections_ct2(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"non-empty.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"non-empty.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"non-empty.result">>])),

Data = [{"repo", [ [{"name", "resque"}], [{"name", "hub"}], [{"name", "rip"}]]}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

sections_ct3(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"non-false.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"non-false.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"non-false.result">>])),

Data = [{"person?", [{"name", "Jon"}]}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

sections_ct4(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"invarted.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"invarted.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"invarted.result">>])),

Data = [{"repo", []}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

lambdas_ct(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"lambdas.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"lambdas.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"lambdas.result">>])),

F = fun(Text, Render) -> ["<b>", Render(Text), "</b>"] end,
Data = [{"name", "Willy"}, {"wrapped", F}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

comments_ct(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"comment.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"comment.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"comment.result">>])),

Data = [],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

partials_ct(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"partial.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"partial.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"partial.result">>])),

Data = [{"names", [[{"name", "alice"}], [{"name", "bob"}]]}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

delimiter_ct(Config) ->
Template = mustache:parse_file(filename:join([?config(data_dir, Config), <<"delimiter.mustache">>])),
Template = bbmustache:parse_file(filename:join([?config(data_dir, Config), <<"delimiter.mustache">>])),
{ok, File} = file:read_file(filename:join([?config(data_dir, Config), <<"delimiter.result">>])),

Data = [{"default_tags", "tag1"}, {"erb_style_tags", "tag2"}, {"default_tags_again", "tag3"}],
?assertEqual(File, mustache:compile(Template, (?config(data_conv, Config))(Data))).
?assertEqual(File, bbmustache:compile(Template, (?config(data_conv, Config))(Data))).

%%----------------------------------------------------------------------------------------------------------------------
%% Internal Functions
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ct/mustache_eunit_SUITE.erl → ct/bbmustache_eunit_SUITE.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%% @copyright 2015 Hinagiku Soranoba All Rights Reserved.

-module(mustache_eunit_SUITE).
-module(bbmustache_eunit_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").

Expand All @@ -20,4 +20,4 @@ all() ->
%%----------------------------------------------------------------------------------------------------------------------

eunit_ct(_Config) ->
ok = eunit:test({application, mustache}).
ok = eunit:test({application, bbmustache}).
4 changes: 2 additions & 2 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@


# The mustache application #
# The bbmustache application #


## Modules ##


<table width="100%" border="0" summary="list of modules">
<tr><td><a href="mustache.md" class="module">mustache</a></td></tr></table>
<tr><td><a href="bbmustache.md" class="module">bbmustache</a></td></tr></table>

10 changes: 5 additions & 5 deletions doc/mustache.md → doc/bbmustache.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@


# Module mustache #
# Module bbmustache #
* [Description](#description)
* [Data Types](#types)
* [Function Index](#index)
* [Function Details](#functions)


Mustach template engine for Erlang/OTP.
Binary pattern match Based Mustach template engine for Erlang/OTP.
Copyright (c) 2015 Hinagiku Soranoba All Rights Reserved.


Expand Down Expand Up @@ -104,7 +104,7 @@ Equivalent to [`compile(Template, Data, [])`](#compile-3).


<pre><code>
compile(Mustache::<a href="#type-template">template()</a>, Data::<a href="#type-data">data()</a>, Options::[<a href="#type-option">option()</a>]) -&gt; binary()
compile(Bbmustache::<a href="#type-template">template()</a>, Data::<a href="#type-data">data()</a>, Options::[<a href="#type-option">option()</a>]) -&gt; binary()
</code></pre>
<br />

Expand All @@ -114,8 +114,8 @@ Embed the data in the template.


```
1> Template = mustache:parse_binary(<<"{{name}}">>).
2> mustache:compile(Template, #{"name" => "Alice"}).
1> Template = bbmustache:parse_binary(<<"{{name}}">>).
2> bbmustache:compile(Template, #{"name" => "Alice"}).
<<"Alice">>
```

Expand Down
4 changes: 2 additions & 2 deletions src/mustache.app.src → src/bbmustache.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% vim: set ft=erlang : -*- erlang -*-
{application, mustache,
{application, bbmustache,
[
{description, "Mustache template engine for Erlang/OTP"},
{description, "Binary pattern match Based Mustache template engine for Erlang/OTP"},
{vsn, git},
{registered, []},
{applications, [
Expand Down
8 changes: 4 additions & 4 deletions src/mustache.erl → src/bbmustache.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% @copyright 2015 Hinagiku Soranoba All Rights Reserved.
%%
%% @doc Mustach template engine for Erlang/OTP.
-module(mustache).
%% @doc Binary pattern match Based Mustach template engine for Erlang/OTP.
-module(bbmustache).

%%----------------------------------------------------------------------------------------------------------------------
%% Exported API
Expand Down Expand Up @@ -112,8 +112,8 @@ compile(Template, Data) ->
%% @doc Embed the data in the template.
%%
%% ```
%% 1> Template = mustache:parse_binary(<<"{{name}}">>).
%% 2> mustache:compile(Template, #{"name" => "Alice"}).
%% 1> Template = bbmustache:parse_binary(<<"{{name}}">>).
%% 2> bbmustache:compile(Template, #{"name" => "Alice"}).
%% <<"Alice">>
%% '''
%% Data support assoc list or maps (OTP17 or later). <br />
Expand Down
18 changes: 9 additions & 9 deletions test/mustache_tests.erl → test/bbmustache_tests.erl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% coding: latin-1
%% @copyright 2015 Hinagiku Soranoba All Rights Reserved.

-module(mustache_tests).
-module(bbmustache_tests).
-include_lib("eunit/include/eunit.hrl").

%%----------------------------------------------------------------------------------------------------------------------
Expand All @@ -11,19 +11,19 @@
-define(PARSE_ERROR, incorrect_format).
-define(FILE_ERROR, file_not_found).

-define(NT_S(X, Y), ?_assertMatch({_, X}, mustache:parse_binary(Y))).
-define(NT_S(X, Y), ?_assertMatch({_, X}, bbmustache:parse_binary(Y))).
%% parse_binary_test generater (success case)
-define(NT_F(X, Y), ?_assertError(X, mustache:parse_binary(Y))).
-define(NT_F(X, Y), ?_assertError(X, bbmustache:parse_binary(Y))).
%% parse_binary_test generater (failure case)

parse_file_test_() ->
[
{"file_not_exist", ?_assertError(?FILE_ERROR, mustache:parse_file(<<"not_exist">>))}
{"file_not_exist", ?_assertError(?FILE_ERROR, bbmustache:parse_file(<<"not_exist">>))}
].

parse_binary_test_() ->
[
{"mustache:template/0 format check", ?NT_S([<<>>], <<>>)},
{"bbmustache:template/0 format check", ?NT_S([<<>>], <<>>)},

{"{{tag}}", ?NT_S([<<"a">>, {n, <<"t">>}, <<"b">>], <<"a{{t}}b">>)},
{"{{ tag }}", ?NT_S([<<>>, {n, <<"t">>}, <<>>], <<"{{ t }}">>)},
Expand Down Expand Up @@ -93,7 +93,7 @@ assoc_list_render_test_() ->
{"integer, float, binary, string",
fun() ->
?assertEqual(<<"1, 1.5, hoge, fugo, atom">>,
mustache:render(<<"{{i}}, {{f}}, {{b}}, {{s}}, {{a}}">>,
bbmustache:render(<<"{{i}}, {{f}}, {{b}}, {{s}}, {{a}}">>,
[{"i", 1}, {"f", 1.5}, {"b", <<"hoge">>}, {"s", "fugo"}, {"a", atom}]))
end}
].
Expand All @@ -104,20 +104,20 @@ atom_and_binary_key_test_() ->
fun() ->
F = fun(Text, Render) -> ["<b>", Render(Text), "</b>"] end,
?assertEqual(<<"<b>Willy is awesome.</b>">>,
mustache:render(<<"{{#wrapped}}{{name}} is awesome.{{dummy_atom}}{{/wrapped}}">>,
bbmustache:render(<<"{{#wrapped}}{{name}} is awesome.{{dummy_atom}}{{/wrapped}}">>,
[{name, "Willy"}, {wrapped, F}], [{key_type, atom}])),
?assertError(_, binary_to_existing_atom(<<"dummy_atom">>, utf8))
end},
{"binary key",
fun() ->
F = fun(Text, Render) -> ["<b>", Render(Text), "</b>"] end,
?assertEqual(<<"<b>Willy is awesome.</b>">>,
mustache:render(<<"{{#wrapped}}{{name}} is awesome.{{dummy}}{{/wrapped}}">>,
bbmustache:render(<<"{{#wrapped}}{{name}} is awesome.{{dummy}}{{/wrapped}}">>,
[{<<"name">>, "Willy"}, {<<"wrapped">>, F}], [{key_type, binary}]))
end}
].

unsupported_data_test_() ->
[
{"dict", ?_assertError(function_clause, mustache:render(<<>>, dict:new()))}
{"dict", ?_assertError(function_clause, bbmustache:render(<<>>, dict:new()))}
].

0 comments on commit 4753677

Please sign in to comment.