diff options
author | Dave Smith <dizzyd@dizzyd.com> | 2013-09-20 07:02:51 -0700 |
---|---|---|
committer | Dave Smith <dizzyd@dizzyd.com> | 2013-09-20 07:02:51 -0700 |
commit | d5ca068983740a60b63308df5bc5997764ecd500 (patch) | |
tree | eb25cab0d1e3a7073e3964e224bd84a53371ffee /src | |
parent | 209c013dff99482dbce51a50833e99f9ba4d59b2 (diff) | |
parent | 2970fab4b743db658b395d7c0f3635df2592fd4f (diff) |
Merge pull request #138 from evax/conditionalTemplateInstructions
Support conditional template instructions
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_templater.erl | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index e997975..b8f7087 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -347,6 +347,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 +368,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), |