README 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. -------------------------------------------------------------------------------
  2. DojoX Django Template Language
  3. -------------------------------------------------------------------------------
  4. Version 0.0
  5. Release date: 09/20/2007
  6. -------------------------------------------------------------------------------
  7. Project state: experimental/feature incomplete
  8. -------------------------------------------------------------------------------
  9. Project authors
  10. Neil Roberts (pottedmeat@dojotoolkit.org)
  11. -------------------------------------------------------------------------------
  12. Project description
  13. The Django Template language uses a system of templates that can be compiled
  14. once and rendered indefinitely afterwards. It uses a simple system of tags
  15. and filters.
  16. This is a 1:1 match with the Django Template Language as outlined in
  17. http://www.djangoproject.com/documentation/templates/. All applicable tags and
  18. filters have been implemented (see below), along with new filters and tags as
  19. necessary (see below).
  20. The Django Template Language is intended within Django to only handle text.
  21. Our implementation is able to handle HTML in addition to text. Actually, the
  22. text and HTML portions of dojox.dtl are two separate layers, the HTML layer
  23. sits on top of the text layer (base). It's also been implemented in such a way
  24. that you have little to fear when moving your code from Django to dojox.dtl.
  25. Your existing templates should work, and will benefit from the massive
  26. performance gain of being able to manipulate nodes, rather than having to do
  27. clunky innerHTML swaps you would have to do with a text-only system. It also
  28. allows for new HTML-centric abilities, outlined below.
  29. Despite having two levels of complexity, if you write your tags correctly, they
  30. will work in both environments.
  31. -------------------------------------------------------------------------------
  32. Dependencies
  33. Base:
  34. dojox.string.Builder
  35. Date filters and tags:
  36. dojox.date.php
  37. Widget:
  38. dijit._Widget
  39. dijit._Container
  40. -------------------------------------------------------------------------------
  41. Installation instructions
  42. Grab the following from the Dojo SVN Repository:
  43. http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/dtl.js
  44. http://svn.dojotoolkit.org/var/src/dojo/dojox/trunk/dtl/*
  45. Install into the following directory structure:
  46. /dojox/dtl/
  47. ...which should be at the same level as your Dojo checkout.
  48. -------------------------------------------------------------------------------
  49. What's Been Done
  50. Note: HTML Unit Tests should only be around for the oddities of HTML, tag/filter
  51. code is the same for each environment with minor exceptions. Cloning of all tags
  52. should be tested inside a for loop.
  53. | Implemented | Tag | Text Unit Test | HTML Unit Test |
  54. | X | block | X | |
  55. | X | comment | X | |
  56. | X | cycle | X | |
  57. | X | debug | X | |
  58. | X | extends | X | |
  59. | X | filter | X | |
  60. | X | firstof | X | |
  61. | X | for | X | |
  62. | X | if | X | |
  63. | X | ifchanged | X | X |
  64. | X | ifequal | X | |
  65. | X | ifnotequal | X | |
  66. | X | include | X | X |
  67. | X | load | X | |
  68. | X | now | X | |
  69. | X | regroup | X | |
  70. | X | spaceless | X | X |
  71. | X | ssi | X | X |
  72. | X | templatetag | X | |
  73. | N/A | url | | |
  74. | X | widthratio | X | |
  75. | X | with | X | |
  76. | Implemented | Filter | Text Unit Test | HTML Unit Test |
  77. | X | add | X | |
  78. | X | addslashes | X | |
  79. | X | capfirst | X | |
  80. | X | center | X | |
  81. | X | cut | X | |
  82. | X | date | X | |
  83. | X | default | X | |
  84. | X | default_if_none | X | |
  85. | X | dictsort | X | |
  86. | X | dictsort_reversed | X | |
  87. | X | divisibleby | X | |
  88. | X | escape | X | |
  89. | X | filesizeformat | X | |
  90. | X | first | X | |
  91. | X | fix_ampersands | X | |
  92. | X | floatformat | X | |
  93. | X | get_digit | X | |
  94. | X | iriencode | X | |
  95. | X | join | X | |
  96. | X | length | X | |
  97. | X | length_is | X | |
  98. | X | linebreaks | X | |
  99. | X | linebreaksbr | X | |
  100. | X | linenumbers | X | |
  101. | X | ljust | X | |
  102. | X | lower | X | |
  103. | X | make_list | X | |
  104. | X | phone2numeric | X | |
  105. | X | pluralize | X | |
  106. | X | pprint | X | |
  107. | X | random | X | |
  108. | X | removetags | X | |
  109. | X | rjust | X | |
  110. | X | slice | X | |
  111. | X | slugify | X | |
  112. | X | stringformat | X | |
  113. | X | striptags | X | |
  114. | X | time | X | |
  115. | X | timesince | X | |
  116. | X | timeuntil | X | |
  117. | X | title | X | |
  118. | X | truncatewords | X | |
  119. | X | truncatewords_html | X | |
  120. | X | unordered_list | X | |
  121. | X | upper | X | |
  122. | X | urlencode | X | |
  123. | X | urlize | X | |
  124. | X | urlizetrunc | X | |
  125. | X | wordcount | X | |
  126. | X | wordwrap | X | |
  127. | X | yesno | X | |
  128. -------------------------------------------------------------------------------
  129. HTML-Specific Additions
  130. -------------------------------------------------------------------------------
  131. {%extends "shared:templates/template.html" %}
  132. When using the {% extends %} tag, we don't always want to replace the parent
  133. node in DOM. For example, if we have a list view and a detail view, but both
  134. share the same base template, we want it to share the parent template. This
  135. basically means that the same nodes will be used in the parent for both views.
  136. To use this, simply add "shared:" to the beginning of the specified template.
  137. -------------------------------------------------------------------------------
  138. <!--{% commented markup %}-->
  139. Some browsers treat comment nodes as full fledged nodes. If performance is
  140. important to you, you can wrap your markup in comments. The comments will be
  141. automatically stripped for browsers that cannot support this.
  142. -------------------------------------------------------------------------------
  143. Attribute Tags
  144. If a tag name begins with "attr:" then it will be able to inject an object
  145. into the parsed template. (See dojox.dtl.tag.event.EventNode)
  146. onclick/onmouseover/etc attributes work by attaching to the rendering object.
  147. tstyle attribute allows for styles to be changed dynamically. Use them just
  148. like a "style" attribute.
  149. attach attribute attaches the node to the rendering object.
  150. -------------------------------------------------------------------------------
  151. New Context Functions
  152. setThis() and getThis() returns the object "in charge" of the current rendering.
  153. This is used so that we can attach events.
  154. mixin() and filter() clone the current context, and either add to or reduce
  155. the keys in the context.
  156. -------------------------------------------------------------------------------
  157. Buffers
  158. Both the base and HTML versions of dojox.dtl use buffers. The base version uses
  159. dojox.string.Builder and the HTML version uses dojox.dtl.DomBuffer.
  160. The HTML buffer has several calls important to rendering:
  161. setParent/getParent/concat/remove:
  162. setParent and concat are used in order to render our HTML. As we move through
  163. the parsed template, different nodes change the parent or add on to the
  164. current parent. getParent is useful in things like the attribute tags, since
  165. they can use getParent to find the node that they're an attribute on. remove is
  166. used during unrendering.
  167. setAttribute:
  168. Sets an attribute on the current parent
  169. -------------------------------------------------------------------------------
  170. Tags Need clone/unrender Functions.
  171. One of the biggest challenges of getting dojox.dtl to work in an HTML
  172. environment was logic blocks. Nodes and objects inside a for loop need to be
  173. cloned, they can't simply be re-rendered, especially if they involve a Node.
  174. Also, in the case of an if/else block, we need to be able to not just render
  175. one of the blocks, but also unrender the second.
  176. This is really simple code, a good example is the dojox.dtl.DomNode
  177. object. Each function in this object is only one line long.