diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-04-23 23:30:19 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-04-24 16:30:24 -0500 |
commit | f491e70cb83b9966d8a42e4ac47a1d3276515240 (patch) | |
tree | e35a30c0d271ccbefe06148ae9cb91de6a9e3c6c /src | |
parent | ee0f4dcd60c5e9eaef4de61ba93af73e57f9d88a (diff) |
support templates even when not run as escript
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_templater.erl | 32 |
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), |