plugin_erlydtl.mk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # ErlyDTL plugin.
  2. ERLYDTL_CASES = compile full-path opts
  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()"