plugin_erlydtl.mk 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. # ErlyDTL plugin.
  2. ERLYDTL_TARGETS = $(call list_targets,erlydtl)
  3. .PHONY: erlydtl $(ERLYDTL_TARGETS)
  4. erlydtl: $(ERLYDTL_TARGETS)
  5. erlydtl-compile: init
  6. $i "Bootstrap a new OTP library named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  10. $i "Add ErlyDTL to the list of dependencies"
  11. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
  12. $i "Generate ErlyDTL templates"
  13. $t mkdir $(APP)/templates/
  14. $t touch $(APP)/templates/$(APP)_one.dtl
  15. $t touch $(APP)/templates/$(APP)_two.dtl
  16. $i "Build the application"
  17. $t $(MAKE) -C $(APP) $v
  18. $i "Check that ErlyDTL templates are compiled"
  19. $t test -f $(APP)/ebin/$(APP)_one_dtl.beam
  20. $t test -f $(APP)/ebin/$(APP)_two_dtl.beam
  21. $i "Check that ErlyDTL generated modules are included in .app file"
  22. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  23. ok = application:load($(APP)), \
  24. {ok, [$(APP_)_one_dtl, $(APP)_two_dtl]} = application:get_key($(APP), modules), \
  25. halt()"
  26. erlydtl-custom-tag: init
  27. $i "Bootstrap a new OTP library named $(APP)"
  28. $t mkdir $(APP)/
  29. $t cp ../erlang.mk $(APP)/
  30. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  31. $i "Add ErlyDTL to the list of dependencies"
  32. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
  33. $i "Generate an ErlyDTL library module containing a custom tag"
  34. $t printf "%s\n" \
  35. "-module($(APP)_lib)." \
  36. "-behavior(erlydtl_library)." \
  37. "-export([version/0, inventory/1, mytag/2])." \
  38. "version() -> 1." \
  39. "inventory(filters) -> [];" \
  40. "inventory(tags) -> [mytag]." \
  41. "mytag(_,_) -> <<\"hello\">>." > $(APP)/src/$(APP)_lib.erl
  42. $i "Add our library to the ErlyDTL options"
  43. $t echo "DTL_OPTS = {libraries, [{erlang_mk, $(APP)_lib}]}" >> $(APP)/Makefile
  44. $i "Generate an ErlyDTL template that uses a custom tag"
  45. $t mkdir $(APP)/templates/
  46. $t printf "%s\n" \
  47. "{% load erlang_mk %}" \
  48. "{% mytag as value %}" \
  49. "{{ value }}" > $(APP)/templates/$(APP).dtl
  50. $i "Build the application"
  51. $t $(MAKE) -C $(APP) $v
  52. $i "Check that the ErlyDTL template is compiled"
  53. $t test -f $(APP)/ebin/$(APP)_dtl.beam
  54. $i "Check that ErlyDTL generated modules are included in .app file"
  55. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  56. ok = application:load($(APP)), \
  57. {ok, [$(APP_)_dtl, $(APP)_lib]} = application:get_key($(APP), modules), \
  58. halt()"
  59. $i "Confirm the custom tag is used"
  60. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/*/ebin/ -eval \
  61. 'file:write_file("$(APP)/OUT", element(2, $(APP)_dtl:render())), halt()'
  62. $t cat $(APP)/OUT | grep -q hello
  63. erlydtl-full-path: init
  64. $i "Bootstrap a new OTP library named $(APP)"
  65. $t mkdir $(APP)/
  66. $t cp ../erlang.mk $(APP)/
  67. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  68. $i "Add ErlyDTL to the list of dependencies; set DTL_FULL_PATH"
  69. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\nDTL_FULL_PATH = 1\n"}' $(APP)/Makefile
  70. $i "Generate ErlyDTL templates"
  71. $t mkdir -p $(APP)/templates/deep/
  72. $t touch $(APP)/templates/$(APP)_one.dtl
  73. $t touch $(APP)/templates/deep/$(APP)_two.dtl
  74. $i "Build the application"
  75. $t $(MAKE) -C $(APP) $v
  76. $i "Check that ErlyDTL templates are compiled"
  77. $t test -f $(APP)/ebin/$(APP)_one_dtl.beam
  78. $t test -f $(APP)/ebin/deep_$(APP)_two_dtl.beam
  79. $i "Check that ErlyDTL generated modules are included in .app file"
  80. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  81. ok = application:load($(APP)), \
  82. {ok, [deep_$(APP)_two_dtl, $(APP_)_one_dtl]} = application:get_key($(APP), modules), \
  83. halt()"
  84. erlydtl-include-template: init
  85. $i "Bootstrap a new OTP library named $(APP)"
  86. $t mkdir $(APP)/
  87. $t cp ../erlang.mk $(APP)/
  88. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  89. $i "Generate ErlyDTL templates"
  90. $t mkdir -p $(APP)/dtl/foo/
  91. $t echo '{% include "foo/bar.dtl" %}' > $(APP)/dtl/foo.dtl
  92. $t echo '{% var %}' > $(APP)/dtl/foo/bar.dtl
  93. $t echo '{% extends "bar.dtl" %}' > $(APP)/dtl/foo/baz.dtl
  94. $i "Build the application"
  95. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PATH=dtl DTL_FULL_PATH=1 DTL_SUFFIX= $v
  96. $i "Check that ErlyDTL templates are compiled"
  97. $t test -f $(APP)/ebin/foo.beam
  98. $t test -f $(APP)/ebin/foo_bar.beam
  99. $t test -f $(APP)/ebin/foo_baz.beam
  100. $i "Check that ErlyDTL generated modules are included in .app file"
  101. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  102. ok = application:load($(APP)), \
  103. {ok, [foo, foo_bar, foo_baz]} = application:get_key($(APP), modules), \
  104. halt()"
  105. erlydtl-opts: init
  106. $i "Bootstrap a new OTP library named $(APP)"
  107. $t mkdir $(APP)/
  108. $t cp ../erlang.mk $(APP)/
  109. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  110. $i "Add ErlyDTL to the list of dependencies"
  111. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
  112. $i "Generate ErlyDTL template"
  113. $t mkdir $(APP)/templates/
  114. $t echo "{{ foo }}" > $(APP)/templates/$(APP)_foo.dtl
  115. $i "Build the application with auto escape turned on"
  116. $t $(MAKE) -C $(APP) DTL_OPTS=auto_escape $v
  117. $i "Check that HTML is escaped"
  118. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  119. ok = application:load($(APP)), \
  120. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  121. <<\"&lt;&amp;&gt;\", _/binary>> = iolist_to_binary(Result), \
  122. halt()"
  123. $i "Clean the application"
  124. $t $(MAKE) -C $(APP) clean $v
  125. $i "Build the application with auto escape turned off"
  126. $t $(MAKE) -C $(APP) "DTL_OPTS={auto_escape, false}" $v
  127. $i "Check that HTML is not escaped"
  128. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  129. ok = application:load($(APP)), \
  130. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  131. <<\"<&>\", _/binary>> = iolist_to_binary(Result), \
  132. halt()"
  133. erlydtl-path-full-path-suffix: init
  134. $i "Bootstrap a new OTP library named $(APP)"
  135. $t mkdir $(APP)/
  136. $t cp ../erlang.mk $(APP)/
  137. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  138. $i "Generate ErlyDTL templates"
  139. $t mkdir -p $(APP)/dtl/two/
  140. $t touch $(APP)/dtl/one.dtl
  141. $t touch $(APP)/dtl/two/three.dtl
  142. $i "Build the application"
  143. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PATH=dtl DTL_FULL_PATH=1 DTL_SUFFIX=_suffix $v
  144. $i "Check that ErlyDTL templates are compiled"
  145. $t test -f $(APP)/ebin/one_suffix.beam
  146. $t test -f $(APP)/ebin/two_three_suffix.beam
  147. $i "Check that ErlyDTL generated modules are included in .app file"
  148. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  149. ok = application:load($(APP)), \
  150. {ok, [one_suffix, two_three_suffix]} = application:get_key($(APP), modules), \
  151. halt()"
  152. erlydtl-prefix: init
  153. $i "Bootstrap a new OTP library named $(APP)"
  154. $t mkdir $(APP)/
  155. $t cp ../erlang.mk $(APP)/
  156. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  157. $i "Generate ErlyDTL templates"
  158. $t mkdir $(APP)/templates/
  159. $t touch $(APP)/templates/one.dtl
  160. $t touch $(APP)/templates/two.dtl
  161. $i "Build the application"
  162. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PREFIX=number_ $v
  163. $i "Check that ErlyDTL templates are compiled"
  164. $t test -f $(APP)/ebin/number_one_dtl.beam
  165. $t test -f $(APP)/ebin/number_two_dtl.beam
  166. $i "Check that ErlyDTL generated modules are included in .app file"
  167. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  168. ok = application:load($(APP)), \
  169. {ok, [number_one_dtl, number_two_dtl]} = application:get_key($(APP), modules), \
  170. halt()"
  171. erlydtl-suffix: init
  172. $i "Bootstrap a new OTP library named $(APP)"
  173. $t mkdir $(APP)/
  174. $t cp ../erlang.mk $(APP)/
  175. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  176. $i "Generate ErlyDTL templates"
  177. $t mkdir $(APP)/templates/
  178. $t touch $(APP)/templates/one.dtl
  179. $t touch $(APP)/templates/two.dtl
  180. $i "Build the application"
  181. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_SUFFIX= $v
  182. $i "Check that ErlyDTL templates are compiled"
  183. $t test -f $(APP)/ebin/one.beam
  184. $t test -f $(APP)/ebin/two.beam
  185. $i "Check that ErlyDTL generated modules are included in .app file"
  186. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  187. ok = application:load($(APP)), \
  188. {ok, [one, two]} = application:get_key($(APP), modules), \
  189. halt()"