diff options
Diffstat (limited to 'src/rebar_templater.erl')
-rw-r--r-- | src/rebar_templater.erl | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index e997975..43bb8da 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -27,6 +27,7 @@ -module(rebar_templater). -export(['create-app'/2, + 'create-lib'/2, 'create-node'/2, 'list-templates'/2, create/2]). @@ -50,6 +51,10 @@ %% Alias for create w/ template=simpleapp create1(Config, "simpleapp"). +'create-lib'(Config, _File) -> + %% Alias for create w/ template=simplelib + create1(Config, "simplelib"). + 'create-node'(Config, _File) -> %% Alias for create w/ template=simplenode create1(Config, "simplenode"). @@ -98,7 +103,7 @@ render(Bin, Context) -> ReOpts = [global, {return, list}], Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts), Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts), - mustache:render(Str1, Context). + rebar_mustache:render(Str1, Context). %% =================================================================== %% Internal functions @@ -116,6 +121,12 @@ info(help, 'create-app') -> "~n" "Valid command line options:~n" " [appid=myapp]~n", []); +info(help, 'create-lib') -> + ?CONSOLE( + "Create simple lib skel.~n" + "~n" + "Valid command line options:~n" + " [libid=mylib]~n", []); info(help, 'create-node') -> ?CONSOLE( "Create simple node skel.~n" @@ -347,6 +358,10 @@ write_file(Output, Data, Force) -> {error, exists} end. +prepend_instructions(Instructions, Rest) when is_list(Instructions) -> + Instructions ++ Rest; +prepend_instructions(Instruction, Rest) -> + [Instruction|Rest]. %% %% Execute each instruction in a template definition file. @@ -364,6 +379,23 @@ execute_template(_Files, [], _TemplateType, _TemplateName, ?ERROR("One or more files already exist on disk and " "were not generated:~n~s~s", [Msg , Help]) end; +execute_template(Files, [{'if', Cond, True} | Rest], TemplateType, + TemplateName, Context, Force, ExistingFiles) -> + execute_template(Files, [{'if', Cond, True, []}|Rest], TemplateType, + TemplateName, Context, Force, ExistingFiles); +execute_template(Files, [{'if', Cond, True, False} | Rest], TemplateType, + TemplateName, Context, Force, ExistingFiles) -> + Instructions = case dict:find(Cond, Context) of + {ok, true} -> + True; + {ok, "true"} -> + True; + _ -> + False + end, + execute_template(Files, prepend_instructions(Instructions, Rest), + TemplateType, TemplateName, Context, Force, + ExistingFiles); execute_template(Files, [{template, Input, Output} | Rest], TemplateType, TemplateName, Context, Force, ExistingFiles) -> InputName = filename:join(filename:dirname(TemplateName), Input), |