818
Du
dustymarkdown / files
dustymarkdown / node_modules / dust / benchmark / suites / jquery_suite.js
2.1 KB
1(function(exports){ 2 3var benches = { 4 5 string: { 6 source: "Hello World!", 7 context: {} 8 }, 9 10 replace: { 11 source: "Hello ${name}! You have ${count} new messages.", 12 context: { name: "Mick", count: 30 } 13 }, 14 15 array: { 16 source: "{{each names}}${name}{{/each}}", 17 context: { names: [{name: "Moe"}, {name: "Larry"}, {name: "Curly"}, {name: "Shemp"}] } 18 }, 19 20 object: { 21 source: "${person.name}${person.age}", 22 context: { person: { name: "Larry", age: 45 } } 23 }, 24 25 partial: { 26 source: "{{tmpl(peeps) \"replace\"}}", 27 context: { peeps: [{name: "Moe", count: 15}, {name: "Larry", count: 5}, {name: "Curly", count: 1}] } 28 }, 29 30 recursion: { 31 source: "${name}{{tmpl(kids) \"recursion\"}}", 32 context: { 33 name: '1', 34 kids: [ 35 { 36 name: '1.1', 37 kids: [ 38 {name: '1.1.1', kids: []} 39 ] 40 } 41 ] 42 } 43 }, 44 45 filter: { 46 source: "FOO ${bar.toUpperCase()}", 47 context: { 48 bar: "bar" 49 } 50 }, 51 52 complex: { 53 source: "<h1>${header}</h1>{{if items.length}}<ul>{{each items}}{{if current}}" + 54 "<li><strong>${name}</strong></li>{{else}}" + 55 "<li><a href=\"${url}\">${name}</a></li>{{/if}}" + 56 "{{/each}}</ul>{{else}}<p>The list is empty.</p>{{/if}}", 57 context: { 58 header: function() { 59 return "Colors"; 60 }, 61 items: [ 62 {name: "red", current: true, url: "#Red"}, 63 {name: "green", current: false, url: "#Green"}, 64 {name: "blue", current: false, url: "#Blue"} 65 ] 66 } 67 } 68 69} 70 71exports.jqueryBench = function(suite, name, id) { 72 var bench = benches[name], 73 fn = $.template(name, bench.source), 74 ctx = bench.context; 75 76 suite.bench(id || name, function(next) { 77 $.tmpl(fn, ctx); 78 next(); 79 }); 80} 81 82exports.jqueryBench.benches = benches; 83 84})(typeof exports !== "undefined" ? exports : window);