plugin_erlydtl.mk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # ErlyDTL plugin.
  2. ERLYDTL_CASES = compile full-path 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-opts: 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 "Add ErlyDTL to the list of dependencies"
  54. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
  55. $i "Generate ErlyDTL template"
  56. $t mkdir $(APP)/templates/
  57. $t echo "{{ foo }}" > $(APP)/templates/$(APP)_foo.dtl
  58. $i "Build the application with auto escape turned on"
  59. $t $(MAKE) -C $(APP) DTL_OPTS=auto_escape $v
  60. $i "Check that HTML is escaped"
  61. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  62. ok = application:load($(APP)), \
  63. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  64. <<\"&lt;&amp;&gt;\", _/binary>> = iolist_to_binary(Result), \
  65. halt()"
  66. $i "Clean the application"
  67. $t $(MAKE) -C $(APP) clean $v
  68. $i "Build the application with auto escape turned off"
  69. $t $(MAKE) -C $(APP) "DTL_OPTS={auto_escape, false}" $v
  70. $i "Check that HTML is not escaped"
  71. $t $(ERL) -pa $(APP)/ebin/ $(APP)/deps/erlydtl/ebin/ -eval " \
  72. ok = application:load($(APP)), \
  73. {ok, Result} = $(APP)_foo_dtl:render([{foo, <<\"<&>\">>}]), \
  74. <<\"<&>\", _/binary>> = iolist_to_binary(Result), \
  75. halt()"
  76. erlydtl-path-full-path-suffix: build clean
  77. $i "Bootstrap a new OTP library named $(APP)"
  78. $t mkdir $(APP)/
  79. $t cp ../erlang.mk $(APP)/
  80. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  81. $i "Generate ErlyDTL templates"
  82. $t mkdir -p $(APP)/dtl/two/
  83. $t touch $(APP)/dtl/one.dtl
  84. $t touch $(APP)/dtl/two/three.dtl
  85. $i "Build the application"
  86. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_PATH=dtl DTL_FULL_PATH=1 DTL_SUFFIX=_suffix $v
  87. $i "Check that ErlyDTL templates are compiled"
  88. $t test -f $(APP)/ebin/one_suffix.beam
  89. $t test -f $(APP)/ebin/two_three_suffix.beam
  90. $i "Check that ErlyDTL generated modules are included in .app file"
  91. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  92. ok = application:load($(APP)), \
  93. {ok, [one_suffix, two_three_suffix]} = application:get_key($(APP), modules), \
  94. halt()"
  95. erlydtl-suffix: build clean
  96. $i "Bootstrap a new OTP library named $(APP)"
  97. $t mkdir $(APP)/
  98. $t cp ../erlang.mk $(APP)/
  99. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  100. $i "Generate ErlyDTL templates"
  101. $t mkdir $(APP)/templates/
  102. $t touch $(APP)/templates/one.dtl
  103. $t touch $(APP)/templates/two.dtl
  104. $i "Build the application"
  105. $t $(MAKE) -C $(APP) DEPS=erlydtl DTL_SUFFIX= $v
  106. $i "Check that ErlyDTL templates are compiled"
  107. $t test -f $(APP)/ebin/one.beam
  108. $t test -f $(APP)/ebin/two.beam
  109. $i "Check that ErlyDTL generated modules are included in .app file"
  110. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  111. ok = application:load($(APP)), \
  112. {ok, [one, two]} = application:get_key($(APP), modules), \
  113. halt()"