Skip to content

Instantly share code, notes, and snippets.

@lefant
Created November 20, 2012 15:10
Show Gist options
  • Save lefant/4118489 to your computer and use it in GitHub Desktop.
Save lefant/4118489 to your computer and use it in GitHub Desktop.
-module(ls).
-compile(export_all).
start() ->
code:add_patha(".."),
Params = [{name_split, ["foo", "bar", "baz"]}],
Ctx = prepare_ctx(Params),
Output = mustache:render(ls, "ls.mustache", Ctx),
io:format(Output, []).
prepare_ctx(Params) ->
dict:from_list([prepare_param(Param) || Param <- Params]).
%% Param is string
prepare_param({_, [X | _]} = Param) when is_integer(X) ->
Param;
%% Param is list of strings
prepare_param({Name, [[X | _] | _] = Words}) when is_integer(X) ->
{Name, [dict:from_list([{word, Word}]) || Word <- Words]}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment