Created
December 23, 2009 07:35
-
-
Save mojombo/262380 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Another mustache.erl example, this time showing off lists and asking for context in one of the view functions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(complex). | |
-compile(export_all). | |
header() -> | |
"Colors". | |
item() -> | |
A = dict:from_list([{name, "red"}, {current, true}, {url, "#Red"}]), | |
B = dict:from_list([{name, "green"}, {current, false}, {url, "#Green"}]), | |
C = dict:from_list([{name, "blue"}, {current, false}, {url, "#Blue"}]), | |
[A, B, C]. | |
link(Ctx) -> | |
{ok, Val} = dict:find(current, Ctx), Val. | |
list() -> | |
length(item()) =/= 0. | |
empty() -> | |
length(item()) =:= 0. | |
%%--------------------------------------------------------------------------- | |
start() -> | |
code:add_patha(".."), | |
Output = mustache:render(complex, "complex.mustache"), | |
io:format(Output, []). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>{{header}}</h1> | |
{{#list}} | |
<ul> | |
{{#item}} | |
{{#current}} | |
<li><strong>{{name}}</strong></li> | |
{{/current}} | |
{{#link}} | |
<li><a href="{{url}}">{{name}}</a></li> | |
{{/link}} | |
{{/item}} | |
</ul> | |
{{/list}} | |
{{#empty}} | |
<p>The list is empty.</p> | |
{{/empty}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Colors</h1> | |
<ul> | |
<li><strong>red</strong></li> | |
<li><a href="#Red">red</a></li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment