1edfce8e77ff82bbf261957ecaa36fb9ab844295.svn-base 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. if (!dojo._hasResource["dojox.dtl.tests.text.tag"]) { // _hasResource checks
  2. // added by build. Do
  3. // not use _hasResource
  4. // directly in your
  5. // code.
  6. dojo._hasResource["dojox.dtl.tests.text.tag"] = true;
  7. dojo.provide("dojox.dtl.tests.text.tag");
  8. dojo.require("dojox.dtl");
  9. doh.register("dojox.dtl.text.tag", [function test_tag_block_and_extends(t) {
  10. var dd = dojox.dtl;
  11. // Simple (messy) string-based extension
  12. var template = new dd.Template('{% extends "../../dojox/dtl/tests/text/templates/pocket.html" %}{% block pocket %}Simple{% endblock %}');
  13. t.is("Simple Pocket", template.render());
  14. // Variable replacement
  15. var context = new dd.Context({
  16. parent : "../../dojox/dtl/tests/text/templates/pocket.html"
  17. })
  18. template = new dd.Template('{% extends parent %}{% block pocket %}Variabled{% endblock %}');
  19. t.is("Variabled Pocket", template.render(context));
  20. // Nicer dojo.moduleUrl and variable based extension
  21. context.parent = dojo.moduleUrl("dojox.dtl.tests.text.templates",
  22. "pocket.html");
  23. template = new dd.Template('{% extends parent %}{% block pocket %}Slightly More Advanced{% endblock %}');
  24. t.is("Slightly More Advanced Pocket", template.render(context));
  25. // dojo.moduleUrl with support for more variables.
  26. // This is important for HTML templates where the "shared" flag will be
  27. // important.
  28. context.parent = {
  29. url : dojo.moduleUrl("dojox.dtl.tests.text.templates",
  30. "pocket.html")
  31. }
  32. template = new dd.Template('{% extends parent %}{% block pocket %}Super{% endblock %}');
  33. t.is("Super Pocket", template.render(context));
  34. }, function test_tag_comment(t) {
  35. var dd = dojox.dtl;
  36. var template = new dd.Template('Hot{% comment %}<strong>Make me disappear</strong>{% endcomment %} Pocket');
  37. t.is("Hot Pocket", template.render());
  38. var found = false;
  39. try {
  40. template = new dd.Template('Hot{% comment %}<strong>Make me disappear</strong> Pocket');
  41. } catch (e) {
  42. t.is("Unclosed tag found when looking for endcomment", e.message);
  43. found = true;
  44. }
  45. t.t(found);
  46. }, function test_tag_cycle(t) {
  47. var dd = dojox.dtl;
  48. var context = new dd.Context({
  49. items : ["apple", "banana", "lemon"],
  50. unplugged : "Torrey"
  51. });
  52. var template = new dd.Template("{% for item in items %}{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' %} Pocket. {% endfor %}");
  53. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  54. .render(context));
  55. // Make sure that it doesn't break on re-render
  56. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  57. .render(context));
  58. // Test repeating the loop
  59. context.items.push("guava", "mango", "pineapple");
  60. t
  61. .is(
  62. "Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket. ",
  63. template.render(context));
  64. // Repeat the above tests for the old style
  65. // ========================================
  66. context.items = context.items.slice(0, 3);
  67. template = new dd.Template("{% for item in items %}{% cycle Hot,Diarrhea,Torrey,Extra %} Pocket. {% endfor %}");
  68. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  69. .render(context));
  70. // Make sure that it doesn't break on re-render
  71. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  72. .render(context));
  73. // Test repeating the loop
  74. context.items.push("guava", "mango", "pineapple");
  75. t
  76. .is(
  77. "Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket. ",
  78. template.render(context));
  79. // Now test outside of the for loop
  80. // ================================
  81. context = new dojox.dtl.Context({
  82. unplugged : "Torrey"
  83. });
  84. template = new dd.Template("{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' as steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket.");
  85. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket.", template
  86. .render(context));
  87. template = new dd.Template("{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' as steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket.");
  88. t
  89. .is(
  90. "Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket.",
  91. template.render(context));
  92. // Test for nested objects
  93. context.items = {
  94. list : ["apple", "banana", "lemon"]
  95. };
  96. template = new dd.Template("{% for item in items.list %}{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' %} Pocket. {% endfor %}");
  97. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  98. .render(context));
  99. // Make sure that it doesn't break on re-render
  100. t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template
  101. .render(context));
  102. }, function test_tag_debug(t) {
  103. var dd = dojox.dtl;
  104. var context = new dd.Context({
  105. items : ["apple", "banana", "lemon"],
  106. unplugged : "Torrey"
  107. });
  108. var template = new dd.Template("{% debug %}");
  109. t.is('items: ["apple", "banana", "lemon"]\n\nunplugged: "Torrey"\n\n',
  110. template.render(context));
  111. }, function test_tag_filter(t) {
  112. var dd = dojox.dtl;
  113. var template = new dd.Template('{% filter lower|center:"15" %}Hot Pocket{% endfilter %}');
  114. t.is(" hot pocket ", template.render());
  115. }, function test_tag_firstof(t) {
  116. t.t(false);
  117. }, function test_tag_for(t) {
  118. t.t(false);
  119. }, function test_tag_if(t) {
  120. t.t(false);
  121. }, function test_tag_ifchanged(t) {
  122. t.t(false);
  123. }, function test_tag_ifequal(t) {
  124. t.t(false);
  125. }, function test_tag_ifnotequal(t) {
  126. t.t(false);
  127. }, function test_tag_include(t) {
  128. t.t(false);
  129. }, function test_tag_load(t) {
  130. t.t(false);
  131. }, function test_tag_now(t) {
  132. t.t(false);
  133. }, function test_tag_regroup(t) {
  134. t.t(false);
  135. }, function test_tag_spaceless(t) {
  136. t.t(false);
  137. }, function test_tag_ssi(t) {
  138. t.t(false);
  139. }, function test_tag_templatetag(t) {
  140. t.t(false);
  141. }, function test_tag_url(t) {
  142. t.t(false);
  143. }, function test_tag_widthratio(t) {
  144. t.t(false);
  145. }, function test_tag_with(t) {
  146. t.t(false);
  147. }]);
  148. }