README 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. doc_root - Included template paths will be relative to this directory;
  17. defaults to the compiled template's directory.
  18. custom_tags_dir - Directory of DTL files (no extension) includable as tags.
  19. E.g. if $custom_tags_dir/foo contains "<b>{{ bar }}</b>", then
  20. "{{ foo bar=100 }}" will evaluate to "<b>100</b>". Get it?
  21. vars - Variables (and their values) to evaluate at compile-time rather than
  22. render-time.
  23. reader - {module, function} tuple that takes a path to a template and returns
  24. a binary with the file contents. Defaults to {file, read_file}. Useful
  25. for reading templates from a network resource.
  26. compiler_options - Proplist passed directly to compiler:forms/2
  27. force_recompile - Recompile the module even if the source's checksum has not
  28. changed. Useful for debugging.
  29. Usage (of a compiled template)
  30. ------------------------------
  31. my_compiled_template:render(Variables) -> {ok, IOList} | {error, Err}
  32. Variables is a proplist, dict, gb_tree, or a parameterized module
  33. (whose method names correspond to variable names). The variable
  34. values can be atoms, strings, binaries, or (nested) variables.
  35. IOList is the rendered template.
  36. my_compiled_template:source() -> {FileName, CheckSum}
  37. Name and checksum of the original template file.
  38. my_compiled_template:dependencies() -> [{FileName, CheckSum}]
  39. List of names/checksums of templates included by the original template
  40. file. Useful for frameworks that recompile a template only when the
  41. template's dependencies change.
  42. Tests
  43. -----
  44. From a Unix shell, run:
  45. make test
  46. Note that the tests will create some output in examples/rendered_output.