Browse Source

Merge pull request #369 from tsloughter/noescript

support templates even when not run as escript
pull/371/head
Fred Hebert 10 years ago
parent
commit
b0fc3aeb2e
1 changed files with 25 additions and 7 deletions
  1. +25
    -7
      src/rebar_templater.erl

+ 25
- 7
src/rebar_templater.erl View File

@ -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),

Loading…
Cancel
Save