diff --git a/Makefile b/Makefile index 3b63dd3..60b7789 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -APP=mustache +APP=bbmustache DIALYZER_OPTS=-Werror_handling -Wrace_conditions -Wunmatched_returns LIBS=$(ERL_LIBS):_build/dev/lib diff --git a/README.md b/README.md index 2fb17bf..a102244 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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">> ``` @@ -36,11 +36,11 @@ 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) @@ -48,33 +48,33 @@ If you don't use the rebar and use the after OTP17, this library should be compi 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">> ``` @@ -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| diff --git a/ct/mustache_SUITE.erl b/ct/bbmustache_SUITE.erl similarity index 74% rename from ct/mustache_SUITE.erl rename to ct/bbmustache_SUITE.erl index 82e471c..1142e93 100644 --- a/ct/mustache_SUITE.erl +++ b/ct/bbmustache_SUITE.erl @@ -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"). @@ -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", "GitHub"}], - ?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) -> ["", Render(Text), ""] 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 diff --git a/ct/mustache_SUITE_data/comment.mustache b/ct/bbmustache_SUITE_data/comment.mustache similarity index 100% rename from ct/mustache_SUITE_data/comment.mustache rename to ct/bbmustache_SUITE_data/comment.mustache diff --git a/ct/mustache_SUITE_data/comment.result b/ct/bbmustache_SUITE_data/comment.result similarity index 100% rename from ct/mustache_SUITE_data/comment.result rename to ct/bbmustache_SUITE_data/comment.result diff --git a/ct/mustache_SUITE_data/delimiter.mustache b/ct/bbmustache_SUITE_data/delimiter.mustache similarity index 100% rename from ct/mustache_SUITE_data/delimiter.mustache rename to ct/bbmustache_SUITE_data/delimiter.mustache diff --git a/ct/mustache_SUITE_data/delimiter.result b/ct/bbmustache_SUITE_data/delimiter.result similarity index 100% rename from ct/mustache_SUITE_data/delimiter.result rename to ct/bbmustache_SUITE_data/delimiter.result diff --git a/ct/mustache_SUITE_data/false_values.mustache b/ct/bbmustache_SUITE_data/false_values.mustache similarity index 100% rename from ct/mustache_SUITE_data/false_values.mustache rename to ct/bbmustache_SUITE_data/false_values.mustache diff --git a/ct/mustache_SUITE_data/false_values.result b/ct/bbmustache_SUITE_data/false_values.result similarity index 100% rename from ct/mustache_SUITE_data/false_values.result rename to ct/bbmustache_SUITE_data/false_values.result diff --git a/ct/mustache_SUITE_data/invarted.mustache b/ct/bbmustache_SUITE_data/invarted.mustache similarity index 100% rename from ct/mustache_SUITE_data/invarted.mustache rename to ct/bbmustache_SUITE_data/invarted.mustache diff --git a/ct/mustache_SUITE_data/invarted.result b/ct/bbmustache_SUITE_data/invarted.result similarity index 100% rename from ct/mustache_SUITE_data/invarted.result rename to ct/bbmustache_SUITE_data/invarted.result diff --git a/ct/mustache_SUITE_data/lambdas.mustache b/ct/bbmustache_SUITE_data/lambdas.mustache similarity index 100% rename from ct/mustache_SUITE_data/lambdas.mustache rename to ct/bbmustache_SUITE_data/lambdas.mustache diff --git a/ct/mustache_SUITE_data/lambdas.result b/ct/bbmustache_SUITE_data/lambdas.result similarity index 100% rename from ct/mustache_SUITE_data/lambdas.result rename to ct/bbmustache_SUITE_data/lambdas.result diff --git a/ct/mustache_SUITE_data/non-empty.mustache b/ct/bbmustache_SUITE_data/non-empty.mustache similarity index 100% rename from ct/mustache_SUITE_data/non-empty.mustache rename to ct/bbmustache_SUITE_data/non-empty.mustache diff --git a/ct/mustache_SUITE_data/non-empty.result b/ct/bbmustache_SUITE_data/non-empty.result similarity index 100% rename from ct/mustache_SUITE_data/non-empty.result rename to ct/bbmustache_SUITE_data/non-empty.result diff --git a/ct/mustache_SUITE_data/non-false.mustache b/ct/bbmustache_SUITE_data/non-false.mustache similarity index 100% rename from ct/mustache_SUITE_data/non-false.mustache rename to ct/bbmustache_SUITE_data/non-false.mustache diff --git a/ct/mustache_SUITE_data/non-false.result b/ct/bbmustache_SUITE_data/non-false.result similarity index 100% rename from ct/mustache_SUITE_data/non-false.result rename to ct/bbmustache_SUITE_data/non-false.result diff --git a/ct/mustache_SUITE_data/partial.mustache b/ct/bbmustache_SUITE_data/partial.mustache similarity index 100% rename from ct/mustache_SUITE_data/partial.mustache rename to ct/bbmustache_SUITE_data/partial.mustache diff --git a/ct/mustache_SUITE_data/partial.result b/ct/bbmustache_SUITE_data/partial.result similarity index 100% rename from ct/mustache_SUITE_data/partial.result rename to ct/bbmustache_SUITE_data/partial.result diff --git a/ct/mustache_SUITE_data/user.mustache b/ct/bbmustache_SUITE_data/user.mustache similarity index 100% rename from ct/mustache_SUITE_data/user.mustache rename to ct/bbmustache_SUITE_data/user.mustache diff --git a/ct/mustache_SUITE_data/variables.mustache b/ct/bbmustache_SUITE_data/variables.mustache similarity index 100% rename from ct/mustache_SUITE_data/variables.mustache rename to ct/bbmustache_SUITE_data/variables.mustache diff --git a/ct/mustache_SUITE_data/variables.result b/ct/bbmustache_SUITE_data/variables.result similarity index 100% rename from ct/mustache_SUITE_data/variables.result rename to ct/bbmustache_SUITE_data/variables.result diff --git a/ct/mustache_eunit_SUITE.erl b/ct/bbmustache_eunit_SUITE.erl similarity index 90% rename from ct/mustache_eunit_SUITE.erl rename to ct/bbmustache_eunit_SUITE.erl index 62eece2..1941103 100644 --- a/ct/mustache_eunit_SUITE.erl +++ b/ct/bbmustache_eunit_SUITE.erl @@ -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"). @@ -20,4 +20,4 @@ all() -> %%---------------------------------------------------------------------------------------------------------------------- eunit_ct(_Config) -> - ok = eunit:test({application, mustache}). + ok = eunit:test({application, bbmustache}). diff --git a/doc/README.md b/doc/README.md index 4589465..a3c0a6c 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,11 +1,11 @@ -# The mustache application # +# The bbmustache application # ## Modules ## -
mustache
+bbmustache diff --git a/doc/mustache.md b/doc/bbmustache.md similarity index 91% rename from doc/mustache.md rename to doc/bbmustache.md index 01e9bca..7cae16f 100644 --- a/doc/mustache.md +++ b/doc/bbmustache.md @@ -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. @@ -104,7 +104,7 @@ Equivalent to [`compile(Template, Data, [])`](#compile-3).

-compile(Mustache::template(), Data::data(), Options::[option()]) -> binary()
+compile(Bbmustache::template(), Data::data(), Options::[option()]) -> binary()
 

@@ -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">> ``` diff --git a/src/mustache.app.src b/src/bbmustache.app.src similarity index 61% rename from src/mustache.app.src rename to src/bbmustache.app.src index ce8156c..8ae8a5b 100644 --- a/src/mustache.app.src +++ b/src/bbmustache.app.src @@ -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, [ diff --git a/src/mustache.erl b/src/bbmustache.erl similarity index 98% rename from src/mustache.erl rename to src/bbmustache.erl index 358e9ff..7890dda 100644 --- a/src/mustache.erl +++ b/src/bbmustache.erl @@ -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 @@ -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).
diff --git a/test/mustache_tests.erl b/test/bbmustache_tests.erl similarity index 89% rename from test/mustache_tests.erl rename to test/bbmustache_tests.erl index 943872f..baa8b59 100644 --- a/test/mustache_tests.erl +++ b/test/bbmustache_tests.erl @@ -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"). %%---------------------------------------------------------------------------------------------------------------------- @@ -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 }}">>)}, @@ -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} ]. @@ -104,7 +104,7 @@ atom_and_binary_key_test_() -> fun() -> F = fun(Text, Render) -> ["", Render(Text), ""] end, ?assertEqual(<<"Willy is awesome.">>, - 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}, @@ -112,12 +112,12 @@ atom_and_binary_key_test_() -> fun() -> F = fun(Text, Render) -> ["", Render(Text), ""] end, ?assertEqual(<<"Willy is awesome.">>, - 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()))} ].