README 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ErlyDTL
  2. =======
  3. ErlyDTL implements most but not all of the Django Template Language.
  4. Project homepage: http://code.google.com/p/erlydtl/
  5. Compilation
  6. -----------
  7. To compile ErlyDTL, type "make" in this directory.
  8. Template compilation
  9. --------------------
  10. Four ways:
  11. erlydtl:compile("/path/to/template.dtl", my_module_name)
  12. erlydtl:compile("/path/to/template.dtl", my_module_name, Options)
  13. erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name)
  14. erlydtl:compile(<<"<html>{{ foo }}</html>">>, my_module_name, Options)
  15. Options is a proplist possibly containing:
  16. out_dir - Directory to store generated .beam files. If not specified, no
  17. .beam files will be created.
  18. doc_root - Included template paths will be relative to this directory;
  19. defaults to the compiled template's directory.
  20. custom_tags_dir - Directory of DTL files (no extension) includable as tags.
  21. E.g. if $custom_tags_dir/foo contains "<b>{{ bar }}</b>", then
  22. "{{ foo bar=100 }}" will evaluate to "<b>100</b>". Get it?
  23. vars - Variables (and their values) to evaluate at compile-time rather than
  24. render-time.
  25. reader - {module, function} tuple that takes a path to a template and returns
  26. a binary with the file contents. Defaults to {file, read_file}. Useful
  27. for reading templates from a network resource.
  28. compiler_options - Proplist passed directly to compiler:forms/2
  29. force_recompile - Recompile the module even if the source's checksum has not
  30. changed. Useful for debugging.
  31. Usage (of a compiled template)
  32. ------------------------------
  33. my_compiled_template:render(Variables) -> {ok, IOList} | {error, Err}
  34. Variables is a proplist, dict, gb_tree, or a parameterized module
  35. (whose method names correspond to variable names). The variable
  36. values can be atoms, strings, binaries, or (nested) variables.
  37. IOList is the rendered template.
  38. my_compiled_template:source() -> {FileName, CheckSum}
  39. Name and checksum of the original template file.
  40. my_compiled_template:dependencies() -> [{FileName, CheckSum}]
  41. List of names/checksums of templates included by the original template
  42. file. Useful for frameworks that recompile a template only when the
  43. template's dependencies change.
  44. Tests
  45. -----
  46. From a Unix shell, run:
  47. make test
  48. Note that the tests will create some output in examples/rendered_output.