From 0e39dc4149e2876649560f43730a34cccda9493c Mon Sep 17 00:00:00 2001 From: Florent Gallaire Date: Thu, 5 Dec 2013 05:56:24 +0100 Subject: [PATCH 1/2] Support switch template instructions --- src/rebar_templater.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index b8f7087..bca817f 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -385,6 +385,17 @@ execute_template(Files, [{'if', Cond, True, False} | Rest], TemplateType, execute_template(Files, prepend_instructions(Instructions, Rest), TemplateType, TemplateName, Context, Force, ExistingFiles); +execute_template(Files, [{'case', Variable, Value, Instructions} | Rest], TemplateType, + TemplateName, Context, Force, ExistingFiles) -> + Instructions2 = case dict:find(Variable, Context) of + {ok, Value} -> + Instructions; + _ -> + [] + end, + execute_template(Files, prepend_instructions(Instructions2, 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), From 51584caa3e2fc6012a3ce4229751704067cae254 Mon Sep 17 00:00:00 2001 From: Florent Gallaire Date: Fri, 6 Dec 2013 06:51:29 +0100 Subject: [PATCH 2/2] A switch variable can have multiple values --- src/rebar_templater.erl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index bca817f..279c53d 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -385,10 +385,11 @@ execute_template(Files, [{'if', Cond, True, False} | Rest], TemplateType, execute_template(Files, prepend_instructions(Instructions, Rest), TemplateType, TemplateName, Context, Force, ExistingFiles); -execute_template(Files, [{'case', Variable, Value, Instructions} | Rest], TemplateType, +execute_template(Files, [{'case', Variable, Values, Instructions} | Rest], TemplateType, TemplateName, Context, Force, ExistingFiles) -> - Instructions2 = case dict:find(Variable, Context) of - {ok, Value} -> + {ok, Value} = dict:find(Variable, Context), + Instructions2 = case lists:member(Value, Values) of + true -> Instructions; _ -> []