summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDave Smith <dizzyd@dizzyd.com>2011-03-29 21:38:14 -0600
committerDave Smith <dizzyd@dizzyd.com>2011-04-10 16:12:50 -0600
commitc4907b62976a3b2341ba1cf16d5276c40634f95c (patch)
tree63af5eb6d847a4f9796e4de7ab99d7de00dd0a01 /src
parent3e2baf1a07ba2512b4efc325ba2b107f69c05434 (diff)
Add support for loading template vars from external file
Diffstat (limited to 'src')
-rw-r--r--src/rebar_templater.erl22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index 487a578..9247cc6 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -104,17 +104,33 @@ create(_Config, _) ->
Context0 = dict:new()
end,
+ %% Load variables from disk file, if provided
+ Context1 = case rebar_config:get_global(template_vars, undefined) of
+ undefined ->
+ Context0;
+ File ->
+ case file:consult(File) of
+ {ok, Terms} ->
+ %% TODO: Cleanup/merge with similar code in rebar_reltool
+ M = fun(_Key, _Base, Override) -> Override end,
+ dict:merge(M, Context0, dict:from_list(Terms));
+ {error, Reason} ->
+ ?ABORT("Unable to load template_vars from ~s: ~p\n",
+ [File, Reason])
+ end
+ end,
+
%% For each variable, see if it's defined in global vars -- if it is,
%% prefer that value over the defaults
- Context1 = update_vars(dict:fetch_keys(Context0), Context0),
+ Context2 = update_vars(dict:fetch_keys(Context1), Context1),
?DEBUG("Template ~p context: ~p\n", [TemplateId, dict:to_list(Context1)]),
%% Handle variables that possibly include other variables in their
%% definition
- Context = resolve_recursive_vars(dict:to_list(Context1), Context1),
+ Context = resolve_recursive_vars(dict:to_list(Context2), Context2),
?DEBUG("Resolved Template ~p context: ~p\n",
- [TemplateId, dict:to_list(Context1)]),
+ [TemplateId, dict:to_list(Context)]),
%% Now, use our context to process the template definition -- this
%% permits us to use variables within the definition for filenames.