handlebars.js 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746
  1. /*!
  2. handlebars v1.3.0
  3. Copyright (C) 2011 by Yehuda Katz
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. @license
  20. */
  21. /* exported Handlebars */
  22. var Handlebars = (function() {
  23. // handlebars/safe-string.js
  24. var __module4__ = (function() {
  25. "use strict";
  26. var __exports__;
  27. // Build out our basic SafeString type
  28. function SafeString(string) {
  29. this.string = string;
  30. }
  31. SafeString.prototype.toString = function() {
  32. return "" + this.string;
  33. };
  34. __exports__ = SafeString;
  35. return __exports__;
  36. })();
  37. // handlebars/utils.js
  38. var __module3__ = (function(__dependency1__) {
  39. "use strict";
  40. var __exports__ = {};
  41. /*jshint -W004 */
  42. var SafeString = __dependency1__;
  43. var escape = {
  44. "&": "&",
  45. "<": "&lt;",
  46. ">": "&gt;",
  47. '"': "&quot;",
  48. "'": "&#x27;",
  49. "`": "&#x60;"
  50. };
  51. var badChars = /[&<>"'`]/g;
  52. var possible = /[&<>"'`]/;
  53. function escapeChar(chr) {
  54. return escape[chr] || "&amp;";
  55. }
  56. function extend(obj, value) {
  57. for(var key in value) {
  58. if(Object.prototype.hasOwnProperty.call(value, key)) {
  59. obj[key] = value[key];
  60. }
  61. }
  62. }
  63. __exports__.extend = extend;var toString = Object.prototype.toString;
  64. __exports__.toString = toString;
  65. // Sourced from lodash
  66. // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
  67. var isFunction = function(value) {
  68. return typeof value === 'function';
  69. };
  70. // fallback for older versions of Chrome and Safari
  71. if (isFunction(/x/)) {
  72. isFunction = function(value) {
  73. return typeof value === 'function' && toString.call(value) === '[object Function]';
  74. };
  75. }
  76. var isFunction;
  77. __exports__.isFunction = isFunction;
  78. var isArray = Array.isArray || function(value) {
  79. return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
  80. };
  81. __exports__.isArray = isArray;
  82. function escapeExpression(string) {
  83. // don't escape SafeStrings, since they're already safe
  84. if (string instanceof SafeString) {
  85. return string.toString();
  86. } else if (!string && string !== 0) {
  87. return "";
  88. }
  89. // Force a string conversion as this will be done by the append regardless and
  90. // the regex test will do this transparently behind the scenes, causing issues if
  91. // an object's to string has escaped characters in it.
  92. string = "" + string;
  93. if(!possible.test(string)) { return string; }
  94. return string.replace(badChars, escapeChar);
  95. }
  96. __exports__.escapeExpression = escapeExpression;function isEmpty(value) {
  97. if (!value && value !== 0) {
  98. return true;
  99. } else if (isArray(value) && value.length === 0) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }
  105. __exports__.isEmpty = isEmpty;
  106. return __exports__;
  107. })(__module4__);
  108. // handlebars/exception.js
  109. var __module5__ = (function() {
  110. "use strict";
  111. var __exports__;
  112. var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
  113. function Exception(message, node) {
  114. var line;
  115. if (node && node.firstLine) {
  116. line = node.firstLine;
  117. message += ' - ' + line + ':' + node.firstColumn;
  118. }
  119. var tmp = Error.prototype.constructor.call(this, message);
  120. // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
  121. for (var idx = 0; idx < errorProps.length; idx++) {
  122. this[errorProps[idx]] = tmp[errorProps[idx]];
  123. }
  124. if (line) {
  125. this.lineNumber = line;
  126. this.column = node.firstColumn;
  127. }
  128. }
  129. Exception.prototype = new Error();
  130. __exports__ = Exception;
  131. return __exports__;
  132. })();
  133. // handlebars/base.js
  134. var __module2__ = (function(__dependency1__, __dependency2__) {
  135. "use strict";
  136. var __exports__ = {};
  137. var Utils = __dependency1__;
  138. var Exception = __dependency2__;
  139. var VERSION = "1.3.0";
  140. __exports__.VERSION = VERSION;var COMPILER_REVISION = 4;
  141. __exports__.COMPILER_REVISION = COMPILER_REVISION;
  142. var REVISION_CHANGES = {
  143. 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it
  144. 2: '== 1.0.0-rc.3',
  145. 3: '== 1.0.0-rc.4',
  146. 4: '>= 1.0.0'
  147. };
  148. __exports__.REVISION_CHANGES = REVISION_CHANGES;
  149. var isArray = Utils.isArray,
  150. isFunction = Utils.isFunction,
  151. toString = Utils.toString,
  152. objectType = '[object Object]';
  153. function HandlebarsEnvironment(helpers, partials) {
  154. this.helpers = helpers || {};
  155. this.partials = partials || {};
  156. registerDefaultHelpers(this);
  157. }
  158. __exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = {
  159. constructor: HandlebarsEnvironment,
  160. logger: logger,
  161. log: log,
  162. registerHelper: function(name, fn, inverse) {
  163. if (toString.call(name) === objectType) {
  164. if (inverse || fn) { throw new Exception('Arg not supported with multiple helpers'); }
  165. Utils.extend(this.helpers, name);
  166. } else {
  167. if (inverse) { fn.not = inverse; }
  168. this.helpers[name] = fn;
  169. }
  170. },
  171. registerPartial: function(name, str) {
  172. if (toString.call(name) === objectType) {
  173. Utils.extend(this.partials, name);
  174. } else {
  175. this.partials[name] = str;
  176. }
  177. }
  178. };
  179. function registerDefaultHelpers(instance) {
  180. instance.registerHelper('helperMissing', function(arg) {
  181. if(arguments.length === 2) {
  182. return undefined;
  183. } else {
  184. throw new Exception("Missing helper: '" + arg + "'");
  185. }
  186. });
  187. instance.registerHelper('blockHelperMissing', function(context, options) {
  188. var inverse = options.inverse || function() {}, fn = options.fn;
  189. if (isFunction(context)) { context = context.call(this); }
  190. if(context === true) {
  191. return fn(this);
  192. } else if(context === false || context == null) {
  193. return inverse(this);
  194. } else if (isArray(context)) {
  195. if(context.length > 0) {
  196. return instance.helpers.each(context, options);
  197. } else {
  198. return inverse(this);
  199. }
  200. } else {
  201. return fn(context);
  202. }
  203. });
  204. instance.registerHelper('each', function(context, options) {
  205. var fn = options.fn, inverse = options.inverse;
  206. var i = 0, ret = "", data;
  207. if (isFunction(context)) { context = context.call(this); }
  208. if (options.data) {
  209. data = createFrame(options.data);
  210. }
  211. if(context && typeof context === 'object') {
  212. if (isArray(context)) {
  213. for(var j = context.length; i<j; i++) {
  214. if (data) {
  215. data.index = i;
  216. data.first = (i === 0);
  217. data.last = (i === (context.length-1));
  218. }
  219. ret = ret + fn(context[i], { data: data });
  220. }
  221. } else {
  222. for(var key in context) {
  223. if(context.hasOwnProperty(key)) {
  224. if(data) {
  225. data.key = key;
  226. data.index = i;
  227. data.first = (i === 0);
  228. }
  229. ret = ret + fn(context[key], {data: data});
  230. i++;
  231. }
  232. }
  233. }
  234. }
  235. if(i === 0){
  236. ret = inverse(this);
  237. }
  238. return ret;
  239. });
  240. instance.registerHelper('if', function(conditional, options) {
  241. if (isFunction(conditional)) { conditional = conditional.call(this); }
  242. // Default behavior is to render the positive path if the value is truthy and not empty.
  243. // The `includeZero` option may be set to treat the condtional as purely not empty based on the
  244. // behavior of isEmpty. Effectively this determines if 0 is handled by the positive path or negative.
  245. if ((!options.hash.includeZero && !conditional) || Utils.isEmpty(conditional)) {
  246. return options.inverse(this);
  247. } else {
  248. return options.fn(this);
  249. }
  250. });
  251. instance.registerHelper('unless', function(conditional, options) {
  252. return instance.helpers['if'].call(this, conditional, {fn: options.inverse, inverse: options.fn, hash: options.hash});
  253. });
  254. instance.registerHelper('with', function(context, options) {
  255. if (isFunction(context)) { context = context.call(this); }
  256. if (!Utils.isEmpty(context)) return options.fn(context);
  257. });
  258. instance.registerHelper('log', function(context, options) {
  259. var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1;
  260. instance.log(level, context);
  261. });
  262. }
  263. var logger = {
  264. methodMap: { 0: 'debug', 1: 'info', 2: 'warn', 3: 'error' },
  265. // State enum
  266. DEBUG: 0,
  267. INFO: 1,
  268. WARN: 2,
  269. ERROR: 3,
  270. level: 3,
  271. // can be overridden in the host environment
  272. log: function(level, obj) {
  273. if (logger.level <= level) {
  274. var method = logger.methodMap[level];
  275. if (typeof console !== 'undefined' && console[method]) {
  276. console[method].call(console, obj);
  277. }
  278. }
  279. }
  280. };
  281. __exports__.logger = logger;
  282. function log(level, obj) { logger.log(level, obj); }
  283. __exports__.log = log;var createFrame = function(object) {
  284. var obj = {};
  285. Utils.extend(obj, object);
  286. return obj;
  287. };
  288. __exports__.createFrame = createFrame;
  289. return __exports__;
  290. })(__module3__, __module5__);
  291. // handlebars/runtime.js
  292. var __module6__ = (function(__dependency1__, __dependency2__, __dependency3__) {
  293. "use strict";
  294. var __exports__ = {};
  295. var Utils = __dependency1__;
  296. var Exception = __dependency2__;
  297. var COMPILER_REVISION = __dependency3__.COMPILER_REVISION;
  298. var REVISION_CHANGES = __dependency3__.REVISION_CHANGES;
  299. function checkRevision(compilerInfo) {
  300. var compilerRevision = compilerInfo && compilerInfo[0] || 1,
  301. currentRevision = COMPILER_REVISION;
  302. if (compilerRevision !== currentRevision) {
  303. if (compilerRevision < currentRevision) {
  304. var runtimeVersions = REVISION_CHANGES[currentRevision],
  305. compilerVersions = REVISION_CHANGES[compilerRevision];
  306. throw new Exception("Template was precompiled with an older version of Handlebars than the current runtime. "+
  307. "Please update your precompiler to a newer version ("+runtimeVersions+") or downgrade your runtime to an older version ("+compilerVersions+").");
  308. } else {
  309. // Use the embedded version info since the runtime doesn't know about this revision yet
  310. throw new Exception("Template was precompiled with a newer version of Handlebars than the current runtime. "+
  311. "Please update your runtime to a newer version ("+compilerInfo[1]+").");
  312. }
  313. }
  314. }
  315. __exports__.checkRevision = checkRevision;// TODO: Remove this line and break up compilePartial
  316. function template(templateSpec, env) {
  317. if (!env) {
  318. throw new Exception("No environment passed to template");
  319. }
  320. // Note: Using env.VM references rather than local var references throughout this section to allow
  321. // for external users to override these as psuedo-supported APIs.
  322. var invokePartialWrapper = function(partial, name, context, helpers, partials, data) {
  323. var result = env.VM.invokePartial.apply(this, arguments);
  324. if (result != null) { return result; }
  325. if (env.compile) {
  326. var options = { helpers: helpers, partials: partials, data: data };
  327. partials[name] = env.compile(partial, { data: data !== undefined }, env);
  328. return partials[name](context, options);
  329. } else {
  330. throw new Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
  331. }
  332. };
  333. // Just add water
  334. var container = {
  335. escapeExpression: Utils.escapeExpression,
  336. invokePartial: invokePartialWrapper,
  337. programs: [],
  338. program: function(i, fn, data) {
  339. var programWrapper = this.programs[i];
  340. if(data) {
  341. programWrapper = program(i, fn, data);
  342. } else if (!programWrapper) {
  343. programWrapper = this.programs[i] = program(i, fn);
  344. }
  345. return programWrapper;
  346. },
  347. merge: function(param, common) {
  348. var ret = param || common;
  349. if (param && common && (param !== common)) {
  350. ret = {};
  351. Utils.extend(ret, common);
  352. Utils.extend(ret, param);
  353. }
  354. return ret;
  355. },
  356. programWithDepth: env.VM.programWithDepth,
  357. noop: env.VM.noop,
  358. compilerInfo: null
  359. };
  360. return function(context, options) {
  361. options = options || {};
  362. var namespace = options.partial ? options : env,
  363. helpers,
  364. partials;
  365. if (!options.partial) {
  366. helpers = options.helpers;
  367. partials = options.partials;
  368. }
  369. var result = templateSpec.call(
  370. container,
  371. namespace, context,
  372. helpers,
  373. partials,
  374. options.data);
  375. if (!options.partial) {
  376. env.VM.checkRevision(container.compilerInfo);
  377. }
  378. return result;
  379. };
  380. }
  381. __exports__.template = template;function programWithDepth(i, fn, data /*, $depth */) {
  382. var args = Array.prototype.slice.call(arguments, 3);
  383. var prog = function(context, options) {
  384. options = options || {};
  385. return fn.apply(this, [context, options.data || data].concat(args));
  386. };
  387. prog.program = i;
  388. prog.depth = args.length;
  389. return prog;
  390. }
  391. __exports__.programWithDepth = programWithDepth;function program(i, fn, data) {
  392. var prog = function(context, options) {
  393. options = options || {};
  394. return fn(context, options.data || data);
  395. };
  396. prog.program = i;
  397. prog.depth = 0;
  398. return prog;
  399. }
  400. __exports__.program = program;function invokePartial(partial, name, context, helpers, partials, data) {
  401. var options = { partial: true, helpers: helpers, partials: partials, data: data };
  402. if(partial === undefined) {
  403. throw new Exception("The partial " + name + " could not be found");
  404. } else if(partial instanceof Function) {
  405. return partial(context, options);
  406. }
  407. }
  408. __exports__.invokePartial = invokePartial;function noop() { return ""; }
  409. __exports__.noop = noop;
  410. return __exports__;
  411. })(__module3__, __module5__, __module2__);
  412. // handlebars.runtime.js
  413. var __module1__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {
  414. "use strict";
  415. var __exports__;
  416. /*globals Handlebars: true */
  417. var base = __dependency1__;
  418. // Each of these augment the Handlebars object. No need to setup here.
  419. // (This is done to easily share code between commonjs and browse envs)
  420. var SafeString = __dependency2__;
  421. var Exception = __dependency3__;
  422. var Utils = __dependency4__;
  423. var runtime = __dependency5__;
  424. // For compatibility and usage outside of module systems, make the Handlebars object a namespace
  425. var create = function() {
  426. var hb = new base.HandlebarsEnvironment();
  427. Utils.extend(hb, base);
  428. hb.SafeString = SafeString;
  429. hb.Exception = Exception;
  430. hb.Utils = Utils;
  431. hb.VM = runtime;
  432. hb.template = function(spec) {
  433. return runtime.template(spec, hb);
  434. };
  435. return hb;
  436. };
  437. var Handlebars = create();
  438. Handlebars.create = create;
  439. __exports__ = Handlebars;
  440. return __exports__;
  441. })(__module2__, __module4__, __module5__, __module3__, __module6__);
  442. // handlebars/compiler/ast.js
  443. var __module7__ = (function(__dependency1__) {
  444. "use strict";
  445. var __exports__;
  446. var Exception = __dependency1__;
  447. function LocationInfo(locInfo){
  448. locInfo = locInfo || {};
  449. this.firstLine = locInfo.first_line;
  450. this.firstColumn = locInfo.first_column;
  451. this.lastColumn = locInfo.last_column;
  452. this.lastLine = locInfo.last_line;
  453. }
  454. var AST = {
  455. ProgramNode: function(statements, inverseStrip, inverse, locInfo) {
  456. var inverseLocationInfo, firstInverseNode;
  457. if (arguments.length === 3) {
  458. locInfo = inverse;
  459. inverse = null;
  460. } else if (arguments.length === 2) {
  461. locInfo = inverseStrip;
  462. inverseStrip = null;
  463. }
  464. LocationInfo.call(this, locInfo);
  465. this.type = "program";
  466. this.statements = statements;
  467. this.strip = {};
  468. if(inverse) {
  469. firstInverseNode = inverse[0];
  470. if (firstInverseNode) {
  471. inverseLocationInfo = {
  472. first_line: firstInverseNode.firstLine,
  473. last_line: firstInverseNode.lastLine,
  474. last_column: firstInverseNode.lastColumn,
  475. first_column: firstInverseNode.firstColumn
  476. };
  477. this.inverse = new AST.ProgramNode(inverse, inverseStrip, inverseLocationInfo);
  478. } else {
  479. this.inverse = new AST.ProgramNode(inverse, inverseStrip);
  480. }
  481. this.strip.right = inverseStrip.left;
  482. } else if (inverseStrip) {
  483. this.strip.left = inverseStrip.right;
  484. }
  485. },
  486. MustacheNode: function(rawParams, hash, open, strip, locInfo) {
  487. LocationInfo.call(this, locInfo);
  488. this.type = "mustache";
  489. this.strip = strip;
  490. // Open may be a string parsed from the parser or a passed boolean flag
  491. if (open != null && open.charAt) {
  492. // Must use charAt to support IE pre-10
  493. var escapeFlag = open.charAt(3) || open.charAt(2);
  494. this.escaped = escapeFlag !== '{' && escapeFlag !== '&';
  495. } else {
  496. this.escaped = !!open;
  497. }
  498. if (rawParams instanceof AST.SexprNode) {
  499. this.sexpr = rawParams;
  500. } else {
  501. // Support old AST API
  502. this.sexpr = new AST.SexprNode(rawParams, hash);
  503. }
  504. this.sexpr.isRoot = true;
  505. // Support old AST API that stored this info in MustacheNode
  506. this.id = this.sexpr.id;
  507. this.params = this.sexpr.params;
  508. this.hash = this.sexpr.hash;
  509. this.eligibleHelper = this.sexpr.eligibleHelper;
  510. this.isHelper = this.sexpr.isHelper;
  511. },
  512. SexprNode: function(rawParams, hash, locInfo) {
  513. LocationInfo.call(this, locInfo);
  514. this.type = "sexpr";
  515. this.hash = hash;
  516. var id = this.id = rawParams[0];
  517. var params = this.params = rawParams.slice(1);
  518. // a mustache is an eligible helper if:
  519. // * its id is simple (a single part, not `this` or `..`)
  520. var eligibleHelper = this.eligibleHelper = id.isSimple;
  521. // a mustache is definitely a helper if:
  522. // * it is an eligible helper, and
  523. // * it has at least one parameter or hash segment
  524. this.isHelper = eligibleHelper && (params.length || hash);
  525. // if a mustache is an eligible helper but not a definite
  526. // helper, it is ambiguous, and will be resolved in a later
  527. // pass or at runtime.
  528. },
  529. PartialNode: function(partialName, context, strip, locInfo) {
  530. LocationInfo.call(this, locInfo);
  531. this.type = "partial";
  532. this.partialName = partialName;
  533. this.context = context;
  534. this.strip = strip;
  535. },
  536. BlockNode: function(mustache, program, inverse, close, locInfo) {
  537. LocationInfo.call(this, locInfo);
  538. if(mustache.sexpr.id.original !== close.path.original) {
  539. throw new Exception(mustache.sexpr.id.original + " doesn't match " + close.path.original, this);
  540. }
  541. this.type = 'block';
  542. this.mustache = mustache;
  543. this.program = program;
  544. this.inverse = inverse;
  545. this.strip = {
  546. left: mustache.strip.left,
  547. right: close.strip.right
  548. };
  549. (program || inverse).strip.left = mustache.strip.right;
  550. (inverse || program).strip.right = close.strip.left;
  551. if (inverse && !program) {
  552. this.isInverse = true;
  553. }
  554. },
  555. ContentNode: function(string, locInfo) {
  556. LocationInfo.call(this, locInfo);
  557. this.type = "content";
  558. this.string = string;
  559. },
  560. HashNode: function(pairs, locInfo) {
  561. LocationInfo.call(this, locInfo);
  562. this.type = "hash";
  563. this.pairs = pairs;
  564. },
  565. IdNode: function(parts, locInfo) {
  566. LocationInfo.call(this, locInfo);
  567. this.type = "ID";
  568. var original = "",
  569. dig = [],
  570. depth = 0;
  571. for(var i=0,l=parts.length; i<l; i++) {
  572. var part = parts[i].part;
  573. original += (parts[i].separator || '') + part;
  574. if (part === ".." || part === "." || part === "this") {
  575. if (dig.length > 0) {
  576. throw new Exception("Invalid path: " + original, this);
  577. } else if (part === "..") {
  578. depth++;
  579. } else {
  580. this.isScoped = true;
  581. }
  582. } else {
  583. dig.push(part);
  584. }
  585. }
  586. this.original = original;
  587. this.parts = dig;
  588. this.string = dig.join('.');
  589. this.depth = depth;
  590. // an ID is simple if it only has one part, and that part is not
  591. // `..` or `this`.
  592. this.isSimple = parts.length === 1 && !this.isScoped && depth === 0;
  593. this.stringModeValue = this.string;
  594. },
  595. PartialNameNode: function(name, locInfo) {
  596. LocationInfo.call(this, locInfo);
  597. this.type = "PARTIAL_NAME";
  598. this.name = name.original;
  599. },
  600. DataNode: function(id, locInfo) {
  601. LocationInfo.call(this, locInfo);
  602. this.type = "DATA";
  603. this.id = id;
  604. },
  605. StringNode: function(string, locInfo) {
  606. LocationInfo.call(this, locInfo);
  607. this.type = "STRING";
  608. this.original =
  609. this.string =
  610. this.stringModeValue = string;
  611. },
  612. IntegerNode: function(integer, locInfo) {
  613. LocationInfo.call(this, locInfo);
  614. this.type = "INTEGER";
  615. this.original =
  616. this.integer = integer;
  617. this.stringModeValue = Number(integer);
  618. },
  619. BooleanNode: function(bool, locInfo) {
  620. LocationInfo.call(this, locInfo);
  621. this.type = "BOOLEAN";
  622. this.bool = bool;
  623. this.stringModeValue = bool === "true";
  624. },
  625. CommentNode: function(comment, locInfo) {
  626. LocationInfo.call(this, locInfo);
  627. this.type = "comment";
  628. this.comment = comment;
  629. }
  630. };
  631. // Must be exported as an object rather than the root of the module as the jison lexer
  632. // most modify the object to operate properly.
  633. __exports__ = AST;
  634. return __exports__;
  635. })(__module5__);
  636. // handlebars/compiler/parser.js
  637. var __module9__ = (function() {
  638. "use strict";
  639. var __exports__;
  640. /* jshint ignore:start */
  641. /* Jison generated parser */
  642. var handlebars = (function(){
  643. var parser = {trace: function trace() { },
  644. yy: {},
  645. symbols_: {"error":2,"root":3,"statements":4,"EOF":5,"program":6,"simpleInverse":7,"statement":8,"openInverse":9,"closeBlock":10,"openBlock":11,"mustache":12,"partial":13,"CONTENT":14,"COMMENT":15,"OPEN_BLOCK":16,"sexpr":17,"CLOSE":18,"OPEN_INVERSE":19,"OPEN_ENDBLOCK":20,"path":21,"OPEN":22,"OPEN_UNESCAPED":23,"CLOSE_UNESCAPED":24,"OPEN_PARTIAL":25,"partialName":26,"partial_option0":27,"sexpr_repetition0":28,"sexpr_option0":29,"dataName":30,"param":31,"STRING":32,"INTEGER":33,"BOOLEAN":34,"OPEN_SEXPR":35,"CLOSE_SEXPR":36,"hash":37,"hash_repetition_plus0":38,"hashSegment":39,"ID":40,"EQUALS":41,"DATA":42,"pathSegments":43,"SEP":44,"$accept":0,"$end":1},
  646. terminals_: {2:"error",5:"EOF",14:"CONTENT",15:"COMMENT",16:"OPEN_BLOCK",18:"CLOSE",19:"OPEN_INVERSE",20:"OPEN_ENDBLOCK",22:"OPEN",23:"OPEN_UNESCAPED",24:"CLOSE_UNESCAPED",25:"OPEN_PARTIAL",32:"STRING",33:"INTEGER",34:"BOOLEAN",35:"OPEN_SEXPR",36:"CLOSE_SEXPR",40:"ID",41:"EQUALS",42:"DATA",44:"SEP"},
  647. productions_: [0,[3,2],[3,1],[6,2],[6,3],[6,2],[6,1],[6,1],[6,0],[4,1],[4,2],[8,3],[8,3],[8,1],[8,1],[8,1],[8,1],[11,3],[9,3],[10,3],[12,3],[12,3],[13,4],[7,2],[17,3],[17,1],[31,1],[31,1],[31,1],[31,1],[31,1],[31,3],[37,1],[39,3],[26,1],[26,1],[26,1],[30,2],[21,1],[43,3],[43,1],[27,0],[27,1],[28,0],[28,2],[29,0],[29,1],[38,1],[38,2]],
  648. performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {
  649. var $0 = $$.length - 1;
  650. switch (yystate) {
  651. case 1: return new yy.ProgramNode($$[$0-1], this._$);
  652. break;
  653. case 2: return new yy.ProgramNode([], this._$);
  654. break;
  655. case 3:this.$ = new yy.ProgramNode([], $$[$0-1], $$[$0], this._$);
  656. break;
  657. case 4:this.$ = new yy.ProgramNode($$[$0-2], $$[$0-1], $$[$0], this._$);
  658. break;
  659. case 5:this.$ = new yy.ProgramNode($$[$0-1], $$[$0], [], this._$);
  660. break;
  661. case 6:this.$ = new yy.ProgramNode($$[$0], this._$);
  662. break;
  663. case 7:this.$ = new yy.ProgramNode([], this._$);
  664. break;
  665. case 8:this.$ = new yy.ProgramNode([], this._$);
  666. break;
  667. case 9:this.$ = [$$[$0]];
  668. break;
  669. case 10: $$[$0-1].push($$[$0]); this.$ = $$[$0-1];
  670. break;
  671. case 11:this.$ = new yy.BlockNode($$[$0-2], $$[$0-1].inverse, $$[$0-1], $$[$0], this._$);
  672. break;
  673. case 12:this.$ = new yy.BlockNode($$[$0-2], $$[$0-1], $$[$0-1].inverse, $$[$0], this._$);
  674. break;
  675. case 13:this.$ = $$[$0];
  676. break;
  677. case 14:this.$ = $$[$0];
  678. break;
  679. case 15:this.$ = new yy.ContentNode($$[$0], this._$);
  680. break;
  681. case 16:this.$ = new yy.CommentNode($$[$0], this._$);
  682. break;
  683. case 17:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], stripFlags($$[$0-2], $$[$0]), this._$);
  684. break;
  685. case 18:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], stripFlags($$[$0-2], $$[$0]), this._$);
  686. break;
  687. case 19:this.$ = {path: $$[$0-1], strip: stripFlags($$[$0-2], $$[$0])};
  688. break;
  689. case 20:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], stripFlags($$[$0-2], $$[$0]), this._$);
  690. break;
  691. case 21:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], stripFlags($$[$0-2], $$[$0]), this._$);
  692. break;
  693. case 22:this.$ = new yy.PartialNode($$[$0-2], $$[$0-1], stripFlags($$[$0-3], $$[$0]), this._$);
  694. break;
  695. case 23:this.$ = stripFlags($$[$0-1], $$[$0]);
  696. break;
  697. case 24:this.$ = new yy.SexprNode([$$[$0-2]].concat($$[$0-1]), $$[$0], this._$);
  698. break;
  699. case 25:this.$ = new yy.SexprNode([$$[$0]], null, this._$);
  700. break;
  701. case 26:this.$ = $$[$0];
  702. break;
  703. case 27:this.$ = new yy.StringNode($$[$0], this._$);
  704. break;
  705. case 28:this.$ = new yy.IntegerNode($$[$0], this._$);
  706. break;
  707. case 29:this.$ = new yy.BooleanNode($$[$0], this._$);
  708. break;
  709. case 30:this.$ = $$[$0];
  710. break;
  711. case 31:$$[$0-1].isHelper = true; this.$ = $$[$0-1];
  712. break;
  713. case 32:this.$ = new yy.HashNode($$[$0], this._$);
  714. break;
  715. case 33:this.$ = [$$[$0-2], $$[$0]];
  716. break;
  717. case 34:this.$ = new yy.PartialNameNode($$[$0], this._$);
  718. break;
  719. case 35:this.$ = new yy.PartialNameNode(new yy.StringNode($$[$0], this._$), this._$);
  720. break;
  721. case 36:this.$ = new yy.PartialNameNode(new yy.IntegerNode($$[$0], this._$));
  722. break;
  723. case 37:this.$ = new yy.DataNode($$[$0], this._$);
  724. break;
  725. case 38:this.$ = new yy.IdNode($$[$0], this._$);
  726. break;
  727. case 39: $$[$0-2].push({part: $$[$0], separator: $$[$0-1]}); this.$ = $$[$0-2];
  728. break;
  729. case 40:this.$ = [{part: $$[$0]}];
  730. break;
  731. case 43:this.$ = [];
  732. break;
  733. case 44:$$[$0-1].push($$[$0]);
  734. break;
  735. case 47:this.$ = [$$[$0]];
  736. break;
  737. case 48:$$[$0-1].push($$[$0]);
  738. break;
  739. }
  740. },
  741. table: [{3:1,4:2,5:[1,3],8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],25:[1,15]},{1:[3]},{5:[1,16],8:17,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],22:[1,13],23:[1,14],25:[1,15]},{1:[2,2]},{5:[2,9],14:[2,9],15:[2,9],16:[2,9],19:[2,9],20:[2,9],22:[2,9],23:[2,9],25:[2,9]},{4:20,6:18,7:19,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,21],20:[2,8],22:[1,13],23:[1,14],25:[1,15]},{4:20,6:22,7:19,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,21],20:[2,8],22:[1,13],23:[1,14],25:[1,15]},{5:[2,13],14:[2,13],15:[2,13],16:[2,13],19:[2,13],20:[2,13],22:[2,13],23:[2,13],25:[2,13]},{5:[2,14],14:[2,14],15:[2,14],16:[2,14],19:[2,14],20:[2,14],22:[2,14],23:[2,14],25:[2,14]},{5:[2,15],14:[2,15],15:[2,15],16:[2,15],19:[2,15],20:[2,15],22:[2,15],23:[2,15],25:[2,15]},{5:[2,16],14:[2,16],15:[2,16],16:[2,16],19:[2,16],20:[2,16],22:[2,16],23:[2,16],25:[2,16]},{17:23,21:24,30:25,40:[1,28],42:[1,27],43:26},{17:29,21:24,30:25,40:[1,28],42:[1,27],43:26},{17:30,21:24,30:25,40:[1,28],42:[1,27],43:26},{17:31,21:24,30:25,40:[1,28],42:[1,27],43:26},{21:33,26:32,32:[1,34],33:[1,35],40:[1,28],43:26},{1:[2,1]},{5:[2,10],14:[2,10],15:[2,10],16:[2,10],19:[2,10],20:[2,10],22:[2,10],23:[2,10],25:[2,10]},{10:36,20:[1,37]},{4:38,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,7],22:[1,13],23:[1,14],25:[1,15]},{7:39,8:17,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,21],20:[2,6],22:[1,13],23:[1,14],25:[1,15]},{17:23,18:[1,40],21:24,30:25,40:[1,28],42:[1,27],43:26},{10:41,20:[1,37]},{18:[1,42]},{18:[2,43],24:[2,43],28:43,32:[2,43],33:[2,43],34:[2,43],35:[2,43],36:[2,43],40:[2,43],42:[2,43]},{18:[2,25],24:[2,25],36:[2,25]},{18:[2,38],24:[2,38],32:[2,38],33:[2,38],34:[2,38],35:[2,38],36:[2,38],40:[2,38],42:[2,38],44:[1,44]},{21:45,40:[1,28],43:26},{18:[2,40],24:[2,40],32:[2,40],33:[2,40],34:[2,40],35:[2,40],36:[2,40],40:[2,40],42:[2,40],44:[2,40]},{18:[1,46]},{18:[1,47]},{24:[1,48]},{18:[2,41],21:50,27:49,40:[1,28],43:26},{18:[2,34],40:[2,34]},{18:[2,35],40:[2,35]},{18:[2,36],40:[2,36]},{5:[2,11],14:[2,11],15:[2,11],16:[2,11],19:[2,11],20:[2,11],22:[2,11],23:[2,11],25:[2,11]},{21:51,40:[1,28],43:26},{8:17,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,3],22:[1,13],23:[1,14],25:[1,15]},{4:52,8:4,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,5],22:[1,13],23:[1,14],25:[1,15]},{14:[2,23],15:[2,23],16:[2,23],19:[2,23],20:[2,23],22:[2,23],23:[2,23],25:[2,23]},{5:[2,12],14:[2,12],15:[2,12],16:[2,12],19:[2,12],20:[2,12],22:[2,12],23:[2,12],25:[2,12]},{14:[2,18],15:[2,18],16:[2,18],19:[2,18],20:[2,18],22:[2,18],23:[2,18],25:[2,18]},{18:[2,45],21:56,24:[2,45],29:53,30:60,31:54,32:[1,57],33:[1,58],34:[1,59],35:[1,61],36:[2,45],37:55,38:62,39:63,40:[1,64],42:[1,27],43:26},{40:[1,65]},{18:[2,37],24:[2,37],32:[2,37],33:[2,37],34:[2,37],35:[2,37],36:[2,37],40:[2,37],42:[2,37]},{14:[2,17],15:[2,17],16:[2,17],19:[2,17],20:[2,17],22:[2,17],23:[2,17],25:[2,17]},{5:[2,20],14:[2,20],15:[2,20],16:[2,20],19:[2,20],20:[2,20],22:[2,20],23:[2,20],25:[2,20]},{5:[2,21],14:[2,21],15:[2,21],16:[2,21],19:[2,21],20:[2,21],22:[2,21],23:[2,21],25:[2,21]},{18:[1,66]},{18:[2,42]},{18:[1,67]},{8:17,9:5,11:6,12:7,13:8,14:[1,9],15:[1,10],16:[1,12],19:[1,11],20:[2,4],22:[1,13],23:[1,14],25:[1,15]},{18:[2,24],24:[2,24],36:[2,24]},{18:[2,44],24:[2,44],32:[2,44],33:[2,44],34:[2,44],35:[2,44],36:[2,44],40:[2,44],42:[2,44]},{18:[2,46],24:[2,46],36:[2,46]},{18:[2,26],24:[2,26],32:[2,26],33:[2,26],34:[2,26],35:[2,26],36:[2,26],40:[2,26],42:[2,26]},{18:[2,27],24:[2,27],32:[2,27],33:[2,27],34:[2,27],35:[2,27],36:[2,27],40:[2,27],42:[2,27]},{18:[2,28],24:[2,28],32:[2,28],33:[2,28],34:[2,28],35:[2,28],36:[2,28],40:[2,28],42:[2,28]},{18:[2,29],24:[2,29],32:[2,29],33:[2,29],34:[2,29],35:[2,29],36:[2,29],40:[2,29],42:[2,29]},{18:[2,30],24:[2,30],32:[2,30],33:[2,30],34:[2,30],35:[2,30],36:[2,30],40:[2,30],42:[2,30]},{17:68,21:24,30:25,40:[1,28],42:[1,27],43:26},{18:[2,32],24:[2,32],36:[2,32],39:69,40:[1,70]},{18:[2,47],24:[2,47],36:[2,47],40:[2,47]},{18:[2,40],24:[2,40],32:[2,40],33:[2,40],34:[2,40],35:[2,40],36:[2,40],40:[2,40],41:[1,71],42:[2,40],44:[2,40]},{18:[2,39],24:[2,39],32:[2,39],33:[2,39],34:[2,39],35:[2,39],36:[2,39],40:[2,39],42:[2,39],44:[2,39]},{5:[2,22],14:[2,22],15:[2,22],16:[2,22],19:[2,22],20:[2,22],22:[2,22],23:[2,22],25:[2,22]},{5:[2,19],14:[2,19],15:[2,19],16:[2,19],19:[2,19],20:[2,19],22:[2,19],23:[2,19],25:[2,19]},{36:[1,72]},{18:[2,48],24:[2,48],36:[2,48],40:[2,48]},{41:[1,71]},{21:56,30:60,31:73,32:[1,57],33:[1,58],34:[1,59],35:[1,61],40:[1,28],42:[1,27],43:26},{18:[2,31],24:[2,31],32:[2,31],33:[2,31],34:[2,31],35:[2,31],36:[2,31],40:[2,31],42:[2,31]},{18:[2,33],24:[2,33],36:[2,33],40:[2,33]}],
  742. defaultActions: {3:[2,2],16:[2,1],50:[2,42]},
  743. parseError: function parseError(str, hash) {
  744. throw new Error(str);
  745. },
  746. parse: function parse(input) {
  747. var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1;
  748. this.lexer.setInput(input);
  749. this.lexer.yy = this.yy;
  750. this.yy.lexer = this.lexer;
  751. this.yy.parser = this;
  752. if (typeof this.lexer.yylloc == "undefined")
  753. this.lexer.yylloc = {};
  754. var yyloc = this.lexer.yylloc;
  755. lstack.push(yyloc);
  756. var ranges = this.lexer.options && this.lexer.options.ranges;
  757. if (typeof this.yy.parseError === "function")
  758. this.parseError = this.yy.parseError;
  759. function popStack(n) {
  760. stack.length = stack.length - 2 * n;
  761. vstack.length = vstack.length - n;
  762. lstack.length = lstack.length - n;
  763. }
  764. function lex() {
  765. var token;
  766. token = self.lexer.lex() || 1;
  767. if (typeof token !== "number") {
  768. token = self.symbols_[token] || token;
  769. }
  770. return token;
  771. }
  772. var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected;
  773. while (true) {
  774. state = stack[stack.length - 1];
  775. if (this.defaultActions[state]) {
  776. action = this.defaultActions[state];
  777. } else {
  778. if (symbol === null || typeof symbol == "undefined") {
  779. symbol = lex();
  780. }
  781. action = table[state] && table[state][symbol];
  782. }
  783. if (typeof action === "undefined" || !action.length || !action[0]) {
  784. var errStr = "";
  785. if (!recovering) {
  786. expected = [];
  787. for (p in table[state])
  788. if (this.terminals_[p] && p > 2) {
  789. expected.push("'" + this.terminals_[p] + "'");
  790. }
  791. if (this.lexer.showPosition) {
  792. errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'";
  793. } else {
  794. errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'");
  795. }
  796. this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
  797. }
  798. }
  799. if (action[0] instanceof Array && action.length > 1) {
  800. throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol);
  801. }
  802. switch (action[0]) {
  803. case 1:
  804. stack.push(symbol);
  805. vstack.push(this.lexer.yytext);
  806. lstack.push(this.lexer.yylloc);
  807. stack.push(action[1]);
  808. symbol = null;
  809. if (!preErrorSymbol) {
  810. yyleng = this.lexer.yyleng;
  811. yytext = this.lexer.yytext;
  812. yylineno = this.lexer.yylineno;
  813. yyloc = this.lexer.yylloc;
  814. if (recovering > 0)
  815. recovering--;
  816. } else {
  817. symbol = preErrorSymbol;
  818. preErrorSymbol = null;
  819. }
  820. break;
  821. case 2:
  822. len = this.productions_[action[1]][1];
  823. yyval.$ = vstack[vstack.length - len];
  824. yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column};
  825. if (ranges) {
  826. yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]];
  827. }
  828. r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);
  829. if (typeof r !== "undefined") {
  830. return r;
  831. }
  832. if (len) {
  833. stack = stack.slice(0, -1 * len * 2);
  834. vstack = vstack.slice(0, -1 * len);
  835. lstack = lstack.slice(0, -1 * len);
  836. }
  837. stack.push(this.productions_[action[1]][0]);
  838. vstack.push(yyval.$);
  839. lstack.push(yyval._$);
  840. newState = table[stack[stack.length - 2]][stack[stack.length - 1]];
  841. stack.push(newState);
  842. break;
  843. case 3:
  844. return true;
  845. }
  846. }
  847. return true;
  848. }
  849. };
  850. function stripFlags(open, close) {
  851. return {
  852. left: open.charAt(2) === '~',
  853. right: close.charAt(0) === '~' || close.charAt(1) === '~'
  854. };
  855. }
  856. /* Jison generated lexer */
  857. var lexer = (function(){
  858. var lexer = ({EOF:1,
  859. parseError:function parseError(str, hash) {
  860. if (this.yy.parser) {
  861. this.yy.parser.parseError(str, hash);
  862. } else {
  863. throw new Error(str);
  864. }
  865. },
  866. setInput:function (input) {
  867. this._input = input;
  868. this._more = this._less = this.done = false;
  869. this.yylineno = this.yyleng = 0;
  870. this.yytext = this.matched = this.match = '';
  871. this.conditionStack = ['INITIAL'];
  872. this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
  873. if (this.options.ranges) this.yylloc.range = [0,0];
  874. this.offset = 0;
  875. return this;
  876. },
  877. input:function () {
  878. var ch = this._input[0];
  879. this.yytext += ch;
  880. this.yyleng++;
  881. this.offset++;
  882. this.match += ch;
  883. this.matched += ch;
  884. var lines = ch.match(/(?:\r\n?|\n).*/g);
  885. if (lines) {
  886. this.yylineno++;
  887. this.yylloc.last_line++;
  888. } else {
  889. this.yylloc.last_column++;
  890. }
  891. if (this.options.ranges) this.yylloc.range[1]++;
  892. this._input = this._input.slice(1);
  893. return ch;
  894. },
  895. unput:function (ch) {
  896. var len = ch.length;
  897. var lines = ch.split(/(?:\r\n?|\n)/g);
  898. this._input = ch + this._input;
  899. this.yytext = this.yytext.substr(0, this.yytext.length-len-1);
  900. //this.yyleng -= len;
  901. this.offset -= len;
  902. var oldLines = this.match.split(/(?:\r\n?|\n)/g);
  903. this.match = this.match.substr(0, this.match.length-1);
  904. this.matched = this.matched.substr(0, this.matched.length-1);
  905. if (lines.length-1) this.yylineno -= lines.length-1;
  906. var r = this.yylloc.range;
  907. this.yylloc = {first_line: this.yylloc.first_line,
  908. last_line: this.yylineno+1,
  909. first_column: this.yylloc.first_column,
  910. last_column: lines ?
  911. (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length:
  912. this.yylloc.first_column - len
  913. };
  914. if (this.options.ranges) {
  915. this.yylloc.range = [r[0], r[0] + this.yyleng - len];
  916. }
  917. return this;
  918. },
  919. more:function () {
  920. this._more = true;
  921. return this;
  922. },
  923. less:function (n) {
  924. this.unput(this.match.slice(n));
  925. },
  926. pastInput:function () {
  927. var past = this.matched.substr(0, this.matched.length - this.match.length);
  928. return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
  929. },
  930. upcomingInput:function () {
  931. var next = this.match;
  932. if (next.length < 20) {
  933. next += this._input.substr(0, 20-next.length);
  934. }
  935. return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
  936. },
  937. showPosition:function () {
  938. var pre = this.pastInput();
  939. var c = new Array(pre.length + 1).join("-");
  940. return pre + this.upcomingInput() + "\n" + c+"^";
  941. },
  942. next:function () {
  943. if (this.done) {
  944. return this.EOF;
  945. }
  946. if (!this._input) this.done = true;
  947. var token,
  948. match,
  949. tempMatch,
  950. index,
  951. col,
  952. lines;
  953. if (!this._more) {
  954. this.yytext = '';
  955. this.match = '';
  956. }
  957. var rules = this._currentRules();
  958. for (var i=0;i < rules.length; i++) {
  959. tempMatch = this._input.match(this.rules[rules[i]]);
  960. if (tempMatch && (!match || tempMatch[0].length > match[0].length)) {
  961. match = tempMatch;
  962. index = i;
  963. if (!this.options.flex) break;
  964. }
  965. }
  966. if (match) {
  967. lines = match[0].match(/(?:\r\n?|\n).*/g);
  968. if (lines) this.yylineno += lines.length;
  969. this.yylloc = {first_line: this.yylloc.last_line,
  970. last_line: this.yylineno+1,
  971. first_column: this.yylloc.last_column,
  972. last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length};
  973. this.yytext += match[0];
  974. this.match += match[0];
  975. this.matches = match;
  976. this.yyleng = this.yytext.length;
  977. if (this.options.ranges) {
  978. this.yylloc.range = [this.offset, this.offset += this.yyleng];
  979. }
  980. this._more = false;
  981. this._input = this._input.slice(match[0].length);
  982. this.matched += match[0];
  983. token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]);
  984. if (this.done && this._input) this.done = false;
  985. if (token) return token;
  986. else return;
  987. }
  988. if (this._input === "") {
  989. return this.EOF;
  990. } else {
  991. return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
  992. {text: "", token: null, line: this.yylineno});
  993. }
  994. },
  995. lex:function lex() {
  996. var r = this.next();
  997. if (typeof r !== 'undefined') {
  998. return r;
  999. } else {
  1000. return this.lex();
  1001. }
  1002. },
  1003. begin:function begin(condition) {
  1004. this.conditionStack.push(condition);
  1005. },
  1006. popState:function popState() {
  1007. return this.conditionStack.pop();
  1008. },
  1009. _currentRules:function _currentRules() {
  1010. return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
  1011. },
  1012. topState:function () {
  1013. return this.conditionStack[this.conditionStack.length-2];
  1014. },
  1015. pushState:function begin(condition) {
  1016. this.begin(condition);
  1017. }});
  1018. lexer.options = {};
  1019. lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
  1020. function strip(start, end) {
  1021. return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng-end);
  1022. }
  1023. var YYSTATE=YY_START
  1024. switch($avoiding_name_collisions) {
  1025. case 0:
  1026. if(yy_.yytext.slice(-2) === "\\\\") {
  1027. strip(0,1);
  1028. this.begin("mu");
  1029. } else if(yy_.yytext.slice(-1) === "\\") {
  1030. strip(0,1);
  1031. this.begin("emu");
  1032. } else {
  1033. this.begin("mu");
  1034. }
  1035. if(yy_.yytext) return 14;
  1036. break;
  1037. case 1:return 14;
  1038. break;
  1039. case 2:
  1040. this.popState();
  1041. return 14;
  1042. break;
  1043. case 3:strip(0,4); this.popState(); return 15;
  1044. break;
  1045. case 4:return 35;
  1046. break;
  1047. case 5:return 36;
  1048. break;
  1049. case 6:return 25;
  1050. break;
  1051. case 7:return 16;
  1052. break;
  1053. case 8:return 20;
  1054. break;
  1055. case 9:return 19;
  1056. break;
  1057. case 10:return 19;
  1058. break;
  1059. case 11:return 23;
  1060. break;
  1061. case 12:return 22;
  1062. break;
  1063. case 13:this.popState(); this.begin('com');
  1064. break;
  1065. case 14:strip(3,5); this.popState(); return 15;
  1066. break;
  1067. case 15:return 22;
  1068. break;
  1069. case 16:return 41;
  1070. break;
  1071. case 17:return 40;
  1072. break;
  1073. case 18:return 40;
  1074. break;
  1075. case 19:return 44;
  1076. break;
  1077. case 20:// ignore whitespace
  1078. break;
  1079. case 21:this.popState(); return 24;
  1080. break;
  1081. case 22:this.popState(); return 18;
  1082. break;
  1083. case 23:yy_.yytext = strip(1,2).replace(/\\"/g,'"'); return 32;
  1084. break;
  1085. case 24:yy_.yytext = strip(1,2).replace(/\\'/g,"'"); return 32;
  1086. break;
  1087. case 25:return 42;
  1088. break;
  1089. case 26:return 34;
  1090. break;
  1091. case 27:return 34;
  1092. break;
  1093. case 28:return 33;
  1094. break;
  1095. case 29:return 40;
  1096. break;
  1097. case 30:yy_.yytext = strip(1,2); return 40;
  1098. break;
  1099. case 31:return 'INVALID';
  1100. break;
  1101. case 32:return 5;
  1102. break;
  1103. }
  1104. };
  1105. lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\()/,/^(?:\))/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{(~)?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/,/^(?:-?[0-9]+(?=([~}\s)])))/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)]))))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/];
  1106. lexer.conditions = {"mu":{"rules":[4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[3],"inclusive":false},"INITIAL":{"rules":[0,1,32],"inclusive":true}};
  1107. return lexer;})()
  1108. parser.lexer = lexer;
  1109. function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser;
  1110. return new Parser;
  1111. })();__exports__ = handlebars;
  1112. /* jshint ignore:end */
  1113. return __exports__;
  1114. })();
  1115. // handlebars/compiler/base.js
  1116. var __module8__ = (function(__dependency1__, __dependency2__) {
  1117. "use strict";
  1118. var __exports__ = {};
  1119. var parser = __dependency1__;
  1120. var AST = __dependency2__;
  1121. __exports__.parser = parser;
  1122. function parse(input) {
  1123. // Just return if an already-compile AST was passed in.
  1124. if(input.constructor === AST.ProgramNode) { return input; }
  1125. parser.yy = AST;
  1126. return parser.parse(input);
  1127. }
  1128. __exports__.parse = parse;
  1129. return __exports__;
  1130. })(__module9__, __module7__);
  1131. // handlebars/compiler/compiler.js
  1132. var __module10__ = (function(__dependency1__) {
  1133. "use strict";
  1134. var __exports__ = {};
  1135. var Exception = __dependency1__;
  1136. function Compiler() {}
  1137. __exports__.Compiler = Compiler;// the foundHelper register will disambiguate helper lookup from finding a
  1138. // function in a context. This is necessary for mustache compatibility, which
  1139. // requires that context functions in blocks are evaluated by blockHelperMissing,
  1140. // and then proceed as if the resulting value was provided to blockHelperMissing.
  1141. Compiler.prototype = {
  1142. compiler: Compiler,
  1143. disassemble: function() {
  1144. var opcodes = this.opcodes, opcode, out = [], params, param;
  1145. for (var i=0, l=opcodes.length; i<l; i++) {
  1146. opcode = opcodes[i];
  1147. if (opcode.opcode === 'DECLARE') {
  1148. out.push("DECLARE " + opcode.name + "=" + opcode.value);
  1149. } else {
  1150. params = [];
  1151. for (var j=0; j<opcode.args.length; j++) {
  1152. param = opcode.args[j];
  1153. if (typeof param === "string") {
  1154. param = "\"" + param.replace("\n", "\\n") + "\"";
  1155. }
  1156. params.push(param);
  1157. }
  1158. out.push(opcode.opcode + " " + params.join(" "));
  1159. }
  1160. }
  1161. return out.join("\n");
  1162. },
  1163. equals: function(other) {
  1164. var len = this.opcodes.length;
  1165. if (other.opcodes.length !== len) {
  1166. return false;
  1167. }
  1168. for (var i = 0; i < len; i++) {
  1169. var opcode = this.opcodes[i],
  1170. otherOpcode = other.opcodes[i];
  1171. if (opcode.opcode !== otherOpcode.opcode || opcode.args.length !== otherOpcode.args.length) {
  1172. return false;
  1173. }
  1174. for (var j = 0; j < opcode.args.length; j++) {
  1175. if (opcode.args[j] !== otherOpcode.args[j]) {
  1176. return false;
  1177. }
  1178. }
  1179. }
  1180. len = this.children.length;
  1181. if (other.children.length !== len) {
  1182. return false;
  1183. }
  1184. for (i = 0; i < len; i++) {
  1185. if (!this.children[i].equals(other.children[i])) {
  1186. return false;
  1187. }
  1188. }
  1189. return true;
  1190. },
  1191. guid: 0,
  1192. compile: function(program, options) {
  1193. this.opcodes = [];
  1194. this.children = [];
  1195. this.depths = {list: []};
  1196. this.options = options;
  1197. // These changes will propagate to the other compiler components
  1198. var knownHelpers = this.options.knownHelpers;
  1199. this.options.knownHelpers = {
  1200. 'helperMissing': true,
  1201. 'blockHelperMissing': true,
  1202. 'each': true,
  1203. 'if': true,
  1204. 'unless': true,
  1205. 'with': true,
  1206. 'log': true
  1207. };
  1208. if (knownHelpers) {
  1209. for (var name in knownHelpers) {
  1210. this.options.knownHelpers[name] = knownHelpers[name];
  1211. }
  1212. }
  1213. return this.accept(program);
  1214. },
  1215. accept: function(node) {
  1216. var strip = node.strip || {},
  1217. ret;
  1218. if (strip.left) {
  1219. this.opcode('strip');
  1220. }
  1221. ret = this[node.type](node);
  1222. if (strip.right) {
  1223. this.opcode('strip');
  1224. }
  1225. return ret;
  1226. },
  1227. program: function(program) {
  1228. var statements = program.statements;
  1229. for(var i=0, l=statements.length; i<l; i++) {
  1230. this.accept(statements[i]);
  1231. }
  1232. this.isSimple = l === 1;
  1233. this.depths.list = this.depths.list.sort(function(a, b) {
  1234. return a - b;
  1235. });
  1236. return this;
  1237. },
  1238. compileProgram: function(program) {
  1239. var result = new this.compiler().compile(program, this.options);
  1240. var guid = this.guid++, depth;
  1241. this.usePartial = this.usePartial || result.usePartial;
  1242. this.children[guid] = result;
  1243. for(var i=0, l=result.depths.list.length; i<l; i++) {
  1244. depth = result.depths.list[i];
  1245. if(depth < 2) { continue; }
  1246. else { this.addDepth(depth - 1); }
  1247. }
  1248. return guid;
  1249. },
  1250. block: function(block) {
  1251. var mustache = block.mustache,
  1252. program = block.program,
  1253. inverse = block.inverse;
  1254. if (program) {
  1255. program = this.compileProgram(program);
  1256. }
  1257. if (inverse) {
  1258. inverse = this.compileProgram(inverse);
  1259. }
  1260. var sexpr = mustache.sexpr;
  1261. var type = this.classifySexpr(sexpr);
  1262. if (type === "helper") {
  1263. this.helperSexpr(sexpr, program, inverse);
  1264. } else if (type === "simple") {
  1265. this.simpleSexpr(sexpr);
  1266. // now that the simple mustache is resolved, we need to
  1267. // evaluate it by executing `blockHelperMissing`
  1268. this.opcode('pushProgram', program);
  1269. this.opcode('pushProgram', inverse);
  1270. this.opcode('emptyHash');
  1271. this.opcode('blockValue');
  1272. } else {
  1273. this.ambiguousSexpr(sexpr, program, inverse);
  1274. // now that the simple mustache is resolved, we need to
  1275. // evaluate it by executing `blockHelperMissing`
  1276. this.opcode('pushProgram', program);
  1277. this.opcode('pushProgram', inverse);
  1278. this.opcode('emptyHash');
  1279. this.opcode('ambiguousBlockValue');
  1280. }
  1281. this.opcode('append');
  1282. },
  1283. hash: function(hash) {
  1284. var pairs = hash.pairs, pair, val;
  1285. this.opcode('pushHash');
  1286. for(var i=0, l=pairs.length; i<l; i++) {
  1287. pair = pairs[i];
  1288. val = pair[1];
  1289. if (this.options.stringParams) {
  1290. if(val.depth) {
  1291. this.addDepth(val.depth);
  1292. }
  1293. this.opcode('getContext', val.depth || 0);
  1294. this.opcode('pushStringParam', val.stringModeValue, val.type);
  1295. if (val.type === 'sexpr') {
  1296. // Subexpressions get evaluated and passed in
  1297. // in string params mode.
  1298. this.sexpr(val);
  1299. }
  1300. } else {
  1301. this.accept(val);
  1302. }
  1303. this.opcode('assignToHash', pair[0]);
  1304. }
  1305. this.opcode('popHash');
  1306. },
  1307. partial: function(partial) {
  1308. var partialName = partial.partialName;
  1309. this.usePartial = true;
  1310. if(partial.context) {
  1311. this.ID(partial.context);
  1312. } else {
  1313. this.opcode('push', 'depth0');
  1314. }
  1315. this.opcode('invokePartial', partialName.name);
  1316. this.opcode('append');
  1317. },
  1318. content: function(content) {
  1319. this.opcode('appendContent', content.string);
  1320. },
  1321. mustache: function(mustache) {
  1322. this.sexpr(mustache.sexpr);
  1323. if(mustache.escaped && !this.options.noEscape) {
  1324. this.opcode('appendEscaped');
  1325. } else {
  1326. this.opcode('append');
  1327. }
  1328. },
  1329. ambiguousSexpr: function(sexpr, program, inverse) {
  1330. var id = sexpr.id,
  1331. name = id.parts[0],
  1332. isBlock = program != null || inverse != null;
  1333. this.opcode('getContext', id.depth);
  1334. this.opcode('pushProgram', program);
  1335. this.opcode('pushProgram', inverse);
  1336. this.opcode('invokeAmbiguous', name, isBlock);
  1337. },
  1338. simpleSexpr: function(sexpr) {
  1339. var id = sexpr.id;
  1340. if (id.type === 'DATA') {
  1341. this.DATA(id);
  1342. } else if (id.parts.length) {
  1343. this.ID(id);
  1344. } else {
  1345. // Simplified ID for `this`
  1346. this.addDepth(id.depth);
  1347. this.opcode('getContext', id.depth);
  1348. this.opcode('pushContext');
  1349. }
  1350. this.opcode('resolvePossibleLambda');
  1351. },
  1352. helperSexpr: function(sexpr, program, inverse) {
  1353. var params = this.setupFullMustacheParams(sexpr, program, inverse),
  1354. name = sexpr.id.parts[0];
  1355. if (this.options.knownHelpers[name]) {
  1356. this.opcode('invokeKnownHelper', params.length, name);
  1357. } else if (this.options.knownHelpersOnly) {
  1358. throw new Exception("You specified knownHelpersOnly, but used the unknown helper " + name, sexpr);
  1359. } else {
  1360. this.opcode('invokeHelper', params.length, name, sexpr.isRoot);
  1361. }
  1362. },
  1363. sexpr: function(sexpr) {
  1364. var type = this.classifySexpr(sexpr);
  1365. if (type === "simple") {
  1366. this.simpleSexpr(sexpr);
  1367. } else if (type === "helper") {
  1368. this.helperSexpr(sexpr);
  1369. } else {
  1370. this.ambiguousSexpr(sexpr);
  1371. }
  1372. },
  1373. ID: function(id) {
  1374. this.addDepth(id.depth);
  1375. this.opcode('getContext', id.depth);
  1376. var name = id.parts[0];
  1377. if (!name) {
  1378. this.opcode('pushContext');
  1379. } else {
  1380. this.opcode('lookupOnContext', id.parts[0]);
  1381. }
  1382. for(var i=1, l=id.parts.length; i<l; i++) {
  1383. this.opcode('lookup', id.parts[i]);
  1384. }
  1385. },
  1386. DATA: function(data) {
  1387. this.options.data = true;
  1388. if (data.id.isScoped || data.id.depth) {
  1389. throw new Exception('Scoped data references are not supported: ' + data.original, data);
  1390. }
  1391. this.opcode('lookupData');
  1392. var parts = data.id.parts;
  1393. for(var i=0, l=parts.length; i<l; i++) {
  1394. this.opcode('lookup', parts[i]);
  1395. }
  1396. },
  1397. STRING: function(string) {
  1398. this.opcode('pushString', string.string);
  1399. },
  1400. INTEGER: function(integer) {
  1401. this.opcode('pushLiteral', integer.integer);
  1402. },
  1403. BOOLEAN: function(bool) {
  1404. this.opcode('pushLiteral', bool.bool);
  1405. },
  1406. comment: function() {},
  1407. // HELPERS
  1408. opcode: function(name) {
  1409. this.opcodes.push({ opcode: name, args: [].slice.call(arguments, 1) });
  1410. },
  1411. declare: function(name, value) {
  1412. this.opcodes.push({ opcode: 'DECLARE', name: name, value: value });
  1413. },
  1414. addDepth: function(depth) {
  1415. if(depth === 0) { return; }
  1416. if(!this.depths[depth]) {
  1417. this.depths[depth] = true;
  1418. this.depths.list.push(depth);
  1419. }
  1420. },
  1421. classifySexpr: function(sexpr) {
  1422. var isHelper = sexpr.isHelper;
  1423. var isEligible = sexpr.eligibleHelper;
  1424. var options = this.options;
  1425. // if ambiguous, we can possibly resolve the ambiguity now
  1426. if (isEligible && !isHelper) {
  1427. var name = sexpr.id.parts[0];
  1428. if (options.knownHelpers[name]) {
  1429. isHelper = true;
  1430. } else if (options.knownHelpersOnly) {
  1431. isEligible = false;
  1432. }
  1433. }
  1434. if (isHelper) { return "helper"; }
  1435. else if (isEligible) { return "ambiguous"; }
  1436. else { return "simple"; }
  1437. },
  1438. pushParams: function(params) {
  1439. var i = params.length, param;
  1440. while(i--) {
  1441. param = params[i];
  1442. if(this.options.stringParams) {
  1443. if(param.depth) {
  1444. this.addDepth(param.depth);
  1445. }
  1446. this.opcode('getContext', param.depth || 0);
  1447. this.opcode('pushStringParam', param.stringModeValue, param.type);
  1448. if (param.type === 'sexpr') {
  1449. // Subexpressions get evaluated and passed in
  1450. // in string params mode.
  1451. this.sexpr(param);
  1452. }
  1453. } else {
  1454. this[param.type](param);
  1455. }
  1456. }
  1457. },
  1458. setupFullMustacheParams: function(sexpr, program, inverse) {
  1459. var params = sexpr.params;
  1460. this.pushParams(params);
  1461. this.opcode('pushProgram', program);
  1462. this.opcode('pushProgram', inverse);
  1463. if (sexpr.hash) {
  1464. this.hash(sexpr.hash);
  1465. } else {
  1466. this.opcode('emptyHash');
  1467. }
  1468. return params;
  1469. }
  1470. };
  1471. function precompile(input, options, env) {
  1472. if (input == null || (typeof input !== 'string' && input.constructor !== env.AST.ProgramNode)) {
  1473. throw new Exception("You must pass a string or Handlebars AST to Handlebars.precompile. You passed " + input);
  1474. }
  1475. options = options || {};
  1476. if (!('data' in options)) {
  1477. options.data = true;
  1478. }
  1479. var ast = env.parse(input);
  1480. var environment = new env.Compiler().compile(ast, options);
  1481. return new env.JavaScriptCompiler().compile(environment, options);
  1482. }
  1483. __exports__.precompile = precompile;function compile(input, options, env) {
  1484. if (input == null || (typeof input !== 'string' && input.constructor !== env.AST.ProgramNode)) {
  1485. throw new Exception("You must pass a string or Handlebars AST to Handlebars.compile. You passed " + input);
  1486. }
  1487. options = options || {};
  1488. if (!('data' in options)) {
  1489. options.data = true;
  1490. }
  1491. var compiled;
  1492. function compileInput() {
  1493. var ast = env.parse(input);
  1494. var environment = new env.Compiler().compile(ast, options);
  1495. var templateSpec = new env.JavaScriptCompiler().compile(environment, options, undefined, true);
  1496. return env.template(templateSpec);
  1497. }
  1498. // Template is only compiled on first use and cached after that point.
  1499. return function(context, options) {
  1500. if (!compiled) {
  1501. compiled = compileInput();
  1502. }
  1503. return compiled.call(this, context, options);
  1504. };
  1505. }
  1506. __exports__.compile = compile;
  1507. return __exports__;
  1508. })(__module5__);
  1509. // handlebars/compiler/javascript-compiler.js
  1510. var __module11__ = (function(__dependency1__, __dependency2__) {
  1511. "use strict";
  1512. var __exports__;
  1513. var COMPILER_REVISION = __dependency1__.COMPILER_REVISION;
  1514. var REVISION_CHANGES = __dependency1__.REVISION_CHANGES;
  1515. var log = __dependency1__.log;
  1516. var Exception = __dependency2__;
  1517. function Literal(value) {
  1518. this.value = value;
  1519. }
  1520. function JavaScriptCompiler() {}
  1521. JavaScriptCompiler.prototype = {
  1522. // PUBLIC API: You can override these methods in a subclass to provide
  1523. // alternative compiled forms for name lookup and buffering semantics
  1524. nameLookup: function(parent, name /* , type*/) {
  1525. var wrap,
  1526. ret;
  1527. if (parent.indexOf('depth') === 0) {
  1528. wrap = true;
  1529. }
  1530. if (/^[0-9]+$/.test(name)) {
  1531. ret = parent + "[" + name + "]";
  1532. } else if (JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
  1533. ret = parent + "." + name;
  1534. }
  1535. else {
  1536. ret = parent + "['" + name + "']";
  1537. }
  1538. if (wrap) {
  1539. return '(' + parent + ' && ' + ret + ')';
  1540. } else {
  1541. return ret;
  1542. }
  1543. },
  1544. compilerInfo: function() {
  1545. var revision = COMPILER_REVISION,
  1546. versions = REVISION_CHANGES[revision];
  1547. return "this.compilerInfo = ["+revision+",'"+versions+"'];\n";
  1548. },
  1549. appendToBuffer: function(string) {
  1550. if (this.environment.isSimple) {
  1551. return "return " + string + ";";
  1552. } else {
  1553. return {
  1554. appendToBuffer: true,
  1555. content: string,
  1556. toString: function() { return "buffer += " + string + ";"; }
  1557. };
  1558. }
  1559. },
  1560. initializeBuffer: function() {
  1561. return this.quotedString("");
  1562. },
  1563. namespace: "Handlebars",
  1564. // END PUBLIC API
  1565. compile: function(environment, options, context, asObject) {
  1566. this.environment = environment;
  1567. this.options = options || {};
  1568. log('debug', this.environment.disassemble() + "\n\n");
  1569. this.name = this.environment.name;
  1570. this.isChild = !!context;
  1571. this.context = context || {
  1572. programs: [],
  1573. environments: [],
  1574. aliases: { }
  1575. };
  1576. this.preamble();
  1577. this.stackSlot = 0;
  1578. this.stackVars = [];
  1579. this.registers = { list: [] };
  1580. this.hashes = [];
  1581. this.compileStack = [];
  1582. this.inlineStack = [];
  1583. this.compileChildren(environment, options);
  1584. var opcodes = environment.opcodes, opcode;
  1585. this.i = 0;
  1586. for(var l=opcodes.length; this.i<l; this.i++) {
  1587. opcode = opcodes[this.i];
  1588. if(opcode.opcode === 'DECLARE') {
  1589. this[opcode.name] = opcode.value;
  1590. } else {
  1591. this[opcode.opcode].apply(this, opcode.args);
  1592. }
  1593. // Reset the stripNext flag if it was not set by this operation.
  1594. if (opcode.opcode !== this.stripNext) {
  1595. this.stripNext = false;
  1596. }
  1597. }
  1598. // Flush any trailing content that might be pending.
  1599. this.pushSource('');
  1600. if (this.stackSlot || this.inlineStack.length || this.compileStack.length) {
  1601. throw new Exception('Compile completed with content left on stack');
  1602. }
  1603. return this.createFunctionContext(asObject);
  1604. },
  1605. preamble: function() {
  1606. var out = [];
  1607. if (!this.isChild) {
  1608. var namespace = this.namespace;
  1609. var copies = "helpers = this.merge(helpers, " + namespace + ".helpers);";
  1610. if (this.environment.usePartial) { copies = copies + " partials = this.merge(partials, " + namespace + ".partials);"; }
  1611. if (this.options.data) { copies = copies + " data = data || {};"; }
  1612. out.push(copies);
  1613. } else {
  1614. out.push('');
  1615. }
  1616. if (!this.environment.isSimple) {
  1617. out.push(", buffer = " + this.initializeBuffer());
  1618. } else {
  1619. out.push("");
  1620. }
  1621. // track the last context pushed into place to allow skipping the
  1622. // getContext opcode when it would be a noop
  1623. this.lastContext = 0;
  1624. this.source = out;
  1625. },
  1626. createFunctionContext: function(asObject) {
  1627. var locals = this.stackVars.concat(this.registers.list);
  1628. if(locals.length > 0) {
  1629. this.source[1] = this.source[1] + ", " + locals.join(", ");
  1630. }
  1631. // Generate minimizer alias mappings
  1632. if (!this.isChild) {
  1633. for (var alias in this.context.aliases) {
  1634. if (this.context.aliases.hasOwnProperty(alias)) {
  1635. this.source[1] = this.source[1] + ', ' + alias + '=' + this.context.aliases[alias];
  1636. }
  1637. }
  1638. }
  1639. if (this.source[1]) {
  1640. this.source[1] = "var " + this.source[1].substring(2) + ";";
  1641. }
  1642. // Merge children
  1643. if (!this.isChild) {
  1644. this.source[1] += '\n' + this.context.programs.join('\n') + '\n';
  1645. }
  1646. if (!this.environment.isSimple) {
  1647. this.pushSource("return buffer;");
  1648. }
  1649. var params = this.isChild ? ["depth0", "data"] : ["Handlebars", "depth0", "helpers", "partials", "data"];
  1650. for(var i=0, l=this.environment.depths.list.length; i<l; i++) {
  1651. params.push("depth" + this.environment.depths.list[i]);
  1652. }
  1653. // Perform a second pass over the output to merge content when possible
  1654. var source = this.mergeSource();
  1655. if (!this.isChild) {
  1656. source = this.compilerInfo()+source;
  1657. }
  1658. if (asObject) {
  1659. params.push(source);
  1660. return Function.apply(this, params);
  1661. } else {
  1662. var functionSource = 'function ' + (this.name || '') + '(' + params.join(',') + ') {\n ' + source + '}';
  1663. log('debug', functionSource + "\n\n");
  1664. return functionSource;
  1665. }
  1666. },
  1667. mergeSource: function() {
  1668. // WARN: We are not handling the case where buffer is still populated as the source should
  1669. // not have buffer append operations as their final action.
  1670. var source = '',
  1671. buffer;
  1672. for (var i = 0, len = this.source.length; i < len; i++) {
  1673. var line = this.source[i];
  1674. if (line.appendToBuffer) {
  1675. if (buffer) {
  1676. buffer = buffer + '\n + ' + line.content;
  1677. } else {
  1678. buffer = line.content;
  1679. }
  1680. } else {
  1681. if (buffer) {
  1682. source += 'buffer += ' + buffer + ';\n ';
  1683. buffer = undefined;
  1684. }
  1685. source += line + '\n ';
  1686. }
  1687. }
  1688. return source;
  1689. },
  1690. // [blockValue]
  1691. //
  1692. // On stack, before: hash, inverse, program, value
  1693. // On stack, after: return value of blockHelperMissing
  1694. //
  1695. // The purpose of this opcode is to take a block of the form
  1696. // `{{#foo}}...{{/foo}}`, resolve the value of `foo`, and
  1697. // replace it on the stack with the result of properly
  1698. // invoking blockHelperMissing.
  1699. blockValue: function() {
  1700. this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
  1701. var params = ["depth0"];
  1702. this.setupParams(0, params);
  1703. this.replaceStack(function(current) {
  1704. params.splice(1, 0, current);
  1705. return "blockHelperMissing.call(" + params.join(", ") + ")";
  1706. });
  1707. },
  1708. // [ambiguousBlockValue]
  1709. //
  1710. // On stack, before: hash, inverse, program, value
  1711. // Compiler value, before: lastHelper=value of last found helper, if any
  1712. // On stack, after, if no lastHelper: same as [blockValue]
  1713. // On stack, after, if lastHelper: value
  1714. ambiguousBlockValue: function() {
  1715. this.context.aliases.blockHelperMissing = 'helpers.blockHelperMissing';
  1716. var params = ["depth0"];
  1717. this.setupParams(0, params);
  1718. var current = this.topStack();
  1719. params.splice(1, 0, current);
  1720. this.pushSource("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }");
  1721. },
  1722. // [appendContent]
  1723. //
  1724. // On stack, before: ...
  1725. // On stack, after: ...
  1726. //
  1727. // Appends the string value of `content` to the current buffer
  1728. appendContent: function(content) {
  1729. if (this.pendingContent) {
  1730. content = this.pendingContent + content;
  1731. }
  1732. if (this.stripNext) {
  1733. content = content.replace(/^\s+/, '');
  1734. }
  1735. this.pendingContent = content;
  1736. },
  1737. // [strip]
  1738. //
  1739. // On stack, before: ...
  1740. // On stack, after: ...
  1741. //
  1742. // Removes any trailing whitespace from the prior content node and flags
  1743. // the next operation for stripping if it is a content node.
  1744. strip: function() {
  1745. if (this.pendingContent) {
  1746. this.pendingContent = this.pendingContent.replace(/\s+$/, '');
  1747. }
  1748. this.stripNext = 'strip';
  1749. },
  1750. // [append]
  1751. //
  1752. // On stack, before: value, ...
  1753. // On stack, after: ...
  1754. //
  1755. // Coerces `value` to a String and appends it to the current buffer.
  1756. //
  1757. // If `value` is truthy, or 0, it is coerced into a string and appended
  1758. // Otherwise, the empty string is appended
  1759. append: function() {
  1760. // Force anything that is inlined onto the stack so we don't have duplication
  1761. // when we examine local
  1762. this.flushInline();
  1763. var local = this.popStack();
  1764. this.pushSource("if(" + local + " || " + local + " === 0) { " + this.appendToBuffer(local) + " }");
  1765. if (this.environment.isSimple) {
  1766. this.pushSource("else { " + this.appendToBuffer("''") + " }");
  1767. }
  1768. },
  1769. // [appendEscaped]
  1770. //
  1771. // On stack, before: value, ...
  1772. // On stack, after: ...
  1773. //
  1774. // Escape `value` and append it to the buffer
  1775. appendEscaped: function() {
  1776. this.context.aliases.escapeExpression = 'this.escapeExpression';
  1777. this.pushSource(this.appendToBuffer("escapeExpression(" + this.popStack() + ")"));
  1778. },
  1779. // [getContext]
  1780. //
  1781. // On stack, before: ...
  1782. // On stack, after: ...
  1783. // Compiler value, after: lastContext=depth
  1784. //
  1785. // Set the value of the `lastContext` compiler value to the depth
  1786. getContext: function(depth) {
  1787. if(this.lastContext !== depth) {
  1788. this.lastContext = depth;
  1789. }
  1790. },
  1791. // [lookupOnContext]
  1792. //
  1793. // On stack, before: ...
  1794. // On stack, after: currentContext[name], ...
  1795. //
  1796. // Looks up the value of `name` on the current context and pushes
  1797. // it onto the stack.
  1798. lookupOnContext: function(name) {
  1799. this.push(this.nameLookup('depth' + this.lastContext, name, 'context'));
  1800. },
  1801. // [pushContext]
  1802. //
  1803. // On stack, before: ...
  1804. // On stack, after: currentContext, ...
  1805. //
  1806. // Pushes the value of the current context onto the stack.
  1807. pushContext: function() {
  1808. this.pushStackLiteral('depth' + this.lastContext);
  1809. },
  1810. // [resolvePossibleLambda]
  1811. //
  1812. // On stack, before: value, ...
  1813. // On stack, after: resolved value, ...
  1814. //
  1815. // If the `value` is a lambda, replace it on the stack by
  1816. // the return value of the lambda
  1817. resolvePossibleLambda: function() {
  1818. this.context.aliases.functionType = '"function"';
  1819. this.replaceStack(function(current) {
  1820. return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
  1821. });
  1822. },
  1823. // [lookup]
  1824. //
  1825. // On stack, before: value, ...
  1826. // On stack, after: value[name], ...
  1827. //
  1828. // Replace the value on the stack with the result of looking
  1829. // up `name` on `value`
  1830. lookup: function(name) {
  1831. this.replaceStack(function(current) {
  1832. return current + " == null || " + current + " === false ? " + current + " : " + this.nameLookup(current, name, 'context');
  1833. });
  1834. },
  1835. // [lookupData]
  1836. //
  1837. // On stack, before: ...
  1838. // On stack, after: data, ...
  1839. //
  1840. // Push the data lookup operator
  1841. lookupData: function() {
  1842. this.pushStackLiteral('data');
  1843. },
  1844. // [pushStringParam]
  1845. //
  1846. // On stack, before: ...
  1847. // On stack, after: string, currentContext, ...
  1848. //
  1849. // This opcode is designed for use in string mode, which
  1850. // provides the string value of a parameter along with its
  1851. // depth rather than resolving it immediately.
  1852. pushStringParam: function(string, type) {
  1853. this.pushStackLiteral('depth' + this.lastContext);
  1854. this.pushString(type);
  1855. // If it's a subexpression, the string result
  1856. // will be pushed after this opcode.
  1857. if (type !== 'sexpr') {
  1858. if (typeof string === 'string') {
  1859. this.pushString(string);
  1860. } else {
  1861. this.pushStackLiteral(string);
  1862. }
  1863. }
  1864. },
  1865. emptyHash: function() {
  1866. this.pushStackLiteral('{}');
  1867. if (this.options.stringParams) {
  1868. this.push('{}'); // hashContexts
  1869. this.push('{}'); // hashTypes
  1870. }
  1871. },
  1872. pushHash: function() {
  1873. if (this.hash) {
  1874. this.hashes.push(this.hash);
  1875. }
  1876. this.hash = {values: [], types: [], contexts: []};
  1877. },
  1878. popHash: function() {
  1879. var hash = this.hash;
  1880. this.hash = this.hashes.pop();
  1881. if (this.options.stringParams) {
  1882. this.push('{' + hash.contexts.join(',') + '}');
  1883. this.push('{' + hash.types.join(',') + '}');
  1884. }
  1885. this.push('{\n ' + hash.values.join(',\n ') + '\n }');
  1886. },
  1887. // [pushString]
  1888. //
  1889. // On stack, before: ...
  1890. // On stack, after: quotedString(string), ...
  1891. //
  1892. // Push a quoted version of `string` onto the stack
  1893. pushString: function(string) {
  1894. this.pushStackLiteral(this.quotedString(string));
  1895. },
  1896. // [push]
  1897. //
  1898. // On stack, before: ...
  1899. // On stack, after: expr, ...
  1900. //
  1901. // Push an expression onto the stack
  1902. push: function(expr) {
  1903. this.inlineStack.push(expr);
  1904. return expr;
  1905. },
  1906. // [pushLiteral]
  1907. //
  1908. // On stack, before: ...
  1909. // On stack, after: value, ...
  1910. //
  1911. // Pushes a value onto the stack. This operation prevents
  1912. // the compiler from creating a temporary variable to hold
  1913. // it.
  1914. pushLiteral: function(value) {
  1915. this.pushStackLiteral(value);
  1916. },
  1917. // [pushProgram]
  1918. //
  1919. // On stack, before: ...
  1920. // On stack, after: program(guid), ...
  1921. //
  1922. // Push a program expression onto the stack. This takes
  1923. // a compile-time guid and converts it into a runtime-accessible
  1924. // expression.
  1925. pushProgram: function(guid) {
  1926. if (guid != null) {
  1927. this.pushStackLiteral(this.programExpression(guid));
  1928. } else {
  1929. this.pushStackLiteral(null);
  1930. }
  1931. },
  1932. // [invokeHelper]
  1933. //
  1934. // On stack, before: hash, inverse, program, params..., ...
  1935. // On stack, after: result of helper invocation
  1936. //
  1937. // Pops off the helper's parameters, invokes the helper,
  1938. // and pushes the helper's return value onto the stack.
  1939. //
  1940. // If the helper is not found, `helperMissing` is called.
  1941. invokeHelper: function(paramSize, name, isRoot) {
  1942. this.context.aliases.helperMissing = 'helpers.helperMissing';
  1943. this.useRegister('helper');
  1944. var helper = this.lastHelper = this.setupHelper(paramSize, name, true);
  1945. var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
  1946. var lookup = 'helper = ' + helper.name + ' || ' + nonHelper;
  1947. if (helper.paramsInit) {
  1948. lookup += ',' + helper.paramsInit;
  1949. }
  1950. this.push(
  1951. '('
  1952. + lookup
  1953. + ',helper '
  1954. + '? helper.call(' + helper.callParams + ') '
  1955. + ': helperMissing.call(' + helper.helperMissingParams + '))');
  1956. // Always flush subexpressions. This is both to prevent the compounding size issue that
  1957. // occurs when the code has to be duplicated for inlining and also to prevent errors
  1958. // due to the incorrect options object being passed due to the shared register.
  1959. if (!isRoot) {
  1960. this.flushInline();
  1961. }
  1962. },
  1963. // [invokeKnownHelper]
  1964. //
  1965. // On stack, before: hash, inverse, program, params..., ...
  1966. // On stack, after: result of helper invocation
  1967. //
  1968. // This operation is used when the helper is known to exist,
  1969. // so a `helperMissing` fallback is not required.
  1970. invokeKnownHelper: function(paramSize, name) {
  1971. var helper = this.setupHelper(paramSize, name);
  1972. this.push(helper.name + ".call(" + helper.callParams + ")");
  1973. },
  1974. // [invokeAmbiguous]
  1975. //
  1976. // On stack, before: hash, inverse, program, params..., ...
  1977. // On stack, after: result of disambiguation
  1978. //
  1979. // This operation is used when an expression like `{{foo}}`
  1980. // is provided, but we don't know at compile-time whether it
  1981. // is a helper or a path.
  1982. //
  1983. // This operation emits more code than the other options,
  1984. // and can be avoided by passing the `knownHelpers` and
  1985. // `knownHelpersOnly` flags at compile-time.
  1986. invokeAmbiguous: function(name, helperCall) {
  1987. this.context.aliases.functionType = '"function"';
  1988. this.useRegister('helper');
  1989. this.emptyHash();
  1990. var helper = this.setupHelper(0, name, helperCall);
  1991. var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper');
  1992. var nonHelper = this.nameLookup('depth' + this.lastContext, name, 'context');
  1993. var nextStack = this.nextStack();
  1994. if (helper.paramsInit) {
  1995. this.pushSource(helper.paramsInit);
  1996. }
  1997. this.pushSource('if (helper = ' + helperName + ') { ' + nextStack + ' = helper.call(' + helper.callParams + '); }');
  1998. this.pushSource('else { helper = ' + nonHelper + '; ' + nextStack + ' = typeof helper === functionType ? helper.call(' + helper.callParams + ') : helper; }');
  1999. },
  2000. // [invokePartial]
  2001. //
  2002. // On stack, before: context, ...
  2003. // On stack after: result of partial invocation
  2004. //
  2005. // This operation pops off a context, invokes a partial with that context,
  2006. // and pushes the result of the invocation back.
  2007. invokePartial: function(name) {
  2008. var params = [this.nameLookup('partials', name, 'partial'), "'" + name + "'", this.popStack(), "helpers", "partials"];
  2009. if (this.options.data) {
  2010. params.push("data");
  2011. }
  2012. this.context.aliases.self = "this";
  2013. this.push("self.invokePartial(" + params.join(", ") + ")");
  2014. },
  2015. // [assignToHash]
  2016. //
  2017. // On stack, before: value, hash, ...
  2018. // On stack, after: hash, ...
  2019. //
  2020. // Pops a value and hash off the stack, assigns `hash[key] = value`
  2021. // and pushes the hash back onto the stack.
  2022. assignToHash: function(key) {
  2023. var value = this.popStack(),
  2024. context,
  2025. type;
  2026. if (this.options.stringParams) {
  2027. type = this.popStack();
  2028. context = this.popStack();
  2029. }
  2030. var hash = this.hash;
  2031. if (context) {
  2032. hash.contexts.push("'" + key + "': " + context);
  2033. }
  2034. if (type) {
  2035. hash.types.push("'" + key + "': " + type);
  2036. }
  2037. hash.values.push("'" + key + "': (" + value + ")");
  2038. },
  2039. // HELPERS
  2040. compiler: JavaScriptCompiler,
  2041. compileChildren: function(environment, options) {
  2042. var children = environment.children, child, compiler;
  2043. for(var i=0, l=children.length; i<l; i++) {
  2044. child = children[i];
  2045. compiler = new this.compiler();
  2046. var index = this.matchExistingProgram(child);
  2047. if (index == null) {
  2048. this.context.programs.push(''); // Placeholder to prevent name conflicts for nested children
  2049. index = this.context.programs.length;
  2050. child.index = index;
  2051. child.name = 'program' + index;
  2052. this.context.programs[index] = compiler.compile(child, options, this.context);
  2053. this.context.environments[index] = child;
  2054. } else {
  2055. child.index = index;
  2056. child.name = 'program' + index;
  2057. }
  2058. }
  2059. },
  2060. matchExistingProgram: function(child) {
  2061. for (var i = 0, len = this.context.environments.length; i < len; i++) {
  2062. var environment = this.context.environments[i];
  2063. if (environment && environment.equals(child)) {
  2064. return i;
  2065. }
  2066. }
  2067. },
  2068. programExpression: function(guid) {
  2069. this.context.aliases.self = "this";
  2070. if(guid == null) {
  2071. return "self.noop";
  2072. }
  2073. var child = this.environment.children[guid],
  2074. depths = child.depths.list, depth;
  2075. var programParams = [child.index, child.name, "data"];
  2076. for(var i=0, l = depths.length; i<l; i++) {
  2077. depth = depths[i];
  2078. if(depth === 1) { programParams.push("depth0"); }
  2079. else { programParams.push("depth" + (depth - 1)); }
  2080. }
  2081. return (depths.length === 0 ? "self.program(" : "self.programWithDepth(") + programParams.join(", ") + ")";
  2082. },
  2083. register: function(name, val) {
  2084. this.useRegister(name);
  2085. this.pushSource(name + " = " + val + ";");
  2086. },
  2087. useRegister: function(name) {
  2088. if(!this.registers[name]) {
  2089. this.registers[name] = true;
  2090. this.registers.list.push(name);
  2091. }
  2092. },
  2093. pushStackLiteral: function(item) {
  2094. return this.push(new Literal(item));
  2095. },
  2096. pushSource: function(source) {
  2097. if (this.pendingContent) {
  2098. this.source.push(this.appendToBuffer(this.quotedString(this.pendingContent)));
  2099. this.pendingContent = undefined;
  2100. }
  2101. if (source) {
  2102. this.source.push(source);
  2103. }
  2104. },
  2105. pushStack: function(item) {
  2106. this.flushInline();
  2107. var stack = this.incrStack();
  2108. if (item) {
  2109. this.pushSource(stack + " = " + item + ";");
  2110. }
  2111. this.compileStack.push(stack);
  2112. return stack;
  2113. },
  2114. replaceStack: function(callback) {
  2115. var prefix = '',
  2116. inline = this.isInline(),
  2117. stack,
  2118. createdStack,
  2119. usedLiteral;
  2120. // If we are currently inline then we want to merge the inline statement into the
  2121. // replacement statement via ','
  2122. if (inline) {
  2123. var top = this.popStack(true);
  2124. if (top instanceof Literal) {
  2125. // Literals do not need to be inlined
  2126. stack = top.value;
  2127. usedLiteral = true;
  2128. } else {
  2129. // Get or create the current stack name for use by the inline
  2130. createdStack = !this.stackSlot;
  2131. var name = !createdStack ? this.topStackName() : this.incrStack();
  2132. prefix = '(' + this.push(name) + ' = ' + top + '),';
  2133. stack = this.topStack();
  2134. }
  2135. } else {
  2136. stack = this.topStack();
  2137. }
  2138. var item = callback.call(this, stack);
  2139. if (inline) {
  2140. if (!usedLiteral) {
  2141. this.popStack();
  2142. }
  2143. if (createdStack) {
  2144. this.stackSlot--;
  2145. }
  2146. this.push('(' + prefix + item + ')');
  2147. } else {
  2148. // Prevent modification of the context depth variable. Through replaceStack
  2149. if (!/^stack/.test(stack)) {
  2150. stack = this.nextStack();
  2151. }
  2152. this.pushSource(stack + " = (" + prefix + item + ");");
  2153. }
  2154. return stack;
  2155. },
  2156. nextStack: function() {
  2157. return this.pushStack();
  2158. },
  2159. incrStack: function() {
  2160. this.stackSlot++;
  2161. if(this.stackSlot > this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); }
  2162. return this.topStackName();
  2163. },
  2164. topStackName: function() {
  2165. return "stack" + this.stackSlot;
  2166. },
  2167. flushInline: function() {
  2168. var inlineStack = this.inlineStack;
  2169. if (inlineStack.length) {
  2170. this.inlineStack = [];
  2171. for (var i = 0, len = inlineStack.length; i < len; i++) {
  2172. var entry = inlineStack[i];
  2173. if (entry instanceof Literal) {
  2174. this.compileStack.push(entry);
  2175. } else {
  2176. this.pushStack(entry);
  2177. }
  2178. }
  2179. }
  2180. },
  2181. isInline: function() {
  2182. return this.inlineStack.length;
  2183. },
  2184. popStack: function(wrapped) {
  2185. var inline = this.isInline(),
  2186. item = (inline ? this.inlineStack : this.compileStack).pop();
  2187. if (!wrapped && (item instanceof Literal)) {
  2188. return item.value;
  2189. } else {
  2190. if (!inline) {
  2191. if (!this.stackSlot) {
  2192. throw new Exception('Invalid stack pop');
  2193. }
  2194. this.stackSlot--;
  2195. }
  2196. return item;
  2197. }
  2198. },
  2199. topStack: function(wrapped) {
  2200. var stack = (this.isInline() ? this.inlineStack : this.compileStack),
  2201. item = stack[stack.length - 1];
  2202. if (!wrapped && (item instanceof Literal)) {
  2203. return item.value;
  2204. } else {
  2205. return item;
  2206. }
  2207. },
  2208. quotedString: function(str) {
  2209. return '"' + str
  2210. .replace(/\\/g, '\\\\')
  2211. .replace(/"/g, '\\"')
  2212. .replace(/\n/g, '\\n')
  2213. .replace(/\r/g, '\\r')
  2214. .replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
  2215. .replace(/\u2029/g, '\\u2029') + '"';
  2216. },
  2217. setupHelper: function(paramSize, name, missingParams) {
  2218. var params = [],
  2219. paramsInit = this.setupParams(paramSize, params, missingParams);
  2220. var foundHelper = this.nameLookup('helpers', name, 'helper');
  2221. return {
  2222. params: params,
  2223. paramsInit: paramsInit,
  2224. name: foundHelper,
  2225. callParams: ["depth0"].concat(params).join(", "),
  2226. helperMissingParams: missingParams && ["depth0", this.quotedString(name)].concat(params).join(", ")
  2227. };
  2228. },
  2229. setupOptions: function(paramSize, params) {
  2230. var options = [], contexts = [], types = [], param, inverse, program;
  2231. options.push("hash:" + this.popStack());
  2232. if (this.options.stringParams) {
  2233. options.push("hashTypes:" + this.popStack());
  2234. options.push("hashContexts:" + this.popStack());
  2235. }
  2236. inverse = this.popStack();
  2237. program = this.popStack();
  2238. // Avoid setting fn and inverse if neither are set. This allows
  2239. // helpers to do a check for `if (options.fn)`
  2240. if (program || inverse) {
  2241. if (!program) {
  2242. this.context.aliases.self = "this";
  2243. program = "self.noop";
  2244. }
  2245. if (!inverse) {
  2246. this.context.aliases.self = "this";
  2247. inverse = "self.noop";
  2248. }
  2249. options.push("inverse:" + inverse);
  2250. options.push("fn:" + program);
  2251. }
  2252. for(var i=0; i<paramSize; i++) {
  2253. param = this.popStack();
  2254. params.push(param);
  2255. if(this.options.stringParams) {
  2256. types.push(this.popStack());
  2257. contexts.push(this.popStack());
  2258. }
  2259. }
  2260. if (this.options.stringParams) {
  2261. options.push("contexts:[" + contexts.join(",") + "]");
  2262. options.push("types:[" + types.join(",") + "]");
  2263. }
  2264. if(this.options.data) {
  2265. options.push("data:data");
  2266. }
  2267. return options;
  2268. },
  2269. // the params and contexts arguments are passed in arrays
  2270. // to fill in
  2271. setupParams: function(paramSize, params, useRegister) {
  2272. var options = '{' + this.setupOptions(paramSize, params).join(',') + '}';
  2273. if (useRegister) {
  2274. this.useRegister('options');
  2275. params.push('options');
  2276. return 'options=' + options;
  2277. } else {
  2278. params.push(options);
  2279. return '';
  2280. }
  2281. }
  2282. };
  2283. var reservedWords = (
  2284. "break else new var" +
  2285. " case finally return void" +
  2286. " catch for switch while" +
  2287. " continue function this with" +
  2288. " default if throw" +
  2289. " delete in try" +
  2290. " do instanceof typeof" +
  2291. " abstract enum int short" +
  2292. " boolean export interface static" +
  2293. " byte extends long super" +
  2294. " char final native synchronized" +
  2295. " class float package throws" +
  2296. " const goto private transient" +
  2297. " debugger implements protected volatile" +
  2298. " double import public let yield"
  2299. ).split(" ");
  2300. var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
  2301. for(var i=0, l=reservedWords.length; i<l; i++) {
  2302. compilerWords[reservedWords[i]] = true;
  2303. }
  2304. JavaScriptCompiler.isValidJavaScriptVariableName = function(name) {
  2305. if(!JavaScriptCompiler.RESERVED_WORDS[name] && /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(name)) {
  2306. return true;
  2307. }
  2308. return false;
  2309. };
  2310. __exports__ = JavaScriptCompiler;
  2311. return __exports__;
  2312. })(__module2__, __module5__);
  2313. // handlebars.js
  2314. var __module0__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__) {
  2315. "use strict";
  2316. var __exports__;
  2317. /*globals Handlebars: true */
  2318. var Handlebars = __dependency1__;
  2319. // Compiler imports
  2320. var AST = __dependency2__;
  2321. var Parser = __dependency3__.parser;
  2322. var parse = __dependency3__.parse;
  2323. var Compiler = __dependency4__.Compiler;
  2324. var compile = __dependency4__.compile;
  2325. var precompile = __dependency4__.precompile;
  2326. var JavaScriptCompiler = __dependency5__;
  2327. var _create = Handlebars.create;
  2328. var create = function() {
  2329. var hb = _create();
  2330. hb.compile = function(input, options) {
  2331. return compile(input, options, hb);
  2332. };
  2333. hb.precompile = function (input, options) {
  2334. return precompile(input, options, hb);
  2335. };
  2336. hb.AST = AST;
  2337. hb.Compiler = Compiler;
  2338. hb.JavaScriptCompiler = JavaScriptCompiler;
  2339. hb.Parser = Parser;
  2340. hb.parse = parse;
  2341. return hb;
  2342. };
  2343. Handlebars = create();
  2344. Handlebars.create = create;
  2345. __exports__ = Handlebars;
  2346. return __exports__;
  2347. })(__module1__, __module7__, __module8__, __module10__, __module11__);
  2348. return __module0__;
  2349. })();