diff options
author | Loïc Hoguin <[email protected]> | 2015-08-26 17:10:29 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-08-26 17:11:39 +0200 |
commit | e88092a674ebf3572c7bc2ca86177c3e8c16a59c (patch) | |
tree | 85e2cee7a1a6d1a5200780918a05a9bd3761e9cf | |
parent | d86f65346df71bd5608315fc244ed49cbf7aa431 (diff) | |
download | erlang.mk-e88092a674ebf3572c7bc2ca86177c3e8c16a59c.tar.gz erlang.mk-e88092a674ebf3572c7bc2ca86177c3e8c16a59c.tar.bz2 erlang.mk-e88092a674ebf3572c7bc2ca86177c3e8c16a59c.zip |
Improve the erlydtl plugin
Among the improvements:
* Work with current versions of ErlyDTL
* Add DTL_PATH, defaulting to templates/
* Add DTL_SUFFIX, defaulting to _dtl (suffix of output module names)
* Simplify the Erlang code and port to the erlang function
The erlang function can now accept any command-line argument for
erl as optional second argument.
-rw-r--r-- | core/core.mk | 2 | ||||
-rw-r--r-- | plugins/erlydtl.mk | 34 |
2 files changed, 22 insertions, 14 deletions
diff --git a/core/core.mk b/core/core.mk index d0e8ed1..d0c701a 100644 --- a/core/core.mk +++ b/core/core.mk @@ -136,7 +136,7 @@ endef # Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy. define erlang -$(ERL) -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk +$(ERL) $(2) -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk endef ifeq ($(shell which wget 2>/dev/null | wc -l), 1) diff --git a/plugins/erlydtl.mk b/plugins/erlydtl.mk index 46a3080..1f33bc6 100644 --- a/plugins/erlydtl.mk +++ b/plugins/erlydtl.mk @@ -4,6 +4,8 @@ # Configuration. DTL_FULL_PATH ?= 0 +DTL_PATH ?= templates/ +DTL_SUFFIX ?= _dtl # Verbosity. @@ -12,20 +14,26 @@ dtl_verbose = $(dtl_verbose_$(V)) # Core targets. -define compile_erlydtl - $(dtl_verbose) $(ERL) -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \ - Compile = fun(F) -> \ - S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \ - (0) -> filename:basename(F, ".dtl") \ - end, \ - Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \ - {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \ - end, \ - _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \ - halt().' +define erlydtl_compile.erl + [begin + Module0 = case $(DTL_FULL_PATH) of + 0 -> + filename:basename(F, ".dtl"); + 1 -> + "$(DTL_PATH)" ++ F2 = filename:rootname(F, ".dtl"), + re:replace(F2, "/", "_", [{return, list}, global]) + end, + Module = list_to_atom(string:to_lower(Module0) ++ "$(DTL_SUFFIX)"), + case erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) of + ok -> ok; + {ok, _} -> ok + end + end || F <- string:tokens("$(1)", " ")], + halt(). endef ifneq ($(wildcard src/),) -ebin/$(PROJECT).app:: $(sort $(call core_find,templates/,*.dtl)) - $(if $(strip $?),$(call compile_erlydtl,$?)) +ebin/$(PROJECT).app:: $(sort $(call core_find,$(DTL_PATH),*.dtl)) + $(if $(strip $?),\ + $(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$?,-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/))) endif |