You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

768 line
23KB

  1. /*!
  2. * mustache.js - Logic-less {{mustache}} templates with JavaScript
  3. * http://github.com/janl/mustache.js
  4. */
  5. var objectToString = Object.prototype.toString;
  6. var isArray = Array.isArray || function isArrayPolyfill (object) {
  7. return objectToString.call(object) === '[object Array]';
  8. };
  9. function isFunction (object) {
  10. return typeof object === 'function';
  11. }
  12. /**
  13. * More correct typeof string handling array
  14. * which normally returns typeof 'object'
  15. */
  16. function typeStr (obj) {
  17. return isArray(obj) ? 'array' : typeof obj;
  18. }
  19. function escapeRegExp (string) {
  20. return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
  21. }
  22. /**
  23. * Null safe way of checking whether or not an object,
  24. * including its prototype, has a given property
  25. */
  26. function hasProperty (obj, propName) {
  27. return obj != null && typeof obj === 'object' && (propName in obj);
  28. }
  29. /**
  30. * Safe way of detecting whether or not the given thing is a primitive and
  31. * whether it has the given property
  32. */
  33. function primitiveHasOwnProperty (primitive, propName) {
  34. return (
  35. primitive != null
  36. && typeof primitive !== 'object'
  37. && primitive.hasOwnProperty
  38. && primitive.hasOwnProperty(propName)
  39. );
  40. }
  41. // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
  42. // See https://github.com/janl/mustache.js/issues/189
  43. var regExpTest = RegExp.prototype.test;
  44. function testRegExp (re, string) {
  45. return regExpTest.call(re, string);
  46. }
  47. var nonSpaceRe = /\S/;
  48. function isWhitespace (string) {
  49. return !testRegExp(nonSpaceRe, string);
  50. }
  51. var entityMap = {
  52. '&': '&',
  53. '<': '&lt;',
  54. '>': '&gt;',
  55. '"': '&quot;',
  56. "'": '&#39;',
  57. '/': '&#x2F;',
  58. '`': '&#x60;',
  59. '=': '&#x3D;'
  60. };
  61. function escapeHtml (string) {
  62. return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
  63. return entityMap[s];
  64. });
  65. }
  66. var whiteRe = /\s*/;
  67. var spaceRe = /\s+/;
  68. var equalsRe = /\s*=/;
  69. var curlyRe = /\s*\}/;
  70. var tagRe = /#|\^|\/|>|\{|&|=|!/;
  71. /**
  72. * Breaks up the given `template` string into a tree of tokens. If the `tags`
  73. * argument is given here it must be an array with two string values: the
  74. * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
  75. * course, the default is to use mustaches (i.e. mustache.tags).
  76. *
  77. * A token is an array with at least 4 elements. The first element is the
  78. * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
  79. * did not contain a symbol (i.e. {{myValue}}) this element is "name". For
  80. * all text that appears outside a symbol this element is "text".
  81. *
  82. * The second element of a token is its "value". For mustache tags this is
  83. * whatever else was inside the tag besides the opening symbol. For text tokens
  84. * this is the text itself.
  85. *
  86. * The third and fourth elements of the token are the start and end indices,
  87. * respectively, of the token in the original template.
  88. *
  89. * Tokens that are the root node of a subtree contain two more elements: 1) an
  90. * array of tokens in the subtree and 2) the index in the original template at
  91. * which the closing tag for that section begins.
  92. *
  93. * Tokens for partials also contain two more elements: 1) a string value of
  94. * indendation prior to that tag and 2) the index of that tag on that line -
  95. * eg a value of 2 indicates the partial is the third tag on this line.
  96. */
  97. function parseTemplate (template, tags) {
  98. if (!template)
  99. return [];
  100. var lineHasNonSpace = false;
  101. var sections = []; // Stack to hold section tokens
  102. var tokens = []; // Buffer to hold the tokens
  103. var spaces = []; // Indices of whitespace tokens on the current line
  104. var hasTag = false; // Is there a {{tag}} on the current line?
  105. var nonSpace = false; // Is there a non-space char on the current line?
  106. var indentation = ''; // Tracks indentation for tags that use it
  107. var tagIndex = 0; // Stores a count of number of tags encountered on a line
  108. // Strips all whitespace tokens array for the current line
  109. // if there was a {{#tag}} on it and otherwise only space.
  110. function stripSpace () {
  111. if (hasTag && !nonSpace) {
  112. while (spaces.length)
  113. delete tokens[spaces.pop()];
  114. } else {
  115. spaces = [];
  116. }
  117. hasTag = false;
  118. nonSpace = false;
  119. }
  120. var openingTagRe, closingTagRe, closingCurlyRe;
  121. function compileTags (tagsToCompile) {
  122. if (typeof tagsToCompile === 'string')
  123. tagsToCompile = tagsToCompile.split(spaceRe, 2);
  124. if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
  125. throw new Error('Invalid tags: ' + tagsToCompile);
  126. openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
  127. closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
  128. closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
  129. }
  130. compileTags(tags || mustache.tags);
  131. var scanner = new Scanner(template);
  132. var start, type, value, chr, token, openSection;
  133. while (!scanner.eos()) {
  134. start = scanner.pos;
  135. // Match any text between tags.
  136. value = scanner.scanUntil(openingTagRe);
  137. if (value) {
  138. for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
  139. chr = value.charAt(i);
  140. if (isWhitespace(chr)) {
  141. spaces.push(tokens.length);
  142. indentation += chr;
  143. } else {
  144. nonSpace = true;
  145. lineHasNonSpace = true;
  146. indentation += ' ';
  147. }
  148. tokens.push([ 'text', chr, start, start + 1 ]);
  149. start += 1;
  150. // Check for whitespace on the current line.
  151. if (chr === '\n') {
  152. stripSpace();
  153. indentation = '';
  154. tagIndex = 0;
  155. lineHasNonSpace = false;
  156. }
  157. }
  158. }
  159. // Match the opening tag.
  160. if (!scanner.scan(openingTagRe))
  161. break;
  162. hasTag = true;
  163. // Get the tag type.
  164. type = scanner.scan(tagRe) || 'name';
  165. scanner.scan(whiteRe);
  166. // Get the tag value.
  167. if (type === '=') {
  168. value = scanner.scanUntil(equalsRe);
  169. scanner.scan(equalsRe);
  170. scanner.scanUntil(closingTagRe);
  171. } else if (type === '{') {
  172. value = scanner.scanUntil(closingCurlyRe);
  173. scanner.scan(curlyRe);
  174. scanner.scanUntil(closingTagRe);
  175. type = '&';
  176. } else {
  177. value = scanner.scanUntil(closingTagRe);
  178. }
  179. // Match the closing tag.
  180. if (!scanner.scan(closingTagRe))
  181. throw new Error('Unclosed tag at ' + scanner.pos);
  182. if (type == '>') {
  183. token = [ type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace ];
  184. } else {
  185. token = [ type, value, start, scanner.pos ];
  186. }
  187. tagIndex++;
  188. tokens.push(token);
  189. if (type === '#' || type === '^') {
  190. sections.push(token);
  191. } else if (type === '/') {
  192. // Check section nesting.
  193. openSection = sections.pop();
  194. if (!openSection)
  195. throw new Error('Unopened section "' + value + '" at ' + start);
  196. if (openSection[1] !== value)
  197. throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
  198. } else if (type === 'name' || type === '{' || type === '&') {
  199. nonSpace = true;
  200. } else if (type === '=') {
  201. // Set the tags for the next time around.
  202. compileTags(value);
  203. }
  204. }
  205. stripSpace();
  206. // Make sure there are no open sections when we're done.
  207. openSection = sections.pop();
  208. if (openSection)
  209. throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
  210. return nestTokens(squashTokens(tokens));
  211. }
  212. /**
  213. * Combines the values of consecutive text tokens in the given `tokens` array
  214. * to a single token.
  215. */
  216. function squashTokens (tokens) {
  217. var squashedTokens = [];
  218. var token, lastToken;
  219. for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
  220. token = tokens[i];
  221. if (token) {
  222. if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
  223. lastToken[1] += token[1];
  224. lastToken[3] = token[3];
  225. } else {
  226. squashedTokens.push(token);
  227. lastToken = token;
  228. }
  229. }
  230. }
  231. return squashedTokens;
  232. }
  233. /**
  234. * Forms the given array of `tokens` into a nested tree structure where
  235. * tokens that represent a section have two additional items: 1) an array of
  236. * all tokens that appear in that section and 2) the index in the original
  237. * template that represents the end of that section.
  238. */
  239. function nestTokens (tokens) {
  240. var nestedTokens = [];
  241. var collector = nestedTokens;
  242. var sections = [];
  243. var token, section;
  244. for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
  245. token = tokens[i];
  246. switch (token[0]) {
  247. case '#':
  248. case '^':
  249. collector.push(token);
  250. sections.push(token);
  251. collector = token[4] = [];
  252. break;
  253. case '/':
  254. section = sections.pop();
  255. section[5] = token[2];
  256. collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
  257. break;
  258. default:
  259. collector.push(token);
  260. }
  261. }
  262. return nestedTokens;
  263. }
  264. /**
  265. * A simple string scanner that is used by the template parser to find
  266. * tokens in template strings.
  267. */
  268. function Scanner (string) {
  269. this.string = string;
  270. this.tail = string;
  271. this.pos = 0;
  272. }
  273. /**
  274. * Returns `true` if the tail is empty (end of string).
  275. */
  276. Scanner.prototype.eos = function eos () {
  277. return this.tail === '';
  278. };
  279. /**
  280. * Tries to match the given regular expression at the current position.
  281. * Returns the matched text if it can match, the empty string otherwise.
  282. */
  283. Scanner.prototype.scan = function scan (re) {
  284. var match = this.tail.match(re);
  285. if (!match || match.index !== 0)
  286. return '';
  287. var string = match[0];
  288. this.tail = this.tail.substring(string.length);
  289. this.pos += string.length;
  290. return string;
  291. };
  292. /**
  293. * Skips all text until the given regular expression can be matched. Returns
  294. * the skipped string, which is the entire tail if no match can be made.
  295. */
  296. Scanner.prototype.scanUntil = function scanUntil (re) {
  297. var index = this.tail.search(re), match;
  298. switch (index) {
  299. case -1:
  300. match = this.tail;
  301. this.tail = '';
  302. break;
  303. case 0:
  304. match = '';
  305. break;
  306. default:
  307. match = this.tail.substring(0, index);
  308. this.tail = this.tail.substring(index);
  309. }
  310. this.pos += match.length;
  311. return match;
  312. };
  313. /**
  314. * Represents a rendering context by wrapping a view object and
  315. * maintaining a reference to the parent context.
  316. */
  317. function Context (view, parentContext) {
  318. this.view = view;
  319. this.cache = { '.': this.view };
  320. this.parent = parentContext;
  321. }
  322. /**
  323. * Creates a new context using the given view with this context
  324. * as the parent.
  325. */
  326. Context.prototype.push = function push (view) {
  327. return new Context(view, this);
  328. };
  329. /**
  330. * Returns the value of the given name in this context, traversing
  331. * up the context hierarchy if the value is absent in this context's view.
  332. */
  333. Context.prototype.lookup = function lookup (name) {
  334. var cache = this.cache;
  335. var value;
  336. if (cache.hasOwnProperty(name)) {
  337. value = cache[name];
  338. } else if (name.includes('.') && cache['.'] && cache['.'].hasOwnProperty(name)) {
  339. value = cache['.'][name];
  340. }
  341. else {
  342. var context = this, intermediateValue, names, index, lookupHit = false;
  343. while (context) {
  344. if (name.indexOf('.') > 0) {
  345. intermediateValue = context.view;
  346. names = name.split('.');
  347. index = 0;
  348. /**
  349. * Using the dot notion path in `name`, we descend through the
  350. * nested objects.
  351. *
  352. * To be certain that the lookup has been successful, we have to
  353. * check if the last object in the path actually has the property
  354. * we are looking for. We store the result in `lookupHit`.
  355. *
  356. * This is specially necessary for when the value has been set to
  357. * `undefined` and we want to avoid looking up parent contexts.
  358. *
  359. * In the case where dot notation is used, we consider the lookup
  360. * to be successful even if the last "object" in the path is
  361. * not actually an object but a primitive (e.g., a string, or an
  362. * integer), because it is sometimes useful to access a property
  363. * of an autoboxed primitive, such as the length of a string.
  364. **/
  365. while (intermediateValue != null && index < names.length) {
  366. if (index === names.length - 1)
  367. lookupHit = (
  368. hasProperty(intermediateValue, names[index])
  369. || primitiveHasOwnProperty(intermediateValue, names[index])
  370. );
  371. intermediateValue = intermediateValue[names[index++]];
  372. }
  373. } else {
  374. intermediateValue = context.view[name];
  375. /**
  376. * Only checking against `hasProperty`, which always returns `false` if
  377. * `context.view` is not an object. Deliberately omitting the check
  378. * against `primitiveHasOwnProperty` if dot notation is not used.
  379. *
  380. * Consider this example:
  381. * ```
  382. * Mustache.render("The length of a football field is {{#length}}{{length}}{{/length}}.", {length: "100 yards"})
  383. * ```
  384. *
  385. * If we were to check also against `primitiveHasOwnProperty`, as we do
  386. * in the dot notation case, then render call would return:
  387. *
  388. * "The length of a football field is 9."
  389. *
  390. * rather than the expected:
  391. *
  392. * "The length of a football field is 100 yards."
  393. **/
  394. lookupHit = hasProperty(context.view, name);
  395. }
  396. if (lookupHit) {
  397. value = intermediateValue;
  398. break;
  399. }
  400. context = context.parent;
  401. }
  402. cache[name] = value;
  403. }
  404. if (isFunction(value))
  405. value = value.call(this.view);
  406. return value;
  407. };
  408. /**
  409. * A Writer knows how to take a stream of tokens and render them to a
  410. * string, given a context. It also maintains a cache of templates to
  411. * avoid the need to parse the same template twice.
  412. */
  413. function Writer () {
  414. this.templateCache = {
  415. _cache: {},
  416. set: function set (key, value) {
  417. this._cache[key] = value;
  418. },
  419. get: function get (key) {
  420. return this._cache[key];
  421. },
  422. clear: function clear () {
  423. this._cache = {};
  424. }
  425. };
  426. }
  427. /**
  428. * Clears all cached templates in this writer.
  429. */
  430. Writer.prototype.clearCache = function clearCache () {
  431. if (typeof this.templateCache !== 'undefined') {
  432. this.templateCache.clear();
  433. }
  434. };
  435. /**
  436. * Parses and caches the given `template` according to the given `tags` or
  437. * `mustache.tags` if `tags` is omitted, and returns the array of tokens
  438. * that is generated from the parse.
  439. */
  440. Writer.prototype.parse = function parse (template, tags) {
  441. var cache = this.templateCache;
  442. var cacheKey = template + ':' + (tags || mustache.tags).join(':');
  443. var isCacheEnabled = typeof cache !== 'undefined';
  444. var tokens = isCacheEnabled ? cache.get(cacheKey) : undefined;
  445. if (tokens == undefined) {
  446. tokens = parseTemplate(template, tags);
  447. isCacheEnabled && cache.set(cacheKey, tokens);
  448. }
  449. return tokens;
  450. };
  451. /**
  452. * High-level method that is used to render the given `template` with
  453. * the given `view`.
  454. *
  455. * The optional `partials` argument may be an object that contains the
  456. * names and templates of partials that are used in the template. It may
  457. * also be a function that is used to load partial templates on the fly
  458. * that takes a single argument: the name of the partial.
  459. *
  460. * If the optional `config` argument is given here, then it should be an
  461. * object with a `tags` attribute or an `escape` attribute or both.
  462. * If an array is passed, then it will be interpreted the same way as
  463. * a `tags` attribute on a `config` object.
  464. *
  465. * The `tags` attribute of a `config` object must be an array with two
  466. * string values: the opening and closing tags used in the template (e.g.
  467. * [ "<%", "%>" ]). The default is to mustache.tags.
  468. *
  469. * The `escape` attribute of a `config` object must be a function which
  470. * accepts a string as input and outputs a safely escaped string.
  471. * If an `escape` function is not provided, then an HTML-safe string
  472. * escaping function is used as the default.
  473. */
  474. Writer.prototype.render = function render (template, view, partials, config) {
  475. var tags = this.getConfigTags(config);
  476. var tokens = this.parse(template, tags);
  477. var context = (view instanceof Context) ? view : new Context(view, undefined);
  478. return this.renderTokens(tokens, context, partials, template, config);
  479. };
  480. /**
  481. * Low-level method that renders the given array of `tokens` using
  482. * the given `context` and `partials`.
  483. *
  484. * Note: The `originalTemplate` is only ever used to extract the portion
  485. * of the original template that was contained in a higher-order section.
  486. * If the template doesn't use higher-order sections, this argument may
  487. * be omitted.
  488. */
  489. Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate, config) {
  490. var buffer = '';
  491. var token, symbol, value;
  492. for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
  493. value = undefined;
  494. token = tokens[i];
  495. symbol = token[0];
  496. if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate, config);
  497. else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate, config);
  498. else if (symbol === '>') value = this.renderPartial(token, context, partials, config);
  499. else if (symbol === '&') value = this.unescapedValue(token, context);
  500. else if (symbol === 'name') value = this.escapedValue(token, context, config);
  501. else if (symbol === 'text') value = this.rawValue(token);
  502. if (value !== undefined)
  503. buffer += value;
  504. }
  505. return buffer;
  506. };
  507. Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate, config) {
  508. var self = this;
  509. var buffer = '';
  510. var value = context.lookup(token[1]);
  511. // This function is used to render an arbitrary template
  512. // in the current context by higher-order sections.
  513. function subRender (template) {
  514. return self.render(template, context, partials, config);
  515. }
  516. if (!value) return;
  517. if (isArray(value)) {
  518. for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
  519. buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate, config);
  520. }
  521. } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
  522. buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate, config);
  523. } else if (isFunction(value)) {
  524. if (typeof originalTemplate !== 'string')
  525. throw new Error('Cannot use higher-order sections without the original template');
  526. // Extract the portion of the original template that the section contains.
  527. value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
  528. if (value != null)
  529. buffer += value;
  530. } else {
  531. buffer += this.renderTokens(token[4], context, partials, originalTemplate, config);
  532. }
  533. return buffer;
  534. };
  535. Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate, config) {
  536. var value = context.lookup(token[1]);
  537. // Use JavaScript's definition of falsy. Include empty arrays.
  538. // See https://github.com/janl/mustache.js/issues/186
  539. if (!value || (isArray(value) && value.length === 0))
  540. return this.renderTokens(token[4], context, partials, originalTemplate, config);
  541. };
  542. Writer.prototype.indentPartial = function indentPartial (partial, indentation, lineHasNonSpace) {
  543. var filteredIndentation = indentation.replace(/[^ \t]/g, '');
  544. var partialByNl = partial.split('\n');
  545. for (var i = 0; i < partialByNl.length; i++) {
  546. if (partialByNl[i].length && (i > 0 || !lineHasNonSpace)) {
  547. partialByNl[i] = filteredIndentation + partialByNl[i];
  548. }
  549. }
  550. return partialByNl.join('\n');
  551. };
  552. Writer.prototype.renderPartial = function renderPartial (token, context, partials, config) {
  553. if (!partials) return;
  554. var tags = this.getConfigTags(config);
  555. var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
  556. if (value != null) {
  557. var lineHasNonSpace = token[6];
  558. var tagIndex = token[5];
  559. var indentation = token[4];
  560. var indentedValue = value;
  561. if (tagIndex == 0 && indentation) {
  562. indentedValue = this.indentPartial(value, indentation, lineHasNonSpace);
  563. }
  564. var tokens = this.parse(indentedValue, tags);
  565. return this.renderTokens(tokens, context, partials, indentedValue, config);
  566. }
  567. };
  568. Writer.prototype.unescapedValue = function unescapedValue (token, context) {
  569. var value = context.lookup(token[1]);
  570. if (value != null)
  571. return value;
  572. };
  573. Writer.prototype.escapedValue = function escapedValue (token, context, config) {
  574. var escape = this.getConfigEscape(config) || mustache.escape;
  575. var value = context.lookup(token[1]);
  576. if (value != null)
  577. return (typeof value === 'number' && escape === mustache.escape) ? String(value) : escape(value);
  578. };
  579. Writer.prototype.rawValue = function rawValue (token) {
  580. return token[1];
  581. };
  582. Writer.prototype.getConfigTags = function getConfigTags (config) {
  583. if (isArray(config)) {
  584. return config;
  585. }
  586. else if (config && typeof config === 'object') {
  587. return config.tags;
  588. }
  589. else {
  590. return undefined;
  591. }
  592. };
  593. Writer.prototype.getConfigEscape = function getConfigEscape (config) {
  594. if (config && typeof config === 'object' && !isArray(config)) {
  595. return config.escape;
  596. }
  597. else {
  598. return undefined;
  599. }
  600. };
  601. var mustache = {
  602. name: 'mustache.js',
  603. version: '4.2.0',
  604. tags: [ '{{', '}}' ],
  605. clearCache: undefined,
  606. escape: undefined,
  607. parse: undefined,
  608. render: undefined,
  609. Scanner: undefined,
  610. Context: undefined,
  611. Writer: undefined,
  612. /**
  613. * Allows a user to override the default caching strategy, by providing an
  614. * object with set, get and clear methods. This can also be used to disable
  615. * the cache by setting it to the literal `undefined`.
  616. */
  617. set templateCache (cache) {
  618. defaultWriter.templateCache = cache;
  619. },
  620. /**
  621. * Gets the default or overridden caching object from the default writer.
  622. */
  623. get templateCache () {
  624. return defaultWriter.templateCache;
  625. }
  626. };
  627. // All high-level mustache.* functions use this writer.
  628. var defaultWriter = new Writer();
  629. /**
  630. * Clears all cached templates in the default writer.
  631. */
  632. mustache.clearCache = function clearCache () {
  633. return defaultWriter.clearCache();
  634. };
  635. /**
  636. * Parses and caches the given template in the default writer and returns the
  637. * array of tokens it contains. Doing this ahead of time avoids the need to
  638. * parse templates on the fly as they are rendered.
  639. */
  640. mustache.parse = function parse (template, tags) {
  641. return defaultWriter.parse(template, tags);
  642. };
  643. /**
  644. * Renders the `template` with the given `view`, `partials`, and `config`
  645. * using the default writer.
  646. */
  647. mustache.render = function render (template, view, partials, config) {
  648. if (typeof template !== 'string') {
  649. throw new TypeError('Invalid template! Template should be a "string" ' +
  650. 'but "' + typeStr(template) + '" was given as the first ' +
  651. 'argument for mustache#render(template, view, partials)');
  652. }
  653. return defaultWriter.render(template, view, partials, config);
  654. };
  655. // Export the escaping function so that the user may override it.
  656. // See https://github.com/janl/mustache.js/issues/244
  657. mustache.escape = escapeHtml;
  658. // Export these mainly for testing, but also for advanced usage.
  659. mustache.Scanner = Scanner;
  660. mustache.Context = Context;
  661. mustache.Writer = Writer;
  662. export default mustache;