diff options
author | Eric <[email protected]> | 2012-12-30 19:34:34 -0500 |
---|---|---|
committer | Eric <[email protected]> | 2012-12-30 19:34:34 -0500 |
commit | 7313be05d2805a3cf699e25d160401fd95635e33 (patch) | |
tree | 6f1b5b59e21f906867bc48095aec98badadd62f3 | |
parent | 78ec90ae6084f44b5379bd4e9eebb79746f4a595 (diff) | |
download | relx-7313be05d2805a3cf699e25d160401fd95635e33.tar.gz relx-7313be05d2805a3cf699e25d160401fd95635e33.tar.bz2 relx-7313be05d2805a3cf699e25d160401fd95635e33.zip |
support config relative directories in templates and copy
-rw-r--r-- | src/rcl_prv_overlay.erl | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/rcl_prv_overlay.erl b/src/rcl_prv_overlay.erl index 866ace5..e792a4f 100644 --- a/src/rcl_prv_overlay.erl +++ b/src/rcl_prv_overlay.erl @@ -281,22 +281,27 @@ do_individual_overlay(State, OverlayVars, {template, From, To}) -> fun(FromFile) -> file_render_do(OverlayVars, To, ToTemplateName, fun(ToFile) -> + RelativeRoot = get_relative_root(State), FromFile0 = absolutize(State, - filename:join(rcl_state:output_dir(State), + filename:join(RelativeRoot, erlang:iolist_to_binary(FromFile))), FromFile1 = erlang:binary_to_list(FromFile0), write_template(OverlayVars, FromFile1, - absolutize(State, ToFile)) + absolutize(State, + filename:join(rcl_state:output_dir(State), + erlang:iolist_to_binary(ToFile)))) end) end). -spec copy_to(rcl_state:t(), file:name(), file:name()) -> ok | relcool:error(). copy_to(State, FromFile0, ToFile0) -> + RelativeRoot = get_relative_root(State), ToFile1 = absolutize(State, filename:join(rcl_state:output_dir(State), erlang:iolist_to_binary(ToFile0))), - FromFile1 = absolutize(State, FromFile0), + FromFile1 = absolutize(State, filename:join(RelativeRoot, + erlang:iolist_to_binary(FromFile0))), ToFile2 = case is_directory(ToFile0, ToFile1) of false -> filelib:ensure_dir(ToFile1), @@ -317,6 +322,14 @@ copy_to(State, FromFile0, ToFile0) -> ToFile1, Err}) end. +get_relative_root(State) -> + case rcl_state:config_file(State) of + [] -> + rcl_state:root_dir(State); + Config -> + filename:dirname(Config) + end. + -spec is_directory(file:name(), file:name()) -> boolean(). is_directory(ToFile0, ToFile1) -> case re:run(ToFile0, ?DIRECTORY_RE) of |