README 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. locale - The locale used for template compile. Requires erlang_gettext. It
  32. will ask gettext_server for the string value on the provided locale.
  33. For example, adding {locale, "en_US"} will call {key2str, Key, "en_US"}
  34. for all string marked as trans ({% trans "StringValue"%} on templates).
  35. See README_I18N.
  36. Usage (of a compiled template)
  37. ------------------------------
  38. my_compiled_template:render(Variables) -> {ok, IOList} | {error, Err}
  39. Variables is a proplist, dict, gb_tree, or a parameterized module
  40. (whose method names correspond to variable names). The variable
  41. values can be atoms, strings, binaries, or (nested) variables.
  42. IOList is the rendered template.
  43. my_compiled_template:source() -> {FileName, CheckSum}
  44. Name and checksum of the original template file.
  45. my_compiled_template:dependencies() -> [{FileName, CheckSum}]
  46. List of names/checksums of templates included by the original template
  47. file. Useful for frameworks that recompile a template only when the
  48. template's dependencies change.
  49. Tests
  50. -----
  51. From a Unix shell, run:
  52. make test
  53. Note that the tests will create some output in examples/rendered_output.