From ba41fb80efcd2083d1cc98802a118d4db2c1eaf8 Mon Sep 17 00:00:00 2001 From: Evgeny M Date: Sun, 16 Nov 2014 22:53:52 +0300 Subject: Make it possible to create erlydtl beam files with full path in the name if DTL_FULL_PATH=1 /templates/a/b/c.dtl -> a_b_c_dtl.beam otherwise (as it was before) -> c_dtl.beam add return_errors flag to erlydtl:compile to return {error, Errors} instead of error; add {doc_root, "templates"} flag to allow extend and include templates from parent directories (by default erlydtl looks for parent template in the directory of the current template); make compilation stop if erlydtl:compile returns an error --- README.md | 9 ++++++++- erlang.mk | 12 +++++++++--- plugins/erlydtl.mk | 12 +++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bcb5042..f0b55f5 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,14 @@ ErlyDTL plugin This plugin is available by default. It adds automatic compilation of ErlyDTL templates found in `templates/*.dtl` -or any subdirectory. +or any subdirectory. + +By default it ignores names of subdirectories and compiles +`a/b/templatename.dtl` into `templatename_dtl.beam`. To include +subdirectories names in the compiled module name add +`DTL_FULL_PATH=1` into your Makefile - `a/b/templatename.dtl` +will be compiled into `a_b_templatename_dtl.beam`. + Relx plugin ----------- diff --git a/erlang.mk b/erlang.mk index 9d6caf9..d3e120c 100644 --- a/erlang.mk +++ b/erlang.mk @@ -738,6 +738,10 @@ distclean-elvis: # Copyright (c) 2013-2014, Loïc Hoguin # This file is part of erlang.mk and subject to the terms of the ISC License. +# Configuration. + +DTL_FULL_PATH ?= 0 + # Verbosity. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F)); @@ -748,9 +752,11 @@ dtl_verbose = $(dtl_verbose_$(V)) define compile_erlydtl $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \ Compile = fun(F) -> \ - Module = list_to_atom( \ - string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \ - erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \ + 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)", " ")], \ init:stop()' diff --git a/plugins/erlydtl.mk b/plugins/erlydtl.mk index e288072..8d8795f 100644 --- a/plugins/erlydtl.mk +++ b/plugins/erlydtl.mk @@ -1,6 +1,10 @@ # Copyright (c) 2013-2014, Loïc Hoguin # This file is part of erlang.mk and subject to the terms of the ISC License. +# Configuration. + +DTL_FULL_PATH ?= 0 + # Verbosity. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F)); @@ -11,9 +15,11 @@ dtl_verbose = $(dtl_verbose_$(V)) define compile_erlydtl $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \ Compile = fun(F) -> \ - Module = list_to_atom( \ - string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \ - erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \ + 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)", " ")], \ init:stop()' -- cgit v1.2.3