plugin_erlydtl.mk 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # ErlyDTL plugin.
  2. ERLYDTL_CASES = compile 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-full-path: 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; set DTL_FULL_PATH"
  33. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\nDTL_FULL_PATH = 1\n"}' $(APP)/Makefile
  34. $i "Generate ErlyDTL templates"
  35. $t mkdir -p $(APP)/templates/deep/
  36. $t touch $(APP)/templates/$(APP)_one.dtl
  37. $t touch $(APP)/templates/deep/$(APP)_two.dtl
  38. $i "Build the application"
  39. $t $(MAKE) -C $(APP) $v
  40. $i "Check that ErlyDTL templates are compiled"
  41. $t test -f $(APP)/ebin/$(APP)_one_dtl.beam
  42. $t test -f $(APP)/ebin/deep_$(APP)_two_dtl.beam
  43. $i "Check that ErlyDTL generated modules are included in .app file"
  44. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  45. ok = application:load($(APP)), \
  46. {ok, [deep_$(APP)_two_dtl, $(APP_)_one_dtl]} = application:get_key($(APP), modules), \
  47. halt()"
  48. erlydtl-include-template: build clean
  49. $i "Bootstrap a new OTP library named $(APP)"
  50. $t mkdir $(APP)/
  51. $t cp ../erlang.mk $(APP)/
  52. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  53. $i "Generate ErlyDTL templates"
  54. $t mkdir -p $(APP)/dtl/foo/
  55. $t echo '{% include "foo/bar.dtl" %}' > $(APP)/dtl/foo.dtl
  56. $t echo '{% var %}' > $(APP)/dtl/foo/bar.dtl
  57. $t echo '{% extends "bar.dtl" %}' > $(APP)/dtl/foo/baz.dtl
  58. $i "Build the application"
  59. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PATH=dtl DTL_FULL_PATH=1 DTL_SUFFIX= $v
  60. $i "Check that ErlyDTL templates are compiled"
  61. $t test -f $(APP)/ebin/foo.beam
  62. $t test -f $(APP)/ebin/foo_bar.beam
  63. $t test -f $(APP)/ebin/foo_baz.beam
  64. $i "Check that ErlyDTL generated modules are included in .app file"
  65. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  66. ok = application:load($(APP)), \
  67. {ok, [foo, foo_bar, foo_baz]} = application:get_key($(APP), modules), \
  68. halt()"
  69. erlydtl-opts: build clean
  70. $i "Bootstrap a new OTP library named $(APP)"
  71. $t mkdir $(APP)/
  72. $t cp ../erlang.mk $(APP)/
  73. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  74. $i "Add ErlyDTL to the list of dependencies"
  75. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
  76. $i "Generate ErlyDTL template"
  77. $t mkdir $(APP)/templates/
  78. $t echo "{{ foo }}" > $(APP)/templates/$(APP)_foo.dtl
  79. $i "Build the application with auto escape turned on"
  80. $t $(MAKE) -C $(APP) DTL_OPTS=auto_escape $v
  81. $i "Check that HTML is escaped"
  82. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  83. ok = application:load($(APP)), \
  84. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  85. <<\"&lt;&amp;&gt;\", _/binary>> = iolist_to_binary(Result), \
  86. halt()"
  87. $i "Clean the application"
  88. $t $(MAKE) -C $(APP) clean $v
  89. $i "Build the application with auto escape turned off"
  90. $t $(MAKE) -C $(APP) "DTL_OPTS={auto_escape, false}" $v
  91. $i "Check that HTML is not escaped"
  92. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  93. ok = application:load($(APP)), \
  94. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  95. <<\"<&>\", _/binary>> = iolist_to_binary(Result), \
  96. halt()"
  97. erlydtl-path-full-path-suffix: build clean
  98. $i "Bootstrap a new OTP library named $(APP)"
  99. $t mkdir $(APP)/
  100. $t cp ../erlang.mk $(APP)/
  101. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  102. $i "Generate ErlyDTL templates"
  103. $t mkdir -p $(APP)/dtl/two/
  104. $t touch $(APP)/dtl/one.dtl
  105. $t touch $(APP)/dtl/two/three.dtl
  106. $i "Build the application"
  107. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PATH=dtl DTL_FULL_PATH=1 DTL_SUFFIX=_suffix $v
  108. $i "Check that ErlyDTL templates are compiled"
  109. $t test -f $(APP)/ebin/one_suffix.beam
  110. $t test -f $(APP)/ebin/two_three_suffix.beam
  111. $i "Check that ErlyDTL generated modules are included in .app file"
  112. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  113. ok = application:load($(APP)), \
  114. {ok, [one_suffix, two_three_suffix]} = application:get_key($(APP), modules), \
  115. halt()"
  116. erlydtl-suffix: build clean
  117. $i "Bootstrap a new OTP library named $(APP)"
  118. $t mkdir $(APP)/
  119. $t cp ../erlang.mk $(APP)/
  120. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  121. $i "Generate ErlyDTL templates"
  122. $t mkdir $(APP)/templates/
  123. $t touch $(APP)/templates/one.dtl
  124. $t touch $(APP)/templates/two.dtl
  125. $i "Build the application"
  126. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_SUFFIX= $v
  127. $i "Check that ErlyDTL templates are compiled"
  128. $t test -f $(APP)/ebin/one.beam
  129. $t test -f $(APP)/ebin/two.beam
  130. $i "Check that ErlyDTL generated modules are included in .app file"
  131. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  132. ok = application:load($(APP)), \
  133. {ok, [one, two]} = application:get_key($(APP), modules), \
  134. halt()"