README 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 aims to be a 1:1 match with the Django Template Language as outlined in
  17. http://www.djangoproject.com/documentation/templates/. Many common 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. | Implemented | Tag | Text Unit Test | HTML Unit Test |
  51. | X | block | X | |
  52. | X | comment | X | |
  53. | X | cycle | X | |
  54. | X | debug | X | |
  55. | X | extends | X | |
  56. | X | filter | X | |
  57. | | firstof | | |
  58. | X | for | | |
  59. | X | if | | |
  60. | | ifchanged | | |
  61. | | ifequal | | |
  62. | | ifnotequal | | |
  63. | | include | | |
  64. | | load | | |
  65. | | now | | |
  66. | | regroup | | |
  67. | | spaceless | | |
  68. | | ssi | | |
  69. | | templatetag | | |
  70. | | url | | |
  71. | | widthratio | | |
  72. | | with | | |
  73. | Implemented | Filter | Text Unit Test | HTML Unit Test |
  74. | X | add | X | |
  75. | X | addslashes | X | |
  76. | X | capfirst | X | |
  77. | X | center | X | |
  78. | X | cut | X | |
  79. | X | date | X | |
  80. | X | default | X | |
  81. | X | default_if_none | X | |
  82. | X | dictsort | X | |
  83. | X | dictsort_reversed | X | |
  84. | X | divisibleby | X | |
  85. | X | escape | X | |
  86. | X | filesizeformat | X | |
  87. | X | first | X | |
  88. | X | fix_ampersands | X | |
  89. | X | floatformat | X | |
  90. | X | get_digit | X | |
  91. | X | iriencode | X | |
  92. | X | join | X | |
  93. | X | length | X | |
  94. | X | length_is | X | |
  95. | X | linebreaks | X | |
  96. | X | linebreaksbr | X | |
  97. | X | linenumbers | X | |
  98. | X | ljust | X | |
  99. | X | lower | X | |
  100. | X | make_list | X | |
  101. | X | phone2numeric | X | |
  102. | X | pluralize | X | |
  103. | X | pprint | X | |
  104. | X | random | X | |
  105. | X | removetags | X | |
  106. | X | rjust | X | |
  107. | X | slice | X | |
  108. | X | slugify | X | |
  109. | X | stringformat | X | |
  110. | X | striptags | X | |
  111. | X | time | X | |
  112. | X | timesince | X | |
  113. | X | timeuntil | X | |
  114. | X | title | X | |
  115. | X | truncatewords | X | |
  116. | X | truncatewords_html | X | |
  117. | X | unordered_list | X | |
  118. | X | upper | X | |
  119. | X | urlencode | X | |
  120. | X | urlize | X | |
  121. | X | urlizetrunc | X | |
  122. | X | wordcount | X | |
  123. | X | wordwrap | X | |
  124. | X | yesno | X | |
  125. -------------------------------------------------------------------------------
  126. HTML-Specific Additions
  127. -------------------------------------------------------------------------------
  128. {%extends "shared:templates/template.html" %}
  129. When using the {% extends %} tag, we don't always want to replace the parent
  130. node in DOM. For example, if we have a list view and a detail view, but both
  131. share the same base template, we want it to share the parent template. This
  132. basically means that the same nodes will be used in the parent for both views.
  133. To use this, simply add "shared:" to the beginning of the specified template.
  134. -------------------------------------------------------------------------------
  135. <!--{% commented markup %}-->
  136. Some browsers treat comment nodes as full fledged nodes. If performance is
  137. important to you, you can wrap your markup in comments. The comments will be
  138. automatically stripped for browsers that cannot support this.
  139. -------------------------------------------------------------------------------
  140. Attribute Tags
  141. If a tag name begins with "attr:" then it will be able to inject an object
  142. into the parsed template. (See dojox.dtl.tag.event.EventNode)
  143. onclick/onmouseover/etc attributes work by attaching to the rendering object.
  144. tstyle attribute allows for styles to be changed dynamically. Use them just
  145. like a "style" attribute.
  146. attach attribute attaches the node to the rendering object.
  147. -------------------------------------------------------------------------------
  148. New Context Functions
  149. setThis() and getThis() returns the object "in charge" of the current rendering.
  150. This is used so that we can attach events.
  151. mixin() and filter() clone the current context, and either add to or reduce
  152. the keys in the context.
  153. -------------------------------------------------------------------------------
  154. Buffers
  155. Both the base and HTML versions of dojox.dtl use buffers. The base version uses
  156. dojox.string.Builder and the HTML version uses dojox.dtl.HtmlBuffer.
  157. The HTML buffer has several calls important to rendering:
  158. setParent/getParent/concat/remove:
  159. setParent and concat are used in order to render our HTML. As we move through
  160. the parsed template, different nodes change the parent or add on to the
  161. current parent. getParent is useful in things like the attribute tags, since
  162. they can use getParent to find the node that they're an attribute on. remove is
  163. used during unrendering.
  164. setAttribute:
  165. Sets an attribute on the current parent
  166. -------------------------------------------------------------------------------
  167. Tags Need clone/unrender Functions.
  168. One of the biggest challenges of getting dojox.dtl to work in an HTML
  169. environment was logic blocks. Nodes and objects inside a for loop need to be
  170. cloned, they can't simply be re-rendered, especially if they involve a Node.
  171. Also, in the case of an if/else block, we need to be able to not just render
  172. one of the blocks, but also unrender the second.
  173. This is really simple code, a good example is the dojox.dtl.HtmlNode
  174. object. Each function in this object is only one line long.