Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

12345678910111213141516171819202122232425262728293031323334
  1. var tmpl = "This is the story of guys who work on a project\n" +
  2. "called {{project}}. Their names were {{#people}}{{firstName}} and {{/people}}\n" +
  3. "they both enjoyed working on {{project}}.\n\n" +
  4. "{{#people}}\n" +
  5. "{{>personPet}}\n" +
  6. "{{/people}}";
  7. var partials = {
  8. personPet: "{{firstName}} {{lastName}} {{#pet}} owned a {{species}}. Its name was {{name}}.{{/pet}}{{^pet}}didn't own a pet.{{/pet}}"
  9. };
  10. var data = {
  11. project: "Handlebars",
  12. people: [
  13. { firstName: "Yehuda", lastName: "Katz" },
  14. { firstName: "Alan", lastName: "Johnson", pet: { species: "cat", name: "Luke" } }
  15. ]
  16. }
  17. $(function() {
  18. var bench = new Benchmark('to_html', function() {
  19. Mustache.to_html(tmpl, data, partials);
  20. });
  21. bench.run();
  22. $('<div>' + bench.toString() + '</div>').appendTo(document.body);
  23. var bench = new Benchmark('compiled', function() {
  24. this.compiled_tmpl(data);
  25. }, {
  26. onStart: function() {
  27. this.compiled_tmpl = Mustache.compile(tmpl, partials);
  28. }
  29. });
  30. bench.run();
  31. $('<div>' + bench.toString() + '</div>').appendTo(document.body);
  32. });