mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Update mustache.erl
This commit is contained in:
parent
2e654513dd
commit
61c564bf72
1 changed files with 19 additions and 7 deletions
|
@ -1,17 +1,17 @@
|
||||||
%% The MIT License
|
%% The MIT License
|
||||||
%%
|
%%
|
||||||
%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
|
%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
|
||||||
%%
|
%%
|
||||||
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% of this software and associated documentation files (the "Software"), to deal
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
%% in the Software without restriction, including without limitation the rights
|
%% in the Software without restriction, including without limitation the rights
|
||||||
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
%% copies of the Software, and to permit persons to whom the Software is
|
%% copies of the Software, and to permit persons to whom the Software is
|
||||||
%% furnished to do so, subject to the following conditions:
|
%% furnished to do so, subject to the following conditions:
|
||||||
%%
|
%%
|
||||||
%% The above copyright notice and this permission notice shall be included in
|
%% The above copyright notice and this permission notice shall be included in
|
||||||
%% all copies or substantial portions of the Software.
|
%% all copies or substantial portions of the Software.
|
||||||
%%
|
%%
|
||||||
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
@ -31,6 +31,10 @@
|
||||||
section_re = undefined,
|
section_re = undefined,
|
||||||
tag_re = undefined}).
|
tag_re = undefined}).
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
-endif.
|
||||||
|
|
||||||
compile(Body) when is_list(Body) ->
|
compile(Body) when is_list(Body) ->
|
||||||
State = #mstate{},
|
State = #mstate{},
|
||||||
CompiledTemplate = pre_compile(Body, State),
|
CompiledTemplate = pre_compile(Body, State),
|
||||||
|
@ -129,8 +133,8 @@ compile_tags(T, State) ->
|
||||||
Content = string:substr(T, C0 + 1, C1),
|
Content = string:substr(T, C0 + 1, C1),
|
||||||
Kind = tag_kind(T, K),
|
Kind = tag_kind(T, K),
|
||||||
Result = compile_tag(Kind, Content, State),
|
Result = compile_tag(Kind, Content, State),
|
||||||
"[\"" ++ Front ++
|
"[\"" ++ Front ++
|
||||||
"\" | [" ++ Result ++
|
"\" | [" ++ Result ++
|
||||||
" | " ++ compile_tags(Back, State) ++ "]]";
|
" | " ++ compile_tags(Back, State) ++ "]]";
|
||||||
nomatch ->
|
nomatch ->
|
||||||
"[\"" ++ T ++ "\"]"
|
"[\"" ++ T ++ "\"]"
|
||||||
|
@ -214,4 +218,12 @@ escape([X | Rest], Acc) ->
|
||||||
start([T]) ->
|
start([T]) ->
|
||||||
Out = render(list_to_atom(T)),
|
Out = render(list_to_atom(T)),
|
||||||
io:format(Out ++ "~n", []).
|
io:format(Out ++ "~n", []).
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
|
||||||
|
simple_test() ->
|
||||||
|
Ctx = dict:from_list([{name, "world"}]),
|
||||||
|
Result = render("Hello {{name}}!", Ctx),
|
||||||
|
?assertEqual("Hello world!", Result).
|
||||||
|
|
||||||
|
-endif.
|
||||||
|
|
Loading…
Reference in a new issue