aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric <[email protected]>2012-12-27 10:18:05 -0500
committerEric <[email protected]>2012-12-27 10:18:05 -0500
commitb87e030af2e3120ea4a6950c9808285897ce7be9 (patch)
tree063f0f89e32028aa542b53156aeb35e1c007bdcc /src
parente390e61cf7d678eac21b5eae6b64ee82304efa9a (diff)
downloadrelx-b87e030af2e3120ea4a6950c9808285897ce7be9.tar.gz
relx-b87e030af2e3120ea4a6950c9808285897ce7be9.tar.bz2
relx-b87e030af2e3120ea4a6950c9808285897ce7be9.zip
splint out render and write so we can reuse the render
Diffstat (limited to 'src')
-rw-r--r--src/rcl_prv_overlay.erl45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/rcl_prv_overlay.erl b/src/rcl_prv_overlay.erl
index 243df99..7e8b369 100644
--- a/src/rcl_prv_overlay.erl
+++ b/src/rcl_prv_overlay.erl
@@ -247,38 +247,47 @@ do_individual_overlay(State, OverlayVars, {template, From, To}) ->
fun(FromFile) ->
file_render_do(State, OverlayVars, To, ToTemplateName,
fun(ToFile) ->
- render_template(OverlayVars,
- erlang:binary_to_list(FromFile),
- ToFile)
+ write_template(OverlayVars,
+ erlang:binary_to_list(FromFile),
+ ToFile)
end)
end).
--spec render_template(proplists:proplist(), iolist(), file:name()) ->
+-spec render_template(proplists:proplist(), iolist()) ->
ok | relcool:error().
-render_template(OverlayVars, FromFile, ToFile) ->
- TemplateName = make_template_name("rcl_template_renderer", FromFile),
- case erlydtl:compile(FromFile, TemplateName) of
+render_template(OverlayVars, Data) ->
+ TemplateName = make_template_name("rcl_template_renderer", Data),
+ case erlydtl:compile(Data, TemplateName) of
Good when Good =:= ok; ok =:= {ok, TemplateName} ->
case render(TemplateName, OverlayVars) of
{ok, IoData} ->
- case filelib:ensure_dir(ToFile) of
+ {ok, IoData};
+ {error, Reason} ->
+ ?RCL_ERROR({unable_to_render_template, Data, Reason})
+ end;
+ {error, Reason} ->
+ ?RCL_ERROR({unable_to_compile_template, Data, Reason})
+ end.
+
+write_template(OverlayVars, FromFile, ToFile) ->
+ case render_template(OverlayVars, FromFile) of
+ {ok, IoData} ->
+ case filelib:ensure_dir(ToFile) of
+ ok ->
+ case file:write_file(ToFile, IoData) of
ok ->
- case file:write_file(ToFile, IoData) of
- ok ->
- ok;
- {error, Reason} ->
- ?RCL_ERROR({unable_to_write, ToFile, Reason})
- end;
+ ok;
{error, Reason} ->
- ?RCL_ERROR({unable_to_enclosing_dir, ToFile, Reason})
+ ?RCL_ERROR({unable_to_write, ToFile, Reason})
end;
{error, Reason} ->
- ?RCL_ERROR({unable_to_render_template, FromFile, Reason})
+ ?RCL_ERROR({unable_to_enclosing_dir, ToFile, Reason})
end;
- {error, Reason} ->
- ?RCL_ERROR({unable_to_compile_template, FromFile, Reason})
+ Error ->
+ Error
end.
+
-spec file_render_do(rcl_state:t(), proplists:proplist(), iolist(), module(),
fun((term()) -> {ok, rcl_state:t()} | relcool:error())) ->
{ok, rcl_state:t()} | relcool:error().