bundle-hbs.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. exports.__esModule = true;
  4. // istanbul ignore next
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  6. // istanbul ignore next
  7. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  8. var _handlebarsBase = require('./handlebars/base');
  9. var base = _interopRequireWildcard(_handlebarsBase);
  10. // Each of these augment the Handlebars object. No need to setup here.
  11. // (This is done to easily share code between commonjs and browse envs)
  12. var _handlebarsSafeString = require('./handlebars/safe-string');
  13. var _handlebarsSafeString2 = _interopRequireDefault(_handlebarsSafeString);
  14. var _handlebarsException = require('./handlebars/exception');
  15. var _handlebarsException2 = _interopRequireDefault(_handlebarsException);
  16. var _handlebarsUtils = require('./handlebars/utils');
  17. var Utils = _interopRequireWildcard(_handlebarsUtils);
  18. var _handlebarsRuntime = require('./handlebars/runtime');
  19. var runtime = _interopRequireWildcard(_handlebarsRuntime);
  20. var _handlebarsNoConflict = require('./handlebars/no-conflict');
  21. var _handlebarsNoConflict2 = _interopRequireDefault(_handlebarsNoConflict);
  22. // For compatibility and usage outside of module systems, make the Handlebars object a namespace
  23. function create() {
  24. var hb = new base.HandlebarsEnvironment();
  25. Utils.extend(hb, base);
  26. hb.SafeString = _handlebarsSafeString2['default'];
  27. hb.Exception = _handlebarsException2['default'];
  28. hb.Utils = Utils;
  29. hb.escapeExpression = Utils.escapeExpression;
  30. hb.VM = runtime;
  31. hb.template = function (spec) {
  32. return runtime.template(spec, hb);
  33. };
  34. return hb;
  35. }
  36. var inst = create();
  37. inst.create = create;
  38. _handlebarsNoConflict2['default'](inst);
  39. inst['default'] = inst;
  40. exports['default'] = inst;
  41. module.exports = exports['default'];
  42. },{"./handlebars/base":2,"./handlebars/exception":5,"./handlebars/no-conflict":15,"./handlebars/runtime":16,"./handlebars/safe-string":17,"./handlebars/utils":18}],2:[function(require,module,exports){
  43. 'use strict';
  44. exports.__esModule = true;
  45. exports.HandlebarsEnvironment = HandlebarsEnvironment;
  46. // istanbul ignore next
  47. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  48. var _utils = require('./utils');
  49. var _exception = require('./exception');
  50. var _exception2 = _interopRequireDefault(_exception);
  51. var _helpers = require('./helpers');
  52. var _decorators = require('./decorators');
  53. var _logger = require('./logger');
  54. var _logger2 = _interopRequireDefault(_logger);
  55. var VERSION = '4.0.5';
  56. exports.VERSION = VERSION;
  57. var COMPILER_REVISION = 7;
  58. exports.COMPILER_REVISION = COMPILER_REVISION;
  59. var REVISION_CHANGES = {
  60. 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
  61. 2: '== 1.0.0-rc.3',
  62. 3: '== 1.0.0-rc.4',
  63. 4: '== 1.x.x',
  64. 5: '== 2.0.0-alpha.x',
  65. 6: '>= 2.0.0-beta.1',
  66. 7: '>= 4.0.0'
  67. };
  68. exports.REVISION_CHANGES = REVISION_CHANGES;
  69. var objectType = '[object Object]';
  70. function HandlebarsEnvironment(helpers, partials, decorators) {
  71. this.helpers = helpers || {};
  72. this.partials = partials || {};
  73. this.decorators = decorators || {};
  74. _helpers.registerDefaultHelpers(this);
  75. _decorators.registerDefaultDecorators(this);
  76. }
  77. HandlebarsEnvironment.prototype = {
  78. constructor: HandlebarsEnvironment,
  79. logger: _logger2['default'],
  80. log: _logger2['default'].log,
  81. registerHelper: function registerHelper(name, fn) {
  82. if (_utils.toString.call(name) === objectType) {
  83. if (fn) {
  84. throw new _exception2['default']('Arg not supported with multiple helpers');
  85. }
  86. _utils.extend(this.helpers, name);
  87. } else {
  88. this.helpers[name] = fn;
  89. }
  90. },
  91. unregisterHelper: function unregisterHelper(name) {
  92. delete this.helpers[name];
  93. },
  94. registerPartial: function registerPartial(name, partial) {
  95. if (_utils.toString.call(name) === objectType) {
  96. _utils.extend(this.partials, name);
  97. } else {
  98. if (typeof partial === 'undefined') {
  99. throw new _exception2['default']('Attempting to register a partial called "' + name + '" as undefined');
  100. }
  101. this.partials[name] = partial;
  102. }
  103. },
  104. unregisterPartial: function unregisterPartial(name) {
  105. delete this.partials[name];
  106. },
  107. registerDecorator: function registerDecorator(name, fn) {
  108. if (_utils.toString.call(name) === objectType) {
  109. if (fn) {
  110. throw new _exception2['default']('Arg not supported with multiple decorators');
  111. }
  112. _utils.extend(this.decorators, name);
  113. } else {
  114. this.decorators[name] = fn;
  115. }
  116. },
  117. unregisterDecorator: function unregisterDecorator(name) {
  118. delete this.decorators[name];
  119. }
  120. };
  121. var log = _logger2['default'].log;
  122. exports.log = log;
  123. exports.createFrame = _utils.createFrame;
  124. exports.logger = _logger2['default'];
  125. },{"./decorators":3,"./exception":5,"./helpers":6,"./logger":14,"./utils":18}],3:[function(require,module,exports){
  126. 'use strict';
  127. exports.__esModule = true;
  128. exports.registerDefaultDecorators = registerDefaultDecorators;
  129. // istanbul ignore next
  130. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  131. var _decoratorsInline = require('./decorators/inline');
  132. var _decoratorsInline2 = _interopRequireDefault(_decoratorsInline);
  133. function registerDefaultDecorators(instance) {
  134. _decoratorsInline2['default'](instance);
  135. }
  136. },{"./decorators/inline":4}],4:[function(require,module,exports){
  137. 'use strict';
  138. exports.__esModule = true;
  139. var _utils = require('../utils');
  140. exports['default'] = function (instance) {
  141. instance.registerDecorator('inline', function (fn, props, container, options) {
  142. var ret = fn;
  143. if (!props.partials) {
  144. props.partials = {};
  145. ret = function (context, options) {
  146. // Create a new partials stack frame prior to exec.
  147. var original = container.partials;
  148. container.partials = _utils.extend({}, original, props.partials);
  149. var ret = fn(context, options);
  150. container.partials = original;
  151. return ret;
  152. };
  153. }
  154. props.partials[options.args[0]] = options.fn;
  155. return ret;
  156. });
  157. };
  158. module.exports = exports['default'];
  159. },{"../utils":18}],5:[function(require,module,exports){
  160. 'use strict';
  161. exports.__esModule = true;
  162. var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
  163. function Exception(message, node) {
  164. var loc = node && node.loc,
  165. line = undefined,
  166. column = undefined;
  167. if (loc) {
  168. line = loc.start.line;
  169. column = loc.start.column;
  170. message += ' - ' + line + ':' + column;
  171. }
  172. var tmp = Error.prototype.constructor.call(this, message);
  173. // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
  174. for (var idx = 0; idx < errorProps.length; idx++) {
  175. this[errorProps[idx]] = tmp[errorProps[idx]];
  176. }
  177. /* istanbul ignore else */
  178. if (Error.captureStackTrace) {
  179. Error.captureStackTrace(this, Exception);
  180. }
  181. if (loc) {
  182. this.lineNumber = line;
  183. this.column = column;
  184. }
  185. }
  186. Exception.prototype = new Error();
  187. exports['default'] = Exception;
  188. module.exports = exports['default'];
  189. },{}],6:[function(require,module,exports){
  190. 'use strict';
  191. exports.__esModule = true;
  192. exports.registerDefaultHelpers = registerDefaultHelpers;
  193. // istanbul ignore next
  194. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  195. var _helpersBlockHelperMissing = require('./helpers/block-helper-missing');
  196. var _helpersBlockHelperMissing2 = _interopRequireDefault(_helpersBlockHelperMissing);
  197. var _helpersEach = require('./helpers/each');
  198. var _helpersEach2 = _interopRequireDefault(_helpersEach);
  199. var _helpersHelperMissing = require('./helpers/helper-missing');
  200. var _helpersHelperMissing2 = _interopRequireDefault(_helpersHelperMissing);
  201. var _helpersIf = require('./helpers/if');
  202. var _helpersIf2 = _interopRequireDefault(_helpersIf);
  203. var _helpersLog = require('./helpers/log');
  204. var _helpersLog2 = _interopRequireDefault(_helpersLog);
  205. var _helpersLookup = require('./helpers/lookup');
  206. var _helpersLookup2 = _interopRequireDefault(_helpersLookup);
  207. var _helpersWith = require('./helpers/with');
  208. var _helpersWith2 = _interopRequireDefault(_helpersWith);
  209. function registerDefaultHelpers(instance) {
  210. _helpersBlockHelperMissing2['default'](instance);
  211. _helpersEach2['default'](instance);
  212. _helpersHelperMissing2['default'](instance);
  213. _helpersIf2['default'](instance);
  214. _helpersLog2['default'](instance);
  215. _helpersLookup2['default'](instance);
  216. _helpersWith2['default'](instance);
  217. }
  218. },{"./helpers/block-helper-missing":7,"./helpers/each":8,"./helpers/helper-missing":9,"./helpers/if":10,"./helpers/log":11,"./helpers/lookup":12,"./helpers/with":13}],7:[function(require,module,exports){
  219. 'use strict';
  220. exports.__esModule = true;
  221. var _utils = require('../utils');
  222. exports['default'] = function (instance) {
  223. instance.registerHelper('blockHelperMissing', function (context, options) {
  224. var inverse = options.inverse,
  225. fn = options.fn;
  226. if (context === true) {
  227. return fn(this);
  228. } else if (context === false || context == null) {
  229. return inverse(this);
  230. } else if (_utils.isArray(context)) {
  231. if (context.length > 0) {
  232. if (options.ids) {
  233. options.ids = [options.name];
  234. }
  235. return instance.helpers.each(context, options);
  236. } else {
  237. return inverse(this);
  238. }
  239. } else {
  240. if (options.data && options.ids) {
  241. var data = _utils.createFrame(options.data);
  242. data.contextPath = _utils.appendContextPath(options.data.contextPath, options.name);
  243. options = { data: data };
  244. }
  245. return fn(context, options);
  246. }
  247. });
  248. };
  249. module.exports = exports['default'];
  250. },{"../utils":18}],8:[function(require,module,exports){
  251. 'use strict';
  252. exports.__esModule = true;
  253. // istanbul ignore next
  254. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  255. var _utils = require('../utils');
  256. var _exception = require('../exception');
  257. var _exception2 = _interopRequireDefault(_exception);
  258. exports['default'] = function (instance) {
  259. instance.registerHelper('each', function (context, options) {
  260. if (!options) {
  261. throw new _exception2['default']('Must pass iterator to #each');
  262. }
  263. var fn = options.fn,
  264. inverse = options.inverse,
  265. i = 0,
  266. ret = '',
  267. data = undefined,
  268. contextPath = undefined;
  269. if (options.data && options.ids) {
  270. contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.';
  271. }
  272. if (_utils.isFunction(context)) {
  273. context = context.call(this);
  274. }
  275. if (options.data) {
  276. data = _utils.createFrame(options.data);
  277. }
  278. function execIteration(field, index, last) {
  279. if (data) {
  280. data.key = field;
  281. data.index = index;
  282. data.first = index === 0;
  283. data.last = !!last;
  284. if (contextPath) {
  285. data.contextPath = contextPath + field;
  286. }
  287. }
  288. ret = ret + fn(context[field], {
  289. data: data,
  290. blockParams: _utils.blockParams([context[field], field], [contextPath + field, null])
  291. });
  292. }
  293. if (context && typeof context === 'object') {
  294. if (_utils.isArray(context)) {
  295. for (var j = context.length; i < j; i++) {
  296. if (i in context) {
  297. execIteration(i, i, i === context.length - 1);
  298. }
  299. }
  300. } else {
  301. var priorKey = undefined;
  302. for (var key in context) {
  303. if (context.hasOwnProperty(key)) {
  304. // We're running the iterations one step out of sync so we can detect
  305. // the last iteration without have to scan the object twice and create
  306. // an itermediate keys array.
  307. if (priorKey !== undefined) {
  308. execIteration(priorKey, i - 1);
  309. }
  310. priorKey = key;
  311. i++;
  312. }
  313. }
  314. if (priorKey !== undefined) {
  315. execIteration(priorKey, i - 1, true);
  316. }
  317. }
  318. }
  319. if (i === 0) {
  320. ret = inverse(this);
  321. }
  322. return ret;
  323. });
  324. };
  325. module.exports = exports['default'];
  326. },{"../exception":5,"../utils":18}],9:[function(require,module,exports){
  327. 'use strict';
  328. exports.__esModule = true;
  329. // istanbul ignore next
  330. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  331. var _exception = require('../exception');
  332. var _exception2 = _interopRequireDefault(_exception);
  333. exports['default'] = function (instance) {
  334. instance.registerHelper('helperMissing', function () /* [args, ]options */{
  335. if (arguments.length === 1) {
  336. // A missing field in a {{foo}} construct.
  337. return undefined;
  338. } else {
  339. // Someone is actually trying to call something, blow up.
  340. throw new _exception2['default']('Missing helper: "' + arguments[arguments.length - 1].name + '"');
  341. }
  342. });
  343. };
  344. module.exports = exports['default'];
  345. },{"../exception":5}],10:[function(require,module,exports){
  346. 'use strict';
  347. exports.__esModule = true;
  348. var _utils = require('../utils');
  349. exports['default'] = function (instance) {
  350. instance.registerHelper('if', function (conditional, options) {
  351. if (_utils.isFunction(conditional)) {
  352. conditional = conditional.call(this);
  353. }
  354. // Default behavior is to render the positive path if the value is truthy and not empty.
  355. // The `includeZero` option may be set to treat the condtional as purely not empty based on the
  356. // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
  357. if (!options.hash.includeZero && !conditional || _utils.isEmpty(conditional)) {
  358. return options.inverse(this);
  359. } else {
  360. return options.fn(this);
  361. }
  362. });
  363. instance.registerHelper('unless', function (conditional, options) {
  364. return instance.helpers['if'].call(this, conditional, { fn: options.inverse, inverse: options.fn, hash: options.hash });
  365. });
  366. };
  367. module.exports = exports['default'];
  368. },{"../utils":18}],11:[function(require,module,exports){
  369. 'use strict';
  370. exports.__esModule = true;
  371. exports['default'] = function (instance) {
  372. instance.registerHelper('log', function () /* message, options */{
  373. var args = [undefined],
  374. options = arguments[arguments.length - 1];
  375. for (var i = 0; i < arguments.length - 1; i++) {
  376. args.push(arguments[i]);
  377. }
  378. var level = 1;
  379. if (options.hash.level != null) {
  380. level = options.hash.level;
  381. } else if (options.data && options.data.level != null) {
  382. level = options.data.level;
  383. }
  384. args[0] = level;
  385. instance.log.apply(instance, args);
  386. });
  387. };
  388. module.exports = exports['default'];
  389. },{}],12:[function(require,module,exports){
  390. 'use strict';
  391. exports.__esModule = true;
  392. exports['default'] = function (instance) {
  393. instance.registerHelper('lookup', function (obj, field) {
  394. return obj && obj[field];
  395. });
  396. };
  397. module.exports = exports['default'];
  398. },{}],13:[function(require,module,exports){
  399. 'use strict';
  400. exports.__esModule = true;
  401. var _utils = require('../utils');
  402. exports['default'] = function (instance) {
  403. instance.registerHelper('with', function (context, options) {
  404. if (_utils.isFunction(context)) {
  405. context = context.call(this);
  406. }
  407. var fn = options.fn;
  408. if (!_utils.isEmpty(context)) {
  409. var data = options.data;
  410. if (options.data && options.ids) {
  411. data = _utils.createFrame(options.data);
  412. data.contextPath = _utils.appendContextPath(options.data.contextPath, options.ids[0]);
  413. }
  414. return fn(context, {
  415. data: data,
  416. blockParams: _utils.blockParams([context], [data && data.contextPath])
  417. });
  418. } else {
  419. return options.inverse(this);
  420. }
  421. });
  422. };
  423. module.exports = exports['default'];
  424. },{"../utils":18}],14:[function(require,module,exports){
  425. 'use strict';
  426. exports.__esModule = true;
  427. var _utils = require('./utils');
  428. var logger = {
  429. methodMap: ['debug', 'info', 'warn', 'error'],
  430. level: 'info',
  431. // Maps a given level value to the `methodMap` indexes above.
  432. lookupLevel: function lookupLevel(level) {
  433. if (typeof level === 'string') {
  434. var levelMap = _utils.indexOf(logger.methodMap, level.toLowerCase());
  435. if (levelMap >= 0) {
  436. level = levelMap;
  437. } else {
  438. level = parseInt(level, 10);
  439. }
  440. }
  441. return level;
  442. },
  443. // Can be overridden in the host environment
  444. log: function log(level) {
  445. level = logger.lookupLevel(level);
  446. if (typeof console !== 'undefined' && logger.lookupLevel(logger.level) <= level) {
  447. var method = logger.methodMap[level];
  448. if (!console[method]) {
  449. // eslint-disable-line no-console
  450. method = 'log';
  451. }
  452. for (var _len = arguments.length, message = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  453. message[_key - 1] = arguments[_key];
  454. }
  455. console[method].apply(console, message); // eslint-disable-line no-console
  456. }
  457. }
  458. };
  459. exports['default'] = logger;
  460. module.exports = exports['default'];
  461. },{"./utils":18}],15:[function(require,module,exports){
  462. (function (global){
  463. /* global window */
  464. 'use strict';
  465. exports.__esModule = true;
  466. exports['default'] = function (Handlebars) {
  467. /* istanbul ignore next */
  468. var root = typeof global !== 'undefined' ? global : window,
  469. $Handlebars = root.Handlebars;
  470. /* istanbul ignore next */
  471. Handlebars.noConflict = function () {
  472. if (root.Handlebars === Handlebars) {
  473. root.Handlebars = $Handlebars;
  474. }
  475. return Handlebars;
  476. };
  477. };
  478. module.exports = exports['default'];
  479. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  480. },{}],16:[function(require,module,exports){
  481. 'use strict';
  482. exports.__esModule = true;
  483. exports.checkRevision = checkRevision;
  484. exports.template = template;
  485. exports.wrapProgram = wrapProgram;
  486. exports.resolvePartial = resolvePartial;
  487. exports.invokePartial = invokePartial;
  488. exports.noop = noop;
  489. // istanbul ignore next
  490. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  491. // istanbul ignore next
  492. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
  493. var _utils = require('./utils');
  494. var Utils = _interopRequireWildcard(_utils);
  495. var _exception = require('./exception');
  496. var _exception2 = _interopRequireDefault(_exception);
  497. var _base = require('./base');
  498. function checkRevision(compilerInfo) {
  499. var compilerRevision = compilerInfo && compilerInfo[0] || 1,
  500. currentRevision = _base.COMPILER_REVISION;
  501. if (compilerRevision !== currentRevision) {
  502. if (compilerRevision < currentRevision) {
  503. var runtimeVersions = _base.REVISION_CHANGES[currentRevision],
  504. compilerVersions = _base.REVISION_CHANGES[compilerRevision];
  505. throw new _exception2['default']('Template was precompiled with an older version of Handlebars than the current runtime. ' + 'Please update your precompiler to a newer version (' + runtimeVersions + ') or downgrade your runtime to an older version (' + compilerVersions + ').');
  506. } else {
  507. // Use the embedded version info since the runtime doesn't know about this revision yet
  508. throw new _exception2['default']('Template was precompiled with a newer version of Handlebars than the current runtime. ' + 'Please update your runtime to a newer version (' + compilerInfo[1] + ').');
  509. }
  510. }
  511. }
  512. function template(templateSpec, env) {
  513. /* istanbul ignore next */
  514. if (!env) {
  515. throw new _exception2['default']('No environment passed to template');
  516. }
  517. if (!templateSpec || !templateSpec.main) {
  518. throw new _exception2['default']('Unknown template object: ' + typeof templateSpec);
  519. }
  520. templateSpec.main.decorator = templateSpec.main_d;
  521. // Note: Using env.VM references rather than local var references throughout this section to allow
  522. // for external users to override these as psuedo-supported APIs.
  523. env.VM.checkRevision(templateSpec.compiler);
  524. function invokePartialWrapper(partial, context, options) {
  525. if (options.hash) {
  526. context = Utils.extend({}, context, options.hash);
  527. if (options.ids) {
  528. options.ids[0] = true;
  529. }
  530. }
  531. partial = env.VM.resolvePartial.call(this, partial, context, options);
  532. var result = env.VM.invokePartial.call(this, partial, context, options);
  533. if (result == null && env.compile) {
  534. options.partials[options.name] = env.compile(partial, templateSpec.compilerOptions, env);
  535. result = options.partials[options.name](context, options);
  536. }
  537. if (result != null) {
  538. if (options.indent) {
  539. var lines = result.split('\n');
  540. for (var i = 0, l = lines.length; i < l; i++) {
  541. if (!lines[i] && i + 1 === l) {
  542. break;
  543. }
  544. lines[i] = options.indent + lines[i];
  545. }
  546. result = lines.join('\n');
  547. }
  548. return result;
  549. } else {
  550. throw new _exception2['default']('The partial ' + options.name + ' could not be compiled when running in runtime-only mode');
  551. }
  552. }
  553. // Just add water
  554. var container = {
  555. strict: function strict(obj, name) {
  556. if (!(name in obj)) {
  557. throw new _exception2['default']('"' + name + '" not defined in ' + obj);
  558. }
  559. return obj[name];
  560. },
  561. lookup: function lookup(depths, name) {
  562. var len = depths.length;
  563. for (var i = 0; i < len; i++) {
  564. if (depths[i] && depths[i][name] != null) {
  565. return depths[i][name];
  566. }
  567. }
  568. },
  569. lambda: function lambda(current, context) {
  570. return typeof current === 'function' ? current.call(context) : current;
  571. },
  572. escapeExpression: Utils.escapeExpression,
  573. invokePartial: invokePartialWrapper,
  574. fn: function fn(i) {
  575. var ret = templateSpec[i];
  576. ret.decorator = templateSpec[i + '_d'];
  577. return ret;
  578. },
  579. programs: [],
  580. program: function program(i, data, declaredBlockParams, blockParams, depths) {
  581. var programWrapper = this.programs[i],
  582. fn = this.fn(i);
  583. if (data || depths || blockParams || declaredBlockParams) {
  584. programWrapper = wrapProgram(this, i, fn, data, declaredBlockParams, blockParams, depths);
  585. } else if (!programWrapper) {
  586. programWrapper = this.programs[i] = wrapProgram(this, i, fn);
  587. }
  588. return programWrapper;
  589. },
  590. data: function data(value, depth) {
  591. while (value && depth--) {
  592. value = value._parent;
  593. }
  594. return value;
  595. },
  596. merge: function merge(param, common) {
  597. var obj = param || common;
  598. if (param && common && param !== common) {
  599. obj = Utils.extend({}, common, param);
  600. }
  601. return obj;
  602. },
  603. noop: env.VM.noop,
  604. compilerInfo: templateSpec.compiler
  605. };
  606. function ret(context) {
  607. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  608. var data = options.data;
  609. ret._setup(options);
  610. if (!options.partial && templateSpec.useData) {
  611. data = initData(context, data);
  612. }
  613. var depths = undefined,
  614. blockParams = templateSpec.useBlockParams ? [] : undefined;
  615. if (templateSpec.useDepths) {
  616. if (options.depths) {
  617. depths = context !== options.depths[0] ? [context].concat(options.depths) : options.depths;
  618. } else {
  619. depths = [context];
  620. }
  621. }
  622. function main(context /*, options*/) {
  623. return '' + templateSpec.main(container, context, container.helpers, container.partials, data, blockParams, depths);
  624. }
  625. main = executeDecorators(templateSpec.main, main, container, options.depths || [], data, blockParams);
  626. return main(context, options);
  627. }
  628. ret.isTop = true;
  629. ret._setup = function (options) {
  630. if (!options.partial) {
  631. container.helpers = container.merge(options.helpers, env.helpers);
  632. if (templateSpec.usePartial) {
  633. container.partials = container.merge(options.partials, env.partials);
  634. }
  635. if (templateSpec.usePartial || templateSpec.useDecorators) {
  636. container.decorators = container.merge(options.decorators, env.decorators);
  637. }
  638. } else {
  639. container.helpers = options.helpers;
  640. container.partials = options.partials;
  641. container.decorators = options.decorators;
  642. }
  643. };
  644. ret._child = function (i, data, blockParams, depths) {
  645. if (templateSpec.useBlockParams && !blockParams) {
  646. throw new _exception2['default']('must pass block params');
  647. }
  648. if (templateSpec.useDepths && !depths) {
  649. throw new _exception2['default']('must pass parent depths');
  650. }
  651. return wrapProgram(container, i, templateSpec[i], data, 0, blockParams, depths);
  652. };
  653. return ret;
  654. }
  655. function wrapProgram(container, i, fn, data, declaredBlockParams, blockParams, depths) {
  656. function prog(context) {
  657. var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
  658. var currentDepths = depths;
  659. if (depths && context !== depths[0]) {
  660. currentDepths = [context].concat(depths);
  661. }
  662. return fn(container, context, container.helpers, container.partials, options.data || data, blockParams && [options.blockParams].concat(blockParams), currentDepths);
  663. }
  664. prog = executeDecorators(fn, prog, container, depths, data, blockParams);
  665. prog.program = i;
  666. prog.depth = depths ? depths.length : 0;
  667. prog.blockParams = declaredBlockParams || 0;
  668. return prog;
  669. }
  670. function resolvePartial(partial, context, options) {
  671. if (!partial) {
  672. if (options.name === '@partial-block') {
  673. partial = options.data['partial-block'];
  674. } else {
  675. partial = options.partials[options.name];
  676. }
  677. } else if (!partial.call && !options.name) {
  678. // This is a dynamic partial that returned a string
  679. options.name = partial;
  680. partial = options.partials[partial];
  681. }
  682. return partial;
  683. }
  684. function invokePartial(partial, context, options) {
  685. options.partial = true;
  686. if (options.ids) {
  687. options.data.contextPath = options.ids[0] || options.data.contextPath;
  688. }
  689. var partialBlock = undefined;
  690. if (options.fn && options.fn !== noop) {
  691. options.data = _base.createFrame(options.data);
  692. partialBlock = options.data['partial-block'] = options.fn;
  693. if (partialBlock.partials) {
  694. options.partials = Utils.extend({}, options.partials, partialBlock.partials);
  695. }
  696. }
  697. if (partial === undefined && partialBlock) {
  698. partial = partialBlock;
  699. }
  700. if (partial === undefined) {
  701. throw new _exception2['default']('The partial ' + options.name + ' could not be found');
  702. } else if (partial instanceof Function) {
  703. return partial(context, options);
  704. }
  705. }
  706. function noop() {
  707. return '';
  708. }
  709. function initData(context, data) {
  710. if (!data || !('root' in data)) {
  711. data = data ? _base.createFrame(data) : {};
  712. data.root = context;
  713. }
  714. return data;
  715. }
  716. function executeDecorators(fn, prog, container, depths, data, blockParams) {
  717. if (fn.decorator) {
  718. var props = {};
  719. prog = fn.decorator(prog, props, container, depths && depths[0], data, blockParams, depths);
  720. Utils.extend(prog, props);
  721. }
  722. return prog;
  723. }
  724. },{"./base":2,"./exception":5,"./utils":18}],17:[function(require,module,exports){
  725. // Build out our basic SafeString type
  726. 'use strict';
  727. exports.__esModule = true;
  728. function SafeString(string) {
  729. this.string = string;
  730. }
  731. SafeString.prototype.toString = SafeString.prototype.toHTML = function () {
  732. return '' + this.string;
  733. };
  734. exports['default'] = SafeString;
  735. module.exports = exports['default'];
  736. },{}],18:[function(require,module,exports){
  737. 'use strict';
  738. exports.__esModule = true;
  739. exports.extend = extend;
  740. exports.indexOf = indexOf;
  741. exports.escapeExpression = escapeExpression;
  742. exports.isEmpty = isEmpty;
  743. exports.createFrame = createFrame;
  744. exports.blockParams = blockParams;
  745. exports.appendContextPath = appendContextPath;
  746. var escape = {
  747. '&': '&amp;',
  748. '<': '&lt;',
  749. '>': '&gt;',
  750. '"': '&quot;',
  751. "'": '&#x27;',
  752. '`': '&#x60;',
  753. '=': '&#x3D;'
  754. };
  755. var badChars = /[&<>"'`=]/g,
  756. possible = /[&<>"'`=]/;
  757. function escapeChar(chr) {
  758. return escape[chr];
  759. }
  760. function extend(obj /* , ...source */) {
  761. for (var i = 1; i < arguments.length; i++) {
  762. for (var key in arguments[i]) {
  763. if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
  764. obj[key] = arguments[i][key];
  765. }
  766. }
  767. }
  768. return obj;
  769. }
  770. var toString = Object.prototype.toString;
  771. exports.toString = toString;
  772. // Sourced from lodash
  773. // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
  774. /* eslint-disable func-style */
  775. var isFunction = function isFunction(value) {
  776. return typeof value === 'function';
  777. };
  778. // fallback for older versions of Chrome and Safari
  779. /* istanbul ignore next */
  780. if (isFunction(/x/)) {
  781. exports.isFunction = isFunction = function (value) {
  782. return typeof value === 'function' && toString.call(value) === '[object Function]';
  783. };
  784. }
  785. exports.isFunction = isFunction;
  786. /* eslint-enable func-style */
  787. /* istanbul ignore next */
  788. var isArray = Array.isArray || function (value) {
  789. return value && typeof value === 'object' ? toString.call(value) === '[object Array]' : false;
  790. };
  791. exports.isArray = isArray;
  792. // Older IE versions do not directly support indexOf so we must implement our own, sadly.
  793. function indexOf(array, value) {
  794. for (var i = 0, len = array.length; i < len; i++) {
  795. if (array[i] === value) {
  796. return i;
  797. }
  798. }
  799. return -1;
  800. }
  801. function escapeExpression(string) {
  802. if (typeof string !== 'string') {
  803. // don't escape SafeStrings, since they're already safe
  804. if (string && string.toHTML) {
  805. return string.toHTML();
  806. } else if (string == null) {
  807. return '';
  808. } else if (!string) {
  809. return string + '';
  810. }
  811. // Force a string conversion as this will be done by the append regardless and
  812. // the regex test will do this transparently behind the scenes, causing issues if
  813. // an object's to string has escaped characters in it.
  814. string = '' + string;
  815. }
  816. if (!possible.test(string)) {
  817. return string;
  818. }
  819. return string.replace(badChars, escapeChar);
  820. }
  821. function isEmpty(value) {
  822. if (!value && value !== 0) {
  823. return true;
  824. } else if (isArray(value) && value.length === 0) {
  825. return true;
  826. } else {
  827. return false;
  828. }
  829. }
  830. function createFrame(object) {
  831. var frame = extend({}, object);
  832. frame._parent = object;
  833. return frame;
  834. }
  835. function blockParams(params, ids) {
  836. params.path = ids;
  837. return params;
  838. }
  839. function appendContextPath(contextPath, id) {
  840. return (contextPath ? contextPath + '.' : '') + id;
  841. }
  842. },{}],19:[function(require,module,exports){
  843. // Create a simple path alias to allow browserify to resolve
  844. // the runtime on a supported path.
  845. module.exports = require('./dist/cjs/handlebars.runtime')['default'];
  846. },{"./dist/cjs/handlebars.runtime":1}],20:[function(require,module,exports){
  847. module.exports = require("handlebars/runtime")["default"];
  848. },{"handlebars/runtime":19}],21:[function(require,module,exports){
  849. 'use strict';
  850. var _index = require('../templates/index.hbs');
  851. var _index2 = _interopRequireDefault(_index);
  852. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  853. console.log('handlebars template:');
  854. console.log((0, _index2.default)({ users: ['John', 'Ira', 'Karl'] }));
  855. },{"../templates/index.hbs":22}],22:[function(require,module,exports){
  856. // hbsfy compiled Handlebars template
  857. var HandlebarsCompiler = require('hbsfy/runtime');
  858. module.exports = HandlebarsCompiler.template({"1":function(container,depth0,helpers,partials,data) {
  859. return " <li>"
  860. + container.escapeExpression(container.lambda(depth0, depth0))
  861. + "</li>\n";
  862. },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
  863. var stack1;
  864. return "<ul>\n"
  865. + ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.users : depth0),{"name":"each","hash":{},"fn":container.program(1, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
  866. + "</ul>\n";
  867. },"useData":true});
  868. },{"hbsfy/runtime":20}]},{},[21]);