818
Du
dustymarkdown / files
dustymarkdown / node_modules / dust / benchmark / suites / dust_suite.js
3.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: "{#names}{name}{/names}", 17 context: { names: [ 18 { name: "Moe" }, 19 { name: "Larry" }, 20 { name: "Curly" }, 21 { name: "Shemp" } 22 ] 23 } 24 }, 25 26 object: { 27 source: "{#person}{name}{age}{/person}", 28 context: { person: { name: "Larry", age: 45 } } 29 }, 30 31 partial: { 32 source: "{#peeps}{>replace/}{/peeps}", 33 context: { peeps: [ 34 { name: "Moe", count: 15 }, 35 { name: "Larry", count: 5 }, 36 { name: "Curly", count: 0 } 37 ] 38 } 39 }, 40 41 recursion: { 42 source: "{name}{#kids}{>recursion:./}{/kids}", 43 context: { 44 name: '1', 45 kids: [ 46 { 47 name: '1.1', 48 kids: [ 49 {name: '1.1.1'} 50 ] 51 } 52 ] 53 } 54 }, 55 56 filter: { 57 source: "{#filter}foo {bar}{/filter}", 58 context: { 59 filter: function(chunk, context, bodies) { 60 return chunk.tap(function(data) { 61 return data.toUpperCase(); 62 }).render(bodies.block, context).untap(); 63 }, 64 bar: "bar" 65 } 66 }, 67 68 complex: { 69 source: "<h1>{header}</h1>\n" + 70 "{?items}\n" + 71 " <ul>\n" + 72 " {#items}\n" + 73 " {#current}\n" + 74 " <li><strong>{name}</strong></li>\n" + 75 " {:else}\n" + 76 " <li><a href=\"{url}\">{name}</a></li>\n" + 77 " {/current}\n" + 78 " {/items}\n" + 79 " </ul>\n" + 80 "{:else}\n" + 81 " <p>The list is empty.</p>\n" + 82 "{/items}", 83 context: { 84 header: function() { 85 return "Colors"; 86 }, 87 items: [ 88 {name: "red", current: true, url: "#Red"}, 89 {name: "green", current: false, url: "#Green"}, 90 {name: "blue", current: false, url: "#Blue"} 91 ] 92 } 93 } 94 95} 96 97exports.dustBench = function(suite, name, id) { 98 var bench = benches[name], 99 ctx = bench.context; 100 101 dust.loadSource(dust.compile(bench.source, name)); 102 suite.bench(id || name, function(next) { 103 dust.render(name, ctx, function() { 104 next(); 105 }); 106 }); 107}; 108 109exports.dustBench.benches = benches; 110 111})(typeof exports !== "undefined" ? exports : window);