2011-01-31 16:43:31 +00:00
|
|
|
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
2009-12-31 18:42:53 +00:00
|
|
|
%% ex: ts=4 sw=4 et
|
2009-12-22 14:57:42 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% rebar: Erlang Build Tools
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com),
|
|
|
|
%% Bryan Fink (bryan@basho.com)
|
|
|
|
%%
|
|
|
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
%% of this software and associated documentation files (the "Software"), to deal
|
|
|
|
%% in the Software without restriction, including without limitation the rights
|
|
|
|
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
%% copies of the Software, and to permit persons to whom the Software is
|
|
|
|
%% furnished to do so, subject to the following conditions:
|
|
|
|
%%
|
|
|
|
%% The above copyright notice and this permission notice shall be included in
|
|
|
|
%% all copies or substantial portions of the Software.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
%% THE SOFTWARE.
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
%% The rebar_erlydtl_compiler module is a plugin for rebar that compiles
|
|
|
|
%% ErlyDTL templates. By default, it compiles all templates/*.dtl
|
|
|
|
%% to ebin/*_dtl.beam.
|
|
|
|
%%
|
|
|
|
%% Configuration options should be placed in rebar.config under
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
%% 'erlydtl_opts'. It can be a list of name-value tuples or a list of
|
|
|
|
%% lists of name-value tuples if you have multiple template directories
|
|
|
|
%% that need to have different settings (see example below).
|
|
|
|
%%
|
|
|
|
%% Available options include:
|
2009-12-22 14:57:42 +00:00
|
|
|
%%
|
|
|
|
%% doc_root: where to find templates to compile
|
|
|
|
%% "templates" by default
|
|
|
|
%%
|
|
|
|
%% out_dir: where to put compiled template beam files
|
|
|
|
%% "ebin" by default
|
|
|
|
%%
|
|
|
|
%% source_ext: the file extension the template sources have
|
|
|
|
%% ".dtl" by default
|
|
|
|
%%
|
|
|
|
%% module_ext: characters to append to the template's module name
|
|
|
|
%% "_dtl" by default
|
|
|
|
%%
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
%% recursive: boolean that determines if doc_root(s) need to be
|
|
|
|
%% scanned recursively for matching template file names
|
|
|
|
%% (default: true).
|
2009-12-22 14:57:42 +00:00
|
|
|
%% For example, if you had:
|
|
|
|
%% /t_src/
|
|
|
|
%% base.html
|
|
|
|
%% foo.html
|
|
|
|
%%
|
|
|
|
%% And you wanted them compiled to:
|
|
|
|
%% /priv/
|
|
|
|
%% base.beam
|
|
|
|
%% foo.beam
|
|
|
|
%%
|
|
|
|
%% You would add to your rebar.config:
|
|
|
|
%% {erlydtl_opts, [
|
|
|
|
%% {doc_root, "t_src"},
|
|
|
|
%% {out_dir, "priv"},
|
|
|
|
%% {source_ext, ".html"},
|
|
|
|
%% {module_ext, ""}
|
|
|
|
%% ]}.
|
|
|
|
%%
|
|
|
|
%% The default settings are the equivalent of:
|
|
|
|
%% {erlydtl_opts, [
|
|
|
|
%% {doc_root, "templates"},
|
|
|
|
%% {out_dir, "ebin"},
|
|
|
|
%% {source_ext, ".dtl"},
|
|
|
|
%% {module_ext, "_dtl"}
|
|
|
|
%% ]}.
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
%%
|
|
|
|
%% The following example will compile the following templates:
|
|
|
|
%% "src/*.dtl" files into "ebin/*_dtl.beam" and
|
|
|
|
%% "templates/*.html" into "ebin/*.beam". Note that any tuple option
|
|
|
|
%% (such as 'out_dir') in the outer list is added to each inner list:
|
|
|
|
%% {erlydtl_opts, [
|
|
|
|
%% {out_dir, "ebin"},
|
|
|
|
%% {recursive, false},
|
|
|
|
%% [
|
|
|
|
%% {doc_root, "src"}, {module_ext, "_dtl"}
|
|
|
|
%% ],
|
|
|
|
%% [
|
|
|
|
%% {doc_root, "templates", {module_ext, ""}, {source_ext, ".html"}
|
|
|
|
%% ]
|
|
|
|
%% ]}.
|
2009-12-22 14:57:42 +00:00
|
|
|
-module(rebar_erlydtl_compiler).
|
|
|
|
|
|
|
|
-export([compile/2]).
|
|
|
|
|
|
|
|
-include("rebar.hrl").
|
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Public API
|
|
|
|
%% ===================================================================
|
|
|
|
|
|
|
|
compile(Config, _AppFile) ->
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
MultiDtlOpts = erlydtl_opts(Config),
|
2012-02-02 23:17:18 +00:00
|
|
|
OrigPath = code:get_path(),
|
2012-08-06 17:00:18 +00:00
|
|
|
true = code:add_path(rebar_utils:ebin_dir()),
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
|
|
|
|
Result = lists:foldl(fun(DtlOpts, _) ->
|
|
|
|
rebar_base_compiler:run(Config, [],
|
2012-02-02 23:17:18 +00:00
|
|
|
option(doc_root, DtlOpts),
|
|
|
|
option(source_ext, DtlOpts),
|
|
|
|
option(out_dir, DtlOpts),
|
|
|
|
option(module_ext, DtlOpts) ++ ".beam",
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
fun(S, T, _C) ->
|
|
|
|
compile_dtl(S, T, DtlOpts)
|
|
|
|
end,
|
|
|
|
[{check_last_mod, false},
|
|
|
|
{recursive, option(recursive, DtlOpts)}])
|
|
|
|
end, ok, MultiDtlOpts),
|
|
|
|
|
2012-02-02 23:17:18 +00:00
|
|
|
true = code:set_path(OrigPath),
|
|
|
|
Result.
|
2009-12-22 14:57:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%% ===================================================================
|
|
|
|
|
|
|
|
erlydtl_opts(Config) ->
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
Opts = rebar_config:get(Config, erlydtl_opts, []),
|
|
|
|
Tuples = [{K,V} || {K,V} <- Opts],
|
|
|
|
case [L || L <- Opts, is_list(L), not io_lib:printable_list(L)] of
|
|
|
|
[] ->
|
|
|
|
lists:keysort(1, [Tuples]);
|
|
|
|
Lists ->
|
|
|
|
lists:map(fun(L) ->
|
|
|
|
lists:keysort(1, lists:foldl(fun({K,T}, Acc) ->
|
|
|
|
lists:keystore(K, 1, Acc, {K, T})
|
|
|
|
end, Tuples, L))
|
|
|
|
end, Lists)
|
|
|
|
end.
|
2009-12-22 14:57:42 +00:00
|
|
|
|
|
|
|
option(Opt, DtlOpts) ->
|
|
|
|
proplists:get_value(Opt, DtlOpts, default(Opt)).
|
|
|
|
|
|
|
|
default(doc_root) -> "templates";
|
|
|
|
default(out_dir) -> "ebin";
|
|
|
|
default(source_ext) -> ".dtl";
|
2010-01-16 19:58:34 +00:00
|
|
|
default(module_ext) -> "_dtl";
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
default(custom_tags_dir) -> "";
|
|
|
|
default(compiler_options) -> [report, return];
|
|
|
|
default(recursive) -> true.
|
2009-12-22 14:57:42 +00:00
|
|
|
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
compile_dtl(Source, Target, DtlOpts) ->
|
2010-01-04 16:24:28 +00:00
|
|
|
case code:which(erlydtl) of
|
|
|
|
non_existing ->
|
2012-03-18 17:51:08 +00:00
|
|
|
?ERROR("~n===============================================~n"
|
|
|
|
" You need to install erlydtl to compile DTL templates~n"
|
|
|
|
" Download the latest tarball release from github~n"
|
|
|
|
" http://code.google.com/p/erlydtl/~n"
|
|
|
|
" and install it into your erlang library dir~n"
|
|
|
|
"===============================================~n~n", []),
|
2012-07-28 17:51:57 +00:00
|
|
|
?FAIL;
|
2010-01-04 16:24:28 +00:00
|
|
|
_ ->
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
case needs_compile(Source, Target, DtlOpts) of
|
2010-01-04 16:24:28 +00:00
|
|
|
true ->
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
do_compile(Source, Target, DtlOpts);
|
2010-01-04 16:24:28 +00:00
|
|
|
false ->
|
|
|
|
skipped
|
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
do_compile(Source, Target, DtlOpts) ->
|
2010-01-04 16:24:28 +00:00
|
|
|
%% TODO: Check last mod on target and referenced DTLs here..
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
|
2010-01-04 16:24:28 +00:00
|
|
|
%% ensure that doc_root and out_dir are defined,
|
|
|
|
%% using defaults if necessary
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
Opts = lists:ukeymerge(1,
|
|
|
|
DtlOpts,
|
|
|
|
lists:sort(
|
|
|
|
[{out_dir, option(out_dir, DtlOpts)},
|
|
|
|
{doc_root, option(doc_root, DtlOpts)},
|
|
|
|
{custom_tags_dir, option(custom_tags_dir, DtlOpts)},
|
|
|
|
{compiler_options, option(compiler_options, DtlOpts)}])),
|
|
|
|
?INFO("Compiling \"~s\" -> \"~s\" with options:~n ~s~n",
|
|
|
|
[Source, Target, io_lib:format("~p", [Opts])]),
|
2010-01-04 16:24:28 +00:00
|
|
|
case erlydtl:compile(Source,
|
|
|
|
module_name(Target),
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
Opts) of
|
2010-01-04 16:24:28 +00:00
|
|
|
ok -> ok;
|
|
|
|
Reason ->
|
2012-01-17 10:53:59 +00:00
|
|
|
?ERROR("Compiling template ~s failed:~n ~p~n",
|
|
|
|
[Source, Reason]),
|
2012-07-28 17:51:57 +00:00
|
|
|
?FAIL
|
2010-01-04 16:24:28 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
module_name(Target) ->
|
|
|
|
F = filename:basename(Target),
|
|
|
|
string:substr(F, 1, length(F)-length(".beam")).
|
|
|
|
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
needs_compile(Source, Target, DtlOpts) ->
|
2010-01-04 16:24:28 +00:00
|
|
|
LM = filelib:last_modified(Target),
|
2010-10-25 22:38:51 +00:00
|
|
|
LM < filelib:last_modified(Source) orelse
|
|
|
|
lists:any(fun(D) -> LM < filelib:last_modified(D) end,
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
referenced_dtls(Source, DtlOpts)).
|
2010-01-04 16:24:28 +00:00
|
|
|
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
referenced_dtls(Source, DtlOpts) ->
|
|
|
|
DtlOpts1 = lists:keyreplace(doc_root, 1, DtlOpts,
|
|
|
|
{doc_root, filename:dirname(Source)}),
|
|
|
|
Set = referenced_dtls1([Source], DtlOpts1,
|
2012-01-17 10:55:07 +00:00
|
|
|
sets:add_element(Source, sets:new())),
|
2010-10-25 22:38:51 +00:00
|
|
|
sets:to_list(sets:del_element(Source, Set)).
|
2009-12-22 14:57:42 +00:00
|
|
|
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
referenced_dtls1(Step, DtlOpts, Seen) ->
|
2010-01-04 16:24:28 +00:00
|
|
|
ExtMatch = re:replace(option(source_ext, DtlOpts), "\.", "\\\\\\\\.",
|
2009-12-22 14:57:42 +00:00
|
|
|
[{return, list}]),
|
2011-01-09 13:22:50 +00:00
|
|
|
|
|
|
|
ShOpts = [{use_stdout, false}, return_on_error],
|
2010-12-05 00:07:12 +00:00
|
|
|
AllRefs =
|
|
|
|
lists:append(
|
2011-01-08 18:09:24 +00:00
|
|
|
[begin
|
2011-01-09 13:22:50 +00:00
|
|
|
Cmd = lists:flatten(["grep -o [^\\\"]*",
|
|
|
|
ExtMatch, " ", F]),
|
|
|
|
case rebar_utils:sh(Cmd, ShOpts) of
|
|
|
|
{ok, Res} ->
|
|
|
|
string:tokens(Res, "\n");
|
|
|
|
{error, _} ->
|
|
|
|
""
|
|
|
|
end
|
2011-01-08 18:09:24 +00:00
|
|
|
end || F <- Step]),
|
2009-12-22 14:57:42 +00:00
|
|
|
DocRoot = option(doc_root, DtlOpts),
|
|
|
|
WithPaths = [ filename:join([DocRoot, F]) || F <- AllRefs ],
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
?DEBUG("All deps: ~p\n", [WithPaths]),
|
2011-01-07 15:32:36 +00:00
|
|
|
Existing = [F || F <- WithPaths, filelib:is_regular(F)],
|
2009-12-22 14:57:42 +00:00
|
|
|
New = sets:subtract(sets:from_list(Existing), Seen),
|
|
|
|
case sets:size(New) of
|
|
|
|
0 -> Seen;
|
Specify multiple locations of DTL template files
Added a backward compartible feature to specify `erlydtl_opts' options
for the DTL template compiler to allow inclusion of templates in different
directories with different compilation settings for each. E.g.:
{erlydtl_opts, [
[{doc_root, "src/view"}, {module_ext, "_dtl_vw"}]
, [{doc_root, "src"}, {module_ext, ""}, {recursive, false}]
, {out_dir, "ebin"}
, {compiler_options, [verbose, debug_info]}
]}.
The definition above is identical to this (the last two options
are duplicated in each list):
{erlydtl_opts, [
[{doc_root, "src/view"}
,{module_ext, "_dtl_vw"}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}]
, [{doc_root, "src"}
,{module_ext, ""}
,{out_dir, "ebin"}
,{compiler_options, [verbose, debug_info]}
,{recursive, false}]
]}.
In this case "src/view" and "src" directories containing template files
will be compiled. A new `recursive' option tells rebar_erlydtl_compiler
to search files recursively from a given doc_root. In the example above
the "src" directory won't be scanned recursively, and the target template
name for target beam modules won't have "_dtl_vw" suffix.
2012-10-21 02:13:35 +00:00
|
|
|
_ -> referenced_dtls1(sets:to_list(New), DtlOpts,
|
2010-01-04 16:24:28 +00:00
|
|
|
sets:union(New, Seen))
|
2009-12-22 14:57:42 +00:00
|
|
|
end.
|