Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
13 лет назад
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. require('./helper');
  2. var renderHelper = require('./render-helper');
  3. var tests = renderHelper.getTests();
  4. describe('Mustache.render', function () {
  5. beforeEach(function () {
  6. Mustache.clearCache();
  7. });
  8. it('requires template to be a string', function () {
  9. assert.throws(function () {
  10. Mustache.render(['dummy template'], ['foo', 'bar']);
  11. }, TypeError, 'Invalid template! Template should be a "string" but ' +
  12. '"array" was given as the first argument ' +
  13. 'for mustache#render(template, view, partials)');
  14. });
  15. describe('custom tags', function () {
  16. it('uses tags argument instead of Mustache.tags when given', function () {
  17. var template = '<<placeholder>>bar{{placeholder}}';
  18. Mustache.tags = ['{{', '}}'];
  19. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']), 'foobar{{placeholder}}');
  20. });
  21. it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using Mustache.tags', function () {
  22. var template = '((placeholder))bar{{placeholder}}';
  23. Mustache.tags = ['{{', '}}'];
  24. Mustache.render(template, { placeholder: 'foo' });
  25. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['((', '))']), 'foobar{{placeholder}}');
  26. });
  27. it('uses tags argument instead of Mustache.tags when given, even when it previous rendered the template using different tags', function () {
  28. var template = '[[placeholder]]bar<<placeholder>>';
  29. Mustache.render(template, { placeholder: 'foo' }, {}, ['<<', '>>']);
  30. assert.equal(Mustache.render(template, { placeholder: 'foo' }, {}, ['[[', ']]']), 'foobar<<placeholder>>');
  31. });
  32. it('does not mutate Mustache.tags when given tags argument', function () {
  33. var correctMustacheTags = ['{{', '}}'];
  34. Mustache.tags = correctMustacheTags;
  35. Mustache.render('((placeholder))', { placeholder: 'foo' }, {}, ['((', '))']);
  36. assert.equal(Mustache.tags, correctMustacheTags);
  37. assert.deepEqual(Mustache.tags, ['{{', '}}']);
  38. });
  39. it('uses provided tags when rendering partials', function () {
  40. var output = Mustache.render('<%> partial %>', { name: 'Santa Claus' }, {
  41. partial: '<% name %>'
  42. }, ['<%', '%>']);
  43. assert.equal(output, 'Santa Claus');
  44. });
  45. });
  46. tests.forEach(function (test) {
  47. var view = eval(test.view);
  48. it('knows how to render ' + test.name, function () {
  49. var output;
  50. if (test.partial) {
  51. output = Mustache.render(test.template, view, { partial: test.partial });
  52. } else {
  53. output = Mustache.render(test.template, view);
  54. }
  55. output.should.equal(test.expect);
  56. });
  57. });
  58. });