Skip to content

Commit

Permalink
Change the rule
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAlphaFox committed Oct 31, 2019
1 parent 87759ac commit 449371a
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 179 deletions.
21 changes: 8 additions & 13 deletions examples/complex.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

context()->
A = maps:from_list([{<<"name">>, "red"}, {<<"current">>, true}, {<<"url">>, "#Red"}]),
B = maps:from_list([{<<"name">>, "green"}, {<<"current">>, false}, {<<"url">>, "#Green"}]),
B = maps:from_list([{<<"name">>, "green"}, {<<"current">>, true}, {<<"url">>, "#Green"}]),
C = maps:from_list([{<<"name">>, "blue"}, {<<"current">>, false}, {<<"url">>, "#Blue"}]),
#{
<<"items">> => [A,B,C],
<<"header">> => <<"Colors">>,
<<"list">> => true,
<<"empty">> => false,
<<"user">> => #{ <<"name">> => <<"David Gao">>},
<<".shared">> => #{
<<"level">> => #{
<<"level">> => true,
<<"name">> => <<"VIP User">>
}
}
<<"items">> => [A,B,C],
<<"header">> => <<"Colors">>,
<<"list">> => true,
<<"empty">> => false,
<<"user">> => #{ <<"name">> => <<"David Gao">>},
<<"level">> => #{ <<"name">> => <<"VIP User">> }
}.


Expand All @@ -32,7 +27,7 @@ start() ->
application:start(aihtml),

{ok,CWD} = file:get_cwd(),
ai_mustache:prepare(CWD),
ai_mustache:bootstrap(CWD),

Output = ai_mustache:render("complex",context()),
io:format("~ts~n",[Output]),
Expand Down
4 changes: 2 additions & 2 deletions examples/complex.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{#list}}
<ul>
{{#items}}
{{> item}}
{{> shared/item}}
{{/items}}
</ul>
{{/list}}
Expand All @@ -20,4 +20,4 @@
|
{{#boolean}}
{{/boolean}}
|
|
3 changes: 0 additions & 3 deletions examples/shared/_level.mustache

This file was deleted.

File renamed without changes.
3 changes: 3 additions & 0 deletions examples/shared/level.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#level}}
{{level.name}}
{{/level}}
File renamed without changes.
9 changes: 4 additions & 5 deletions src/ai_mustache.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-module(ai_mustache).
-export([prepare/0,prepare/1,prepare/2]).
-export([bootstrap/0,bootstrap/1,bootstrap/2]).
-export([render/2]).

%% 定义如下规则
Expand All @@ -25,7 +25,6 @@ render(Template,Ctx)->
end,
ai_mustache_runner:render(Run,Ctx).

prepare()-> ai_mustache_loader:prepare().
prepare(ViewPath)-> ai_mustache_loader:prepare(ViewPath).
prepare(ViewPath,Suffix)-> ai_mustache_loader:prepare(ViewPath,Suffix).

bootstrap()-> ai_mustache_loader:bootstrap().
bootstrap(ViewPath)-> ai_mustache_loader:bootstrap(ViewPath).
bootstrap(ViewPath,Suffix)-> ai_mustache_loader:bootstrap(ViewPath,Suffix).
Loading

0 comments on commit 449371a

Please sign in to comment.