plugin_erlydtl.mk 7.1 KB

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