|
@ -59,7 +59,7 @@ list_templates(State) -> |
|
|
|
|
|
|
|
|
%% Expand a single template's value |
|
|
%% Expand a single template's value |
|
|
list_template(Files, {Name, Type, File}, State) -> |
|
|
list_template(Files, {Name, Type, File}, State) -> |
|
|
case consult(load_file(Files, Type, File)) of |
|
|
|
|
|
|
|
|
case rebar_string:consult(binary_to_list(load_file(Files, Type, File))) of |
|
|
{error, Reason} -> |
|
|
{error, Reason} -> |
|
|
{error, {consult, File, Reason}}; |
|
|
{error, {consult, File, Reason}}; |
|
|
TemplateTerms -> |
|
|
TemplateTerms -> |
|
@ -158,7 +158,7 @@ drop_var_docs([{K,V}|Rest]) -> [{K,V} | drop_var_docs(Rest)]. |
|
|
%% Load the template index, resolve all variables, and then execute |
|
|
%% Load the template index, resolve all variables, and then execute |
|
|
%% the template. |
|
|
%% the template. |
|
|
create({Template, Type, File}, Files, UserVars, Force, State) -> |
|
|
create({Template, Type, File}, Files, UserVars, Force, State) -> |
|
|
TemplateTerms = consult(load_file(Files, Type, File)), |
|
|
|
|
|
|
|
|
TemplateTerms = rebar_string:consult(binary_to_list(load_file(Files, Type, File))), |
|
|
Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))), |
|
|
Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))), |
|
|
maybe_warn_about_name(Vars), |
|
|
maybe_warn_about_name(Vars), |
|
|
TemplateCwd = filename:dirname(File), |
|
|
TemplateCwd = filename:dirname(File), |
|
@ -394,31 +394,6 @@ load_file(_Files, file, Name) -> |
|
|
{ok, Bin} = file:read_file(Name), |
|
|
{ok, Bin} = file:read_file(Name), |
|
|
Bin. |
|
|
Bin. |
|
|
|
|
|
|
|
|
%% Given a string or binary, parse it into a list of terms, ala file:consult/1 |
|
|
|
|
|
consult(Str) when is_list(Str) -> |
|
|
|
|
|
consult([], Str, []); |
|
|
|
|
|
consult(Bin) when is_binary(Bin)-> |
|
|
|
|
|
consult([], binary_to_list(Bin), []). |
|
|
|
|
|
|
|
|
|
|
|
consult(Cont, Str, Acc) -> |
|
|
|
|
|
case erl_scan:tokens(Cont, Str, 0) of |
|
|
|
|
|
{done, Result, Remaining} -> |
|
|
|
|
|
case Result of |
|
|
|
|
|
{ok, Tokens, _} -> |
|
|
|
|
|
case erl_parse:parse_term(Tokens) of |
|
|
|
|
|
{ok, Term} -> consult([], Remaining, [Term | Acc]); |
|
|
|
|
|
{error, Reason} -> {error, Reason} |
|
|
|
|
|
end; |
|
|
|
|
|
{eof, _Other} -> |
|
|
|
|
|
lists:reverse(Acc); |
|
|
|
|
|
{error, Info, _} -> |
|
|
|
|
|
{error, Info} |
|
|
|
|
|
end; |
|
|
|
|
|
{more, Cont1} -> |
|
|
|
|
|
consult(Cont1, eof, Acc) |
|
|
|
|
|
end. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
write_file(Output, Data, Force) -> |
|
|
write_file(Output, Data, Force) -> |
|
|
%% determine if the target file already exists |
|
|
%% determine if the target file already exists |
|
|
FileExists = filelib:is_regular(Output), |
|
|
FileExists = filelib:is_regular(Output), |
|
|