if(!dojo._hasResource["dojox.dtl.tests.html.tag"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. dojo._hasResource["dojox.dtl.tests.html.tag"] = true; dojo.provide("dojox.dtl.tests.html.tag"); dojo.require("dojox.dtl.html"); dojo.require("dojox.dtl.Context"); dojo.require("dojox.dtl.tests.html.util"); doh.register("dojox.dtl.html.tag", [ function test_errors(t){ var dd = dojox.dtl; var template; // No root node after rendering var found = false; try { template = new dd.HtmlTemplate('No div'); dd.tests.html.util.render(template); }catch(e){ t.is("Text should not exist outside of the root node in template", e.message); found = true; } t.t(found); var context = new dojox.dtl.Context({test: "Pocket"}); found = false; try { template = new dd.HtmlTemplate('{{ test }}'); dd.tests.html.util.render(template, context); }catch(e){ t.is("Text should not exist outside of the root node in template", e.message); found = true; } t.t(found); template = new dd.HtmlTemplate('
extra content'); found = false; try { dd.tests.html.util.render(template); }catch(e){ t.is("Content should not exist outside of the root node in template", e.message); found = true; } t.t(found); // More than one top-level node (except for blocks) template = new dd.HtmlTemplate('
'); found = false; try { dd.tests.html.util.render(template); }catch(e){ t.is("Content should not exist outside of the root node in template", e.message); found = true; } t.t(found); // Logic block rules out any root node template = new dd.HtmlTemplate('{% if missing %}
{% endif %}'); found = false; try { dd.tests.html.util.render(template); }catch(e){ t.is("Rendered template does not have a root node", e.message); found = true; } t.t(found); }, function test_structures(t){ var dd = dojox.dtl; var context = new dd.Context({ actions: ["ate", "picked"], items: [ { name: "apple" }, { name: "banana", date: new Date(2007, 2, 16, 14, 30, 10) }, { name: "orange", date: new Date(2008, 0, 1, 12, 0, 0) } ] }); var template = new dd.HtmlTemplate('
'); t.is('
', dd.tests.html.util.render(template, context)); }, function test_tag_extend(t){ // Problems to look for: // * Content outside of blocks }, function test_tag_for(t){ var dd = dojox.dtl; var context = new dd.Context({ items: ["apple", "banana", "lemon"] }); var template = new dd.HtmlTemplate('
'); t.is('
', dd.tests.html.util.render(template, context)); // The line break is there to make sure our regex works template = new dd.HtmlTemplate('
'); t.is('
', dd.tests.html.util.render(template, context)); }, function test_tag_if(t){ var dd = dojox.dtl; var context = new dd.Context({key: true}); var template = new dd.HtmlTemplate('{% if key %}
has key
{% else %}
no key
{% endif %}'); t.is("
has key
", dd.tests.html.util.render(template, context)); context.key = false; t.is("
no key
", dd.tests.html.util.render(template, context)); }, function test_tag_ifchanged(t){ var dd = dojox.dtl; var context = new dd.Context({ year: 2008, days: [ new Date(2008, 0, 12), new Date(2008, 0, 28), new Date(2008, 1, 1), new Date(2008, 1, 1), new Date(2008, 1, 1) ] }); var template = new dd.HtmlTemplate("

Archive for {{ year }}

"+ "{% for date in days %}"+ '{% ifchanged %}

Month:

{{ date|date:"F" }}

{% endifchanged %}'+ '{{ date|date:\'j\' }}'+ "{% endfor %}
"); t.is('

Archive for 2008

'+ '

Month:

January

'+ '12'+ '28'+ '

Month:

February

'+ '1'+ '1'+ '1
', dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate('
{% for date in days %}'+ '{% ifchanged date.date %} {{ date.date }} {% endifchanged %}'+ '{% ifchanged date.hour date.date %}'+ '{{ date.hour }}'+ '{% endifchanged %}'+ '{% endfor %}
'); t.is('
2008-01-12 0 2008-01-28 0 2008-02-01 0
', dd.tests.html.util.render(template, context)); }, function test_tag_ifequal(t){ var dd = dojox.dtl; var context = new dd.Context({ items: [ { name: "apple", color: "red" }, { name: "banana", color: "yellow" }, { name: "pear", color: "green" }, { name: "kiwi", color: "brown" } ], edit_item: "banana" }); var template = new dd.HtmlTemplate("
"); t.is('
', dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate("
"); t.is('
', dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate("
"); t.is('
', dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate("
"); t.is('
', dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate("
"); t.is('
', dd.tests.html.util.render(template, context)); }, function test_tag_include(t){ var dd = dojox.dtl; var context = new dd.Context({ hello: dojo.moduleUrl("dojox.dtl.tests.templates", "hello.html"), person: "Bob", people: ["Charles", "Ralph", "Julia"] }); var template = new dd.HtmlTemplate("
{% include hello %}
"); t.is("
Hello, Bob
", dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate('
{% include "../../dojox/dtl/tests/templates/hello.html" %}
'); t.is("
Hello, Bob
", dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate('
{% for person in people %}
{% include hello %}
{% endfor %}
'); t.is('
Hello, Charles
Hello, Ralph
Hello, Julia
', dd.tests.html.util.render(template, context)); }, function test_tag_spaceless(t){ var dd = dojox.dtl; var template = new dd.HtmlTemplate("{% spaceless %}{% endspaceless %}"); t.is("", dd.tests.html.util.render(template)); }, function test_tag_ssi(t){ var dd = dojox.dtl; var context = new dd.Context({ hello: dojo.moduleUrl("dojox.dtl.tests.templates", "hello.html"), person: "Bob", people: ["Charles", "Ralph", "Julia"] }); var template = new dd.HtmlTemplate("
{% ssi hello parsed %}
"); t.is("
Hello, Bob
", dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate("
{% ssi hello %}
"); t.is("
Hello, {{ person }}
", dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate('
{% ssi "../../dojox/dtl/tests/templates/hello.html" parsed %}
'); t.is("
Hello, Bob
", dd.tests.html.util.render(template, context)); template = new dd.HtmlTemplate('
{% for person in people %}{% ssi hello parsed %} {% endfor %}
'); t.is("
Hello, Charles Hello, Ralph Hello, Julia
", dd.tests.html.util.render(template, context)); } ] ); }