summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-04-24 19:40:35 -0400
committerFred Hebert <mononcqc@ferd.ca>2015-04-24 19:40:35 -0400
commitb0fc3aeb2ef7893cc45087f29658e8e25a31ae60 (patch)
tree3fdca852c8d0a5a11444b85800e39f33b53c9e8b /src
parent557de99d6c9893504d32dbd870f2ca12651c44d6 (diff)
parentf491e70cb83b9966d8a42e4ac47a1d3276515240 (diff)
Merge pull request #369 from tsloughter/noescript
support templates even when not run as escript
Diffstat (limited to 'src')
-rw-r--r--src/rebar_templater.erl32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index 78d1e83..746e440 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -266,17 +266,29 @@ replace_var([H|T], Acc, Vars) ->
%% Load a list of all the files in the escript and on disk
find_templates(State) ->
- %% Cache the files since we'll potentially need to walk it several times
- %% over the course of a run.
- Files = cache_escript_files(State),
+ DiskTemplates = find_disk_templates(State),
+ {MainTemplates, Files} =
+ case rebar_state:escript_path(State) of
+ undefined ->
+ {find_priv_templates(State), []};
+ _ ->
+ %% Cache the files since we'll potentially need to walk it several times
+ %% over the course of a run.
+ F = cache_escript_files(State),
+ {find_escript_templates(F), F}
+ end,
+ AvailTemplates = find_available_templates(DiskTemplates,
+ MainTemplates),
+ ?DEBUG("Available templates: ~p\n", [AvailTemplates]),
+ {AvailTemplates, Files}.
- %% Build a list of available templates
+find_available_templates(TemplateList1, TemplateList2) ->
AvailTemplates = prioritize_templates(
- tag_names(find_disk_templates(State)),
- tag_names(find_escript_templates(Files))),
+ tag_names(TemplateList1),
+ tag_names(TemplateList2)),
?DEBUG("Available templates: ~p\n", [AvailTemplates]),
- {AvailTemplates, Files}.
+ AvailTemplates.
%% Scan the current escript for available files
cache_escript_files(State) ->
@@ -293,6 +305,12 @@ find_escript_templates(Files) ->
|| {Name, _Bin} <- Files,
re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match].
+find_priv_templates(State) ->
+ OtherTemplates = rebar_utils:find_files(code:priv_dir(rebar), ?TEMPLATE_RE),
+ HomeFiles = rebar_utils:find_files(rebar_dir:template_dir(State),
+ ?TEMPLATE_RE, true), % recursive
+ [{file, F} || F <- OtherTemplates ++ HomeFiles].
+
%% Fetch template indexes that sit on disk in the user's HOME
find_disk_templates(State) ->
OtherTemplates = find_other_templates(State),