diff options
author | Tristan Sloughter <[email protected]> | 2014-12-13 14:48:41 -0600 |
---|---|---|
committer | Tristan Sloughter <[email protected]> | 2014-12-13 14:53:16 -0600 |
commit | c131510aa4804d7d6bf2ffb44fdd1e1e5ded9b5a (patch) | |
tree | 6b08fb84bc4e78e99eca3891308f7f284ae385ec /src/rlx_prv_overlay.erl | |
parent | abba53cc41747654b50a1eff355172d98d228f77 (diff) | |
download | relx-c131510aa4804d7d6bf2ffb44fdd1e1e5ded9b5a.tar.gz relx-c131510aa4804d7d6bf2ffb44fdd1e1e5ded9b5a.tar.bz2 relx-c131510aa4804d7d6bf2ffb44fdd1e1e5ded9b5a.zip |
render overlay filenames for tar archive
Diffstat (limited to 'src/rlx_prv_overlay.erl')
-rw-r--r-- | src/rlx_prv_overlay.erl | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/rlx_prv_overlay.erl b/src/rlx_prv_overlay.erl index f7e2be8..f14963e 100644 --- a/src/rlx_prv_overlay.erl +++ b/src/rlx_prv_overlay.erl @@ -28,6 +28,10 @@ do/1, format_error/1]). +-export([generate_overlay_vars/2, + make_template_name/2, + render_string/3]). + -define(DIRECTORY_RE, ".*(\/|\\\\)$"). -define(ERLYDTL_COMPILE_OPTS, [report_warnings, return_errors, {auto_escape, false}, {out_dir, false}]). @@ -61,7 +65,12 @@ do(State) -> Release = rlx_state:get_realized_release(State, RelName, RelVsn), case rlx_release:realized(Release) of true -> - generate_overlay_vars(State, Release); + case generate_overlay_vars(State, Release) of + {error, Reason} -> + {error, Reason}; + OverlayVars -> + do_overlay(State, OverlayVars) + end; false -> ?RLX_ERROR({unresolved_release, RelName, RelVsn}) end. @@ -126,20 +135,20 @@ format_errors(_, []) -> []. -spec generate_overlay_vars(rlx_state:t(), rlx_release:t()) -> - {ok, rlx_state:t()} | relx:error(). + proplists:proplist() | relx:error(). generate_overlay_vars(State, Release) -> StateVars = generate_state_vars(State), ReleaseVars = generate_release_vars(Release), get_overlay_vars_from_file(State, StateVars ++ ReleaseVars). -spec get_overlay_vars_from_file(rlx_state:t(), proplists:proplist()) -> - {ok, rlx_state:t()} | relx:error(). + proplists:proplist() | relx:error(). get_overlay_vars_from_file(State, OverlayVars) -> case rlx_state:get(State, overlay_vars, undefined) of undefined -> - do_overlay(State, OverlayVars); + OverlayVars; [] -> - do_overlay(State, OverlayVars); + OverlayVars; [H | _]=FileNames when is_list(H) -> read_overlay_vars(State, OverlayVars, FileNames); FileName when is_list(FileName) -> @@ -147,12 +156,12 @@ get_overlay_vars_from_file(State, OverlayVars) -> end. -spec read_overlay_vars(rlx_state:t(), proplists:proplist(), [file:name()]) -> - {ok, rlx_state:t()} | relx:error(). + proplists:proplist() | relx:error(). read_overlay_vars(State, OverlayVars, FileNames) -> Terms = merge_overlay_vars(State, FileNames), case render_overlay_vars(OverlayVars, Terms, []) of {ok, NewTerms} -> - do_overlay(State, OverlayVars ++ NewTerms); + OverlayVars ++ NewTerms; Error -> Error end. @@ -431,6 +440,19 @@ write_template(OverlayVars, FromFile, ToFile) -> Error end. +render_string(OverlayVars, Data, TemplateName) -> + case erlydtl:compile(erlang:iolist_to_binary(Data), TemplateName, ?ERLYDTL_COMPILE_OPTS) of + {ok, TemplateName} -> + case render(TemplateName, OverlayVars) of + {ok, IoList} -> + erlang:iolist_to_binary(IoList); + {error, Error} -> + ?RLX_ERROR({render_failed, Data, Error}) + end; + {error, Reason, _Warnings} -> + ?RLX_ERROR({unable_to_compile_template, Data, Reason}) + end. + -spec file_render_do(proplists:proplist(), iolist(), module(), fun((term()) -> {ok, rlx_state:t()} | relx:error())) -> {ok, rlx_state:t()} | relx:error(). |