nunjucks-slim.js 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165
  1. /*! Browser bundle of nunjucks 3.2.0 (slim, only works with precompiled templates) */
  2. (function webpackUniversalModuleDefinition(root, factory) {
  3. if(typeof exports === 'object' && typeof module === 'object')
  4. module.exports = factory();
  5. else if(typeof define === 'function' && define.amd)
  6. define([], factory);
  7. else if(typeof exports === 'object')
  8. exports["nunjucks"] = factory();
  9. else
  10. root["nunjucks"] = factory();
  11. })(typeof self !== 'undefined' ? self : this, function() {
  12. return /******/ (function(modules) { // webpackBootstrap
  13. /******/ // The module cache
  14. /******/ var installedModules = {};
  15. /******/
  16. /******/ // The require function
  17. /******/ function __webpack_require__(moduleId) {
  18. /******/
  19. /******/ // Check if module is in cache
  20. /******/ if(installedModules[moduleId]) {
  21. /******/ return installedModules[moduleId].exports;
  22. /******/ }
  23. /******/ // Create a new module (and put it into the cache)
  24. /******/ var module = installedModules[moduleId] = {
  25. /******/ i: moduleId,
  26. /******/ l: false,
  27. /******/ exports: {}
  28. /******/ };
  29. /******/
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/
  33. /******/ // Flag the module as loaded
  34. /******/ module.l = true;
  35. /******/
  36. /******/ // Return the exports of the module
  37. /******/ return module.exports;
  38. /******/ }
  39. /******/
  40. /******/
  41. /******/ // expose the modules object (__webpack_modules__)
  42. /******/ __webpack_require__.m = modules;
  43. /******/
  44. /******/ // expose the module cache
  45. /******/ __webpack_require__.c = installedModules;
  46. /******/
  47. /******/ // define getter function for harmony exports
  48. /******/ __webpack_require__.d = function(exports, name, getter) {
  49. /******/ if(!__webpack_require__.o(exports, name)) {
  50. /******/ Object.defineProperty(exports, name, {
  51. /******/ configurable: false,
  52. /******/ enumerable: true,
  53. /******/ get: getter
  54. /******/ });
  55. /******/ }
  56. /******/ };
  57. /******/
  58. /******/ // getDefaultExport function for compatibility with non-harmony modules
  59. /******/ __webpack_require__.n = function(module) {
  60. /******/ var getter = module && module.__esModule ?
  61. /******/ function getDefault() { return module['default']; } :
  62. /******/ function getModuleExports() { return module; };
  63. /******/ __webpack_require__.d(getter, 'a', getter);
  64. /******/ return getter;
  65. /******/ };
  66. /******/
  67. /******/ // Object.prototype.hasOwnProperty.call
  68. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  69. /******/
  70. /******/ // __webpack_public_path__
  71. /******/ __webpack_require__.p = "";
  72. /******/
  73. /******/ // Load entry module and return exports
  74. /******/ return __webpack_require__(__webpack_require__.s = 6);
  75. /******/ })
  76. /************************************************************************/
  77. /******/ ([
  78. /* 0 */
  79. /***/ (function(module, exports) {
  80. /***/ }),
  81. /* 1 */
  82. /***/ (function(module, exports, __webpack_require__) {
  83. "use strict";
  84. var ArrayProto = Array.prototype;
  85. var ObjProto = Object.prototype;
  86. var escapeMap = {
  87. '&': '&',
  88. '"': '"',
  89. '\'': ''',
  90. '<': '&lt;',
  91. '>': '&gt;'
  92. };
  93. var escapeRegex = /[&"'<>]/g;
  94. var exports = module.exports = {};
  95. function hasOwnProp(obj, k) {
  96. return ObjProto.hasOwnProperty.call(obj, k);
  97. }
  98. exports.hasOwnProp = hasOwnProp;
  99. function lookupEscape(ch) {
  100. return escapeMap[ch];
  101. }
  102. function _prettifyError(path, withInternals, err) {
  103. if (!err.Update) {
  104. // not one of ours, cast it
  105. err = new exports.TemplateError(err);
  106. }
  107. err.Update(path); // Unless they marked the dev flag, show them a trace from here
  108. if (!withInternals) {
  109. var old = err;
  110. err = new Error(old.message);
  111. err.name = old.name;
  112. }
  113. return err;
  114. }
  115. exports._prettifyError = _prettifyError;
  116. function TemplateError(message, lineno, colno) {
  117. var err;
  118. var cause;
  119. if (message instanceof Error) {
  120. cause = message;
  121. message = cause.name + ": " + cause.message;
  122. }
  123. if (Object.setPrototypeOf) {
  124. err = new Error(message);
  125. Object.setPrototypeOf(err, TemplateError.prototype);
  126. } else {
  127. err = this;
  128. Object.defineProperty(err, 'message', {
  129. enumerable: false,
  130. writable: true,
  131. value: message
  132. });
  133. }
  134. Object.defineProperty(err, 'name', {
  135. value: 'Template render error'
  136. });
  137. if (Error.captureStackTrace) {
  138. Error.captureStackTrace(err, this.constructor);
  139. }
  140. var getStack;
  141. if (cause) {
  142. var stackDescriptor = Object.getOwnPropertyDescriptor(cause, 'stack');
  143. getStack = stackDescriptor && (stackDescriptor.get || function () {
  144. return stackDescriptor.value;
  145. });
  146. if (!getStack) {
  147. getStack = function getStack() {
  148. return cause.stack;
  149. };
  150. }
  151. } else {
  152. var stack = new Error(message).stack;
  153. getStack = function getStack() {
  154. return stack;
  155. };
  156. }
  157. Object.defineProperty(err, 'stack', {
  158. get: function get() {
  159. return getStack.call(err);
  160. }
  161. });
  162. Object.defineProperty(err, 'cause', {
  163. value: cause
  164. });
  165. err.lineno = lineno;
  166. err.colno = colno;
  167. err.firstUpdate = true;
  168. err.Update = function Update(path) {
  169. var msg = '(' + (path || 'unknown path') + ')'; // only show lineno + colno next to path of template
  170. // where error occurred
  171. if (this.firstUpdate) {
  172. if (this.lineno && this.colno) {
  173. msg += " [Line " + this.lineno + ", Column " + this.colno + "]";
  174. } else if (this.lineno) {
  175. msg += " [Line " + this.lineno + "]";
  176. }
  177. }
  178. msg += '\n ';
  179. if (this.firstUpdate) {
  180. msg += ' ';
  181. }
  182. this.message = msg + (this.message || '');
  183. this.firstUpdate = false;
  184. return this;
  185. };
  186. return err;
  187. }
  188. if (Object.setPrototypeOf) {
  189. Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
  190. } else {
  191. TemplateError.prototype = Object.create(Error.prototype, {
  192. constructor: {
  193. value: TemplateError
  194. }
  195. });
  196. }
  197. exports.TemplateError = TemplateError;
  198. function escape(val) {
  199. return val.replace(escapeRegex, lookupEscape);
  200. }
  201. exports.escape = escape;
  202. function isFunction(obj) {
  203. return ObjProto.toString.call(obj) === '[object Function]';
  204. }
  205. exports.isFunction = isFunction;
  206. function isArray(obj) {
  207. return ObjProto.toString.call(obj) === '[object Array]';
  208. }
  209. exports.isArray = isArray;
  210. function isString(obj) {
  211. return ObjProto.toString.call(obj) === '[object String]';
  212. }
  213. exports.isString = isString;
  214. function isObject(obj) {
  215. return ObjProto.toString.call(obj) === '[object Object]';
  216. }
  217. exports.isObject = isObject;
  218. function groupBy(obj, val) {
  219. var result = {};
  220. var iterator = isFunction(val) ? val : function (o) {
  221. return o[val];
  222. };
  223. for (var i = 0; i < obj.length; i++) {
  224. var value = obj[i];
  225. var key = iterator(value, i);
  226. (result[key] || (result[key] = [])).push(value);
  227. }
  228. return result;
  229. }
  230. exports.groupBy = groupBy;
  231. function toArray(obj) {
  232. return Array.prototype.slice.call(obj);
  233. }
  234. exports.toArray = toArray;
  235. function without(array) {
  236. var result = [];
  237. if (!array) {
  238. return result;
  239. }
  240. var length = array.length;
  241. var contains = toArray(arguments).slice(1);
  242. var index = -1;
  243. while (++index < length) {
  244. if (indexOf(contains, array[index]) === -1) {
  245. result.push(array[index]);
  246. }
  247. }
  248. return result;
  249. }
  250. exports.without = without;
  251. function repeat(char_, n) {
  252. var str = '';
  253. for (var i = 0; i < n; i++) {
  254. str += char_;
  255. }
  256. return str;
  257. }
  258. exports.repeat = repeat;
  259. function each(obj, func, context) {
  260. if (obj == null) {
  261. return;
  262. }
  263. if (ArrayProto.forEach && obj.forEach === ArrayProto.forEach) {
  264. obj.forEach(func, context);
  265. } else if (obj.length === +obj.length) {
  266. for (var i = 0, l = obj.length; i < l; i++) {
  267. func.call(context, obj[i], i, obj);
  268. }
  269. }
  270. }
  271. exports.each = each;
  272. function map(obj, func) {
  273. var results = [];
  274. if (obj == null) {
  275. return results;
  276. }
  277. if (ArrayProto.map && obj.map === ArrayProto.map) {
  278. return obj.map(func);
  279. }
  280. for (var i = 0; i < obj.length; i++) {
  281. results[results.length] = func(obj[i], i);
  282. }
  283. if (obj.length === +obj.length) {
  284. results.length = obj.length;
  285. }
  286. return results;
  287. }
  288. exports.map = map;
  289. function asyncIter(arr, iter, cb) {
  290. var i = -1;
  291. function next() {
  292. i++;
  293. if (i < arr.length) {
  294. iter(arr[i], i, next, cb);
  295. } else {
  296. cb();
  297. }
  298. }
  299. next();
  300. }
  301. exports.asyncIter = asyncIter;
  302. function asyncFor(obj, iter, cb) {
  303. var keys = keys_(obj || {});
  304. var len = keys.length;
  305. var i = -1;
  306. function next() {
  307. i++;
  308. var k = keys[i];
  309. if (i < len) {
  310. iter(k, obj[k], i, len, next);
  311. } else {
  312. cb();
  313. }
  314. }
  315. next();
  316. }
  317. exports.asyncFor = asyncFor;
  318. function indexOf(arr, searchElement, fromIndex) {
  319. return Array.prototype.indexOf.call(arr || [], searchElement, fromIndex);
  320. }
  321. exports.indexOf = indexOf;
  322. function keys_(obj) {
  323. /* eslint-disable no-restricted-syntax */
  324. var arr = [];
  325. for (var k in obj) {
  326. if (hasOwnProp(obj, k)) {
  327. arr.push(k);
  328. }
  329. }
  330. return arr;
  331. }
  332. exports.keys = keys_;
  333. function _entries(obj) {
  334. return keys_(obj).map(function (k) {
  335. return [k, obj[k]];
  336. });
  337. }
  338. exports._entries = _entries;
  339. function _values(obj) {
  340. return keys_(obj).map(function (k) {
  341. return obj[k];
  342. });
  343. }
  344. exports._values = _values;
  345. function extend(obj1, obj2) {
  346. obj1 = obj1 || {};
  347. keys_(obj2).forEach(function (k) {
  348. obj1[k] = obj2[k];
  349. });
  350. return obj1;
  351. }
  352. exports._assign = exports.extend = extend;
  353. function inOperator(key, val) {
  354. if (isArray(val) || isString(val)) {
  355. return val.indexOf(key) !== -1;
  356. } else if (isObject(val)) {
  357. return key in val;
  358. }
  359. throw new Error('Cannot use "in" operator to search for "' + key + '" in unexpected types.');
  360. }
  361. exports.inOperator = inOperator;
  362. /***/ }),
  363. /* 2 */
  364. /***/ (function(module, exports, __webpack_require__) {
  365. "use strict";
  366. var lib = __webpack_require__(1);
  367. var arrayFrom = Array.from;
  368. var supportsIterators = typeof Symbol === 'function' && Symbol.iterator && typeof arrayFrom === 'function'; // Frames keep track of scoping both at compile-time and run-time so
  369. // we know how to access variables. Block tags can introduce special
  370. // variables, for example.
  371. var Frame =
  372. /*#__PURE__*/
  373. function () {
  374. function Frame(parent, isolateWrites) {
  375. this.variables = {};
  376. this.parent = parent;
  377. this.topLevel = false; // if this is true, writes (set) should never propagate upwards past
  378. // this frame to its parent (though reads may).
  379. this.isolateWrites = isolateWrites;
  380. }
  381. var _proto = Frame.prototype;
  382. _proto.set = function set(name, val, resolveUp) {
  383. // Allow variables with dots by automatically creating the
  384. // nested structure
  385. var parts = name.split('.');
  386. var obj = this.variables;
  387. var frame = this;
  388. if (resolveUp) {
  389. if (frame = this.resolve(parts[0], true)) {
  390. frame.set(name, val);
  391. return;
  392. }
  393. }
  394. for (var i = 0; i < parts.length - 1; i++) {
  395. var id = parts[i];
  396. if (!obj[id]) {
  397. obj[id] = {};
  398. }
  399. obj = obj[id];
  400. }
  401. obj[parts[parts.length - 1]] = val;
  402. };
  403. _proto.get = function get(name) {
  404. var val = this.variables[name];
  405. if (val !== undefined) {
  406. return val;
  407. }
  408. return null;
  409. };
  410. _proto.lookup = function lookup(name) {
  411. var p = this.parent;
  412. var val = this.variables[name];
  413. if (val !== undefined) {
  414. return val;
  415. }
  416. return p && p.lookup(name);
  417. };
  418. _proto.resolve = function resolve(name, forWrite) {
  419. var p = forWrite && this.isolateWrites ? undefined : this.parent;
  420. var val = this.variables[name];
  421. if (val !== undefined) {
  422. return this;
  423. }
  424. return p && p.resolve(name);
  425. };
  426. _proto.push = function push(isolateWrites) {
  427. return new Frame(this, isolateWrites);
  428. };
  429. _proto.pop = function pop() {
  430. return this.parent;
  431. };
  432. return Frame;
  433. }();
  434. function makeMacro(argNames, kwargNames, func) {
  435. var _this = this;
  436. return function () {
  437. for (var _len = arguments.length, macroArgs = new Array(_len), _key = 0; _key < _len; _key++) {
  438. macroArgs[_key] = arguments[_key];
  439. }
  440. var argCount = numArgs(macroArgs);
  441. var args;
  442. var kwargs = getKeywordArgs(macroArgs);
  443. if (argCount > argNames.length) {
  444. args = macroArgs.slice(0, argNames.length); // Positional arguments that should be passed in as
  445. // keyword arguments (essentially default values)
  446. macroArgs.slice(args.length, argCount).forEach(function (val, i) {
  447. if (i < kwargNames.length) {
  448. kwargs[kwargNames[i]] = val;
  449. }
  450. });
  451. args.push(kwargs);
  452. } else if (argCount < argNames.length) {
  453. args = macroArgs.slice(0, argCount);
  454. for (var i = argCount; i < argNames.length; i++) {
  455. var arg = argNames[i]; // Keyword arguments that should be passed as
  456. // positional arguments, i.e. the caller explicitly
  457. // used the name of a positional arg
  458. args.push(kwargs[arg]);
  459. delete kwargs[arg];
  460. }
  461. args.push(kwargs);
  462. } else {
  463. args = macroArgs;
  464. }
  465. return func.apply(_this, args);
  466. };
  467. }
  468. function makeKeywordArgs(obj) {
  469. obj.__keywords = true;
  470. return obj;
  471. }
  472. function isKeywordArgs(obj) {
  473. return obj && Object.prototype.hasOwnProperty.call(obj, '__keywords');
  474. }
  475. function getKeywordArgs(args) {
  476. var len = args.length;
  477. if (len) {
  478. var lastArg = args[len - 1];
  479. if (isKeywordArgs(lastArg)) {
  480. return lastArg;
  481. }
  482. }
  483. return {};
  484. }
  485. function numArgs(args) {
  486. var len = args.length;
  487. if (len === 0) {
  488. return 0;
  489. }
  490. var lastArg = args[len - 1];
  491. if (isKeywordArgs(lastArg)) {
  492. return len - 1;
  493. } else {
  494. return len;
  495. }
  496. } // A SafeString object indicates that the string should not be
  497. // autoescaped. This happens magically because autoescaping only
  498. // occurs on primitive string objects.
  499. function SafeString(val) {
  500. if (typeof val !== 'string') {
  501. return val;
  502. }
  503. this.val = val;
  504. this.length = val.length;
  505. }
  506. SafeString.prototype = Object.create(String.prototype, {
  507. length: {
  508. writable: true,
  509. configurable: true,
  510. value: 0
  511. }
  512. });
  513. SafeString.prototype.valueOf = function valueOf() {
  514. return this.val;
  515. };
  516. SafeString.prototype.toString = function toString() {
  517. return this.val;
  518. };
  519. function copySafeness(dest, target) {
  520. if (dest instanceof SafeString) {
  521. return new SafeString(target);
  522. }
  523. return target.toString();
  524. }
  525. function markSafe(val) {
  526. var type = typeof val;
  527. if (type === 'string') {
  528. return new SafeString(val);
  529. } else if (type !== 'function') {
  530. return val;
  531. } else {
  532. return function wrapSafe(args) {
  533. var ret = val.apply(this, arguments);
  534. if (typeof ret === 'string') {
  535. return new SafeString(ret);
  536. }
  537. return ret;
  538. };
  539. }
  540. }
  541. function suppressValue(val, autoescape) {
  542. val = val !== undefined && val !== null ? val : '';
  543. if (autoescape && !(val instanceof SafeString)) {
  544. val = lib.escape(val.toString());
  545. }
  546. return val;
  547. }
  548. function ensureDefined(val, lineno, colno) {
  549. if (val === null || val === undefined) {
  550. throw new lib.TemplateError('attempted to output null or undefined value', lineno + 1, colno + 1);
  551. }
  552. return val;
  553. }
  554. function memberLookup(obj, val) {
  555. if (obj === undefined || obj === null) {
  556. return undefined;
  557. }
  558. if (typeof obj[val] === 'function') {
  559. return function () {
  560. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  561. args[_key2] = arguments[_key2];
  562. }
  563. return obj[val].apply(obj, args);
  564. };
  565. }
  566. return obj[val];
  567. }
  568. function callWrap(obj, name, context, args) {
  569. if (!obj) {
  570. throw new Error('Unable to call `' + name + '`, which is undefined or falsey');
  571. } else if (typeof obj !== 'function') {
  572. throw new Error('Unable to call `' + name + '`, which is not a function');
  573. }
  574. return obj.apply(context, args);
  575. }
  576. function contextOrFrameLookup(context, frame, name) {
  577. var val = frame.lookup(name);
  578. return val !== undefined ? val : context.lookup(name);
  579. }
  580. function handleError(error, lineno, colno) {
  581. if (error.lineno) {
  582. return error;
  583. } else {
  584. return new lib.TemplateError(error, lineno, colno);
  585. }
  586. }
  587. function asyncEach(arr, dimen, iter, cb) {
  588. if (lib.isArray(arr)) {
  589. var len = arr.length;
  590. lib.asyncIter(arr, function iterCallback(item, i, next) {
  591. switch (dimen) {
  592. case 1:
  593. iter(item, i, len, next);
  594. break;
  595. case 2:
  596. iter(item[0], item[1], i, len, next);
  597. break;
  598. case 3:
  599. iter(item[0], item[1], item[2], i, len, next);
  600. break;
  601. default:
  602. item.push(i, len, next);
  603. iter.apply(this, item);
  604. }
  605. }, cb);
  606. } else {
  607. lib.asyncFor(arr, function iterCallback(key, val, i, len, next) {
  608. iter(key, val, i, len, next);
  609. }, cb);
  610. }
  611. }
  612. function asyncAll(arr, dimen, func, cb) {
  613. var finished = 0;
  614. var len;
  615. var outputArr;
  616. function done(i, output) {
  617. finished++;
  618. outputArr[i] = output;
  619. if (finished === len) {
  620. cb(null, outputArr.join(''));
  621. }
  622. }
  623. if (lib.isArray(arr)) {
  624. len = arr.length;
  625. outputArr = new Array(len);
  626. if (len === 0) {
  627. cb(null, '');
  628. } else {
  629. for (var i = 0; i < arr.length; i++) {
  630. var item = arr[i];
  631. switch (dimen) {
  632. case 1:
  633. func(item, i, len, done);
  634. break;
  635. case 2:
  636. func(item[0], item[1], i, len, done);
  637. break;
  638. case 3:
  639. func(item[0], item[1], item[2], i, len, done);
  640. break;
  641. default:
  642. item.push(i, len, done);
  643. func.apply(this, item);
  644. }
  645. }
  646. }
  647. } else {
  648. var keys = lib.keys(arr || {});
  649. len = keys.length;
  650. outputArr = new Array(len);
  651. if (len === 0) {
  652. cb(null, '');
  653. } else {
  654. for (var _i = 0; _i < keys.length; _i++) {
  655. var k = keys[_i];
  656. func(k, arr[k], _i, len, done);
  657. }
  658. }
  659. }
  660. }
  661. function fromIterator(arr) {
  662. if (typeof arr !== 'object' || arr === null || lib.isArray(arr)) {
  663. return arr;
  664. } else if (supportsIterators && Symbol.iterator in arr) {
  665. return arrayFrom(arr);
  666. } else {
  667. return arr;
  668. }
  669. }
  670. module.exports = {
  671. Frame: Frame,
  672. makeMacro: makeMacro,
  673. makeKeywordArgs: makeKeywordArgs,
  674. numArgs: numArgs,
  675. suppressValue: suppressValue,
  676. ensureDefined: ensureDefined,
  677. memberLookup: memberLookup,
  678. contextOrFrameLookup: contextOrFrameLookup,
  679. callWrap: callWrap,
  680. handleError: handleError,
  681. isArray: lib.isArray,
  682. keys: lib.keys,
  683. SafeString: SafeString,
  684. copySafeness: copySafeness,
  685. markSafe: markSafe,
  686. asyncEach: asyncEach,
  687. asyncAll: asyncAll,
  688. inOperator: lib.inOperator,
  689. fromIterator: fromIterator
  690. };
  691. /***/ }),
  692. /* 3 */
  693. /***/ (function(module, exports, __webpack_require__) {
  694. "use strict";
  695. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  696. var Loader = __webpack_require__(4);
  697. var PrecompiledLoader =
  698. /*#__PURE__*/
  699. function (_Loader) {
  700. _inheritsLoose(PrecompiledLoader, _Loader);
  701. function PrecompiledLoader(compiledTemplates) {
  702. var _this;
  703. _this = _Loader.call(this) || this;
  704. _this.precompiled = compiledTemplates || {};
  705. return _this;
  706. }
  707. var _proto = PrecompiledLoader.prototype;
  708. _proto.getSource = function getSource(name) {
  709. if (this.precompiled[name]) {
  710. return {
  711. src: {
  712. type: 'code',
  713. obj: this.precompiled[name]
  714. },
  715. path: name
  716. };
  717. }
  718. return null;
  719. };
  720. return PrecompiledLoader;
  721. }(Loader);
  722. module.exports = {
  723. PrecompiledLoader: PrecompiledLoader
  724. };
  725. /***/ }),
  726. /* 4 */
  727. /***/ (function(module, exports, __webpack_require__) {
  728. "use strict";
  729. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  730. var path = __webpack_require__(0);
  731. var _require = __webpack_require__(5),
  732. EmitterObj = _require.EmitterObj;
  733. module.exports =
  734. /*#__PURE__*/
  735. function (_EmitterObj) {
  736. _inheritsLoose(Loader, _EmitterObj);
  737. function Loader() {
  738. return _EmitterObj.apply(this, arguments) || this;
  739. }
  740. var _proto = Loader.prototype;
  741. _proto.resolve = function resolve(from, to) {
  742. return path.resolve(path.dirname(from), to);
  743. };
  744. _proto.isRelative = function isRelative(filename) {
  745. return filename.indexOf('./') === 0 || filename.indexOf('../') === 0;
  746. };
  747. return Loader;
  748. }(EmitterObj);
  749. /***/ }),
  750. /* 5 */
  751. /***/ (function(module, exports, __webpack_require__) {
  752. "use strict";
  753. // A simple class system, more documentation to come
  754. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  755. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  756. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  757. var EventEmitter = __webpack_require__(13);
  758. var lib = __webpack_require__(1);
  759. function parentWrap(parent, prop) {
  760. if (typeof parent !== 'function' || typeof prop !== 'function') {
  761. return prop;
  762. }
  763. return function wrap() {
  764. // Save the current parent method
  765. var tmp = this.parent; // Set parent to the previous method, call, and restore
  766. this.parent = parent;
  767. var res = prop.apply(this, arguments);
  768. this.parent = tmp;
  769. return res;
  770. };
  771. }
  772. function extendClass(cls, name, props) {
  773. props = props || {};
  774. lib.keys(props).forEach(function (k) {
  775. props[k] = parentWrap(cls.prototype[k], props[k]);
  776. });
  777. var subclass =
  778. /*#__PURE__*/
  779. function (_cls) {
  780. _inheritsLoose(subclass, _cls);
  781. function subclass() {
  782. return _cls.apply(this, arguments) || this;
  783. }
  784. _createClass(subclass, [{
  785. key: "typename",
  786. get: function get() {
  787. return name;
  788. }
  789. }]);
  790. return subclass;
  791. }(cls);
  792. lib._assign(subclass.prototype, props);
  793. return subclass;
  794. }
  795. var Obj =
  796. /*#__PURE__*/
  797. function () {
  798. function Obj() {
  799. // Unfortunately necessary for backwards compatibility
  800. this.init.apply(this, arguments);
  801. }
  802. var _proto = Obj.prototype;
  803. _proto.init = function init() {};
  804. Obj.extend = function extend(name, props) {
  805. if (typeof name === 'object') {
  806. props = name;
  807. name = 'anonymous';
  808. }
  809. return extendClass(this, name, props);
  810. };
  811. _createClass(Obj, [{
  812. key: "typename",
  813. get: function get() {
  814. return this.constructor.name;
  815. }
  816. }]);
  817. return Obj;
  818. }();
  819. var EmitterObj =
  820. /*#__PURE__*/
  821. function (_EventEmitter) {
  822. _inheritsLoose(EmitterObj, _EventEmitter);
  823. function EmitterObj() {
  824. var _this2;
  825. var _this;
  826. _this = _EventEmitter.call(this) || this; // Unfortunately necessary for backwards compatibility
  827. (_this2 = _this).init.apply(_this2, arguments);
  828. return _this;
  829. }
  830. var _proto2 = EmitterObj.prototype;
  831. _proto2.init = function init() {};
  832. EmitterObj.extend = function extend(name, props) {
  833. if (typeof name === 'object') {
  834. props = name;
  835. name = 'anonymous';
  836. }
  837. return extendClass(this, name, props);
  838. };
  839. _createClass(EmitterObj, [{
  840. key: "typename",
  841. get: function get() {
  842. return this.constructor.name;
  843. }
  844. }]);
  845. return EmitterObj;
  846. }(EventEmitter);
  847. module.exports = {
  848. Obj: Obj,
  849. EmitterObj: EmitterObj
  850. };
  851. /***/ }),
  852. /* 6 */
  853. /***/ (function(module, exports, __webpack_require__) {
  854. "use strict";
  855. var lib = __webpack_require__(1);
  856. var _require = __webpack_require__(7),
  857. Environment = _require.Environment,
  858. Template = _require.Template;
  859. var Loader = __webpack_require__(4);
  860. var loaders = __webpack_require__(3);
  861. var precompile = __webpack_require__(0);
  862. var compiler = __webpack_require__(0);
  863. var parser = __webpack_require__(0);
  864. var lexer = __webpack_require__(0);
  865. var runtime = __webpack_require__(2);
  866. var nodes = __webpack_require__(0);
  867. var installJinjaCompat = __webpack_require__(17); // A single instance of an environment, since this is so commonly used
  868. var e;
  869. function configure(templatesPath, opts) {
  870. opts = opts || {};
  871. if (lib.isObject(templatesPath)) {
  872. opts = templatesPath;
  873. templatesPath = null;
  874. }
  875. var TemplateLoader;
  876. if (loaders.FileSystemLoader) {
  877. TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
  878. watch: opts.watch,
  879. noCache: opts.noCache
  880. });
  881. } else if (loaders.WebLoader) {
  882. TemplateLoader = new loaders.WebLoader(templatesPath, {
  883. useCache: opts.web && opts.web.useCache,
  884. async: opts.web && opts.web.async
  885. });
  886. }
  887. e = new Environment(TemplateLoader, opts);
  888. if (opts && opts.express) {
  889. e.express(opts.express);
  890. }
  891. return e;
  892. }
  893. module.exports = {
  894. Environment: Environment,
  895. Template: Template,
  896. Loader: Loader,
  897. FileSystemLoader: loaders.FileSystemLoader,
  898. NodeResolveLoader: loaders.NodeResolveLoader,
  899. PrecompiledLoader: loaders.PrecompiledLoader,
  900. WebLoader: loaders.WebLoader,
  901. compiler: compiler,
  902. parser: parser,
  903. lexer: lexer,
  904. runtime: runtime,
  905. lib: lib,
  906. nodes: nodes,
  907. installJinjaCompat: installJinjaCompat,
  908. configure: configure,
  909. reset: function reset() {
  910. e = undefined;
  911. },
  912. compile: function compile(src, env, path, eagerCompile) {
  913. if (!e) {
  914. configure();
  915. }
  916. return new Template(src, env, path, eagerCompile);
  917. },
  918. render: function render(name, ctx, cb) {
  919. if (!e) {
  920. configure();
  921. }
  922. return e.render(name, ctx, cb);
  923. },
  924. renderString: function renderString(src, ctx, cb) {
  925. if (!e) {
  926. configure();
  927. }
  928. return e.renderString(src, ctx, cb);
  929. },
  930. precompile: precompile ? precompile.precompile : undefined,
  931. precompileString: precompile ? precompile.precompileString : undefined
  932. };
  933. /***/ }),
  934. /* 7 */
  935. /***/ (function(module, exports, __webpack_require__) {
  936. "use strict";
  937. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  938. var asap = __webpack_require__(8);
  939. var _waterfall = __webpack_require__(11);
  940. var lib = __webpack_require__(1);
  941. var compiler = __webpack_require__(0);
  942. var filters = __webpack_require__(12);
  943. var _require = __webpack_require__(3),
  944. FileSystemLoader = _require.FileSystemLoader,
  945. WebLoader = _require.WebLoader,
  946. PrecompiledLoader = _require.PrecompiledLoader;
  947. var tests = __webpack_require__(14);
  948. var globals = __webpack_require__(15);
  949. var _require2 = __webpack_require__(5),
  950. Obj = _require2.Obj,
  951. EmitterObj = _require2.EmitterObj;
  952. var globalRuntime = __webpack_require__(2);
  953. var handleError = globalRuntime.handleError,
  954. Frame = globalRuntime.Frame;
  955. var expressApp = __webpack_require__(16); // If the user is using the async API, *always* call it
  956. // asynchronously even if the template was synchronous.
  957. function callbackAsap(cb, err, res) {
  958. asap(function () {
  959. cb(err, res);
  960. });
  961. }
  962. /**
  963. * A no-op template, for use with {% include ignore missing %}
  964. */
  965. var noopTmplSrc = {
  966. type: 'code',
  967. obj: {
  968. root: function root(env, context, frame, runtime, cb) {
  969. try {
  970. cb(null, '');
  971. } catch (e) {
  972. cb(handleError(e, null, null));
  973. }
  974. }
  975. }
  976. };
  977. var Environment =
  978. /*#__PURE__*/
  979. function (_EmitterObj) {
  980. _inheritsLoose(Environment, _EmitterObj);
  981. function Environment() {
  982. return _EmitterObj.apply(this, arguments) || this;
  983. }
  984. var _proto = Environment.prototype;
  985. _proto.init = function init(loaders, opts) {
  986. var _this = this;
  987. // The dev flag determines the trace that'll be shown on errors.
  988. // If set to true, returns the full trace from the error point,
  989. // otherwise will return trace starting from Template.render
  990. // (the full trace from within nunjucks may confuse developers using
  991. // the library)
  992. // defaults to false
  993. opts = this.opts = opts || {};
  994. this.opts.dev = !!opts.dev; // The autoescape flag sets global autoescaping. If true,
  995. // every string variable will be escaped by default.
  996. // If false, strings can be manually escaped using the `escape` filter.
  997. // defaults to true
  998. this.opts.autoescape = opts.autoescape != null ? opts.autoescape : true; // If true, this will make the system throw errors if trying
  999. // to output a null or undefined value
  1000. this.opts.throwOnUndefined = !!opts.throwOnUndefined;
  1001. this.opts.trimBlocks = !!opts.trimBlocks;
  1002. this.opts.lstripBlocks = !!opts.lstripBlocks;
  1003. this.loaders = [];
  1004. if (!loaders) {
  1005. // The filesystem loader is only available server-side
  1006. if (FileSystemLoader) {
  1007. this.loaders = [new FileSystemLoader('views')];
  1008. } else if (WebLoader) {
  1009. this.loaders = [new WebLoader('/views')];
  1010. }
  1011. } else {
  1012. this.loaders = lib.isArray(loaders) ? loaders : [loaders];
  1013. } // It's easy to use precompiled templates: just include them
  1014. // before you configure nunjucks and this will automatically
  1015. // pick it up and use it
  1016. if (typeof window !== 'undefined' && window.nunjucksPrecompiled) {
  1017. this.loaders.unshift(new PrecompiledLoader(window.nunjucksPrecompiled));
  1018. }
  1019. this._initLoaders();
  1020. this.globals = globals();
  1021. this.filters = {};
  1022. this.tests = {};
  1023. this.asyncFilters = [];
  1024. this.extensions = {};
  1025. this.extensionsList = [];
  1026. lib._entries(filters).forEach(function (_ref) {
  1027. var name = _ref[0],
  1028. filter = _ref[1];
  1029. return _this.addFilter(name, filter);
  1030. });
  1031. lib._entries(tests).forEach(function (_ref2) {
  1032. var name = _ref2[0],
  1033. test = _ref2[1];
  1034. return _this.addTest(name, test);
  1035. });
  1036. };
  1037. _proto._initLoaders = function _initLoaders() {
  1038. var _this2 = this;
  1039. this.loaders.forEach(function (loader) {
  1040. // Caching and cache busting
  1041. loader.cache = {};
  1042. if (typeof loader.on === 'function') {
  1043. loader.on('update', function (name, fullname) {
  1044. loader.cache[name] = null;
  1045. _this2.emit('update', name, fullname, loader);
  1046. });
  1047. loader.on('load', function (name, source) {
  1048. _this2.emit('load', name, source, loader);
  1049. });
  1050. }
  1051. });
  1052. };
  1053. _proto.invalidateCache = function invalidateCache() {
  1054. this.loaders.forEach(function (loader) {
  1055. loader.cache = {};
  1056. });
  1057. };
  1058. _proto.addExtension = function addExtension(name, extension) {
  1059. extension.__name = name;
  1060. this.extensions[name] = extension;
  1061. this.extensionsList.push(extension);
  1062. return this;
  1063. };
  1064. _proto.removeExtension = function removeExtension(name) {
  1065. var extension = this.getExtension(name);
  1066. if (!extension) {
  1067. return;
  1068. }
  1069. this.extensionsList = lib.without(this.extensionsList, extension);
  1070. delete this.extensions[name];
  1071. };
  1072. _proto.getExtension = function getExtension(name) {
  1073. return this.extensions[name];
  1074. };
  1075. _proto.hasExtension = function hasExtension(name) {
  1076. return !!this.extensions[name];
  1077. };
  1078. _proto.addGlobal = function addGlobal(name, value) {
  1079. this.globals[name] = value;
  1080. return this;
  1081. };
  1082. _proto.getGlobal = function getGlobal(name) {
  1083. if (typeof this.globals[name] === 'undefined') {
  1084. throw new Error('global not found: ' + name);
  1085. }
  1086. return this.globals[name];
  1087. };
  1088. _proto.addFilter = function addFilter(name, func, async) {
  1089. var wrapped = func;
  1090. if (async) {
  1091. this.asyncFilters.push(name);
  1092. }
  1093. this.filters[name] = wrapped;
  1094. return this;
  1095. };
  1096. _proto.getFilter = function getFilter(name) {
  1097. if (!this.filters[name]) {
  1098. throw new Error('filter not found: ' + name);
  1099. }
  1100. return this.filters[name];
  1101. };
  1102. _proto.addTest = function addTest(name, func) {
  1103. this.tests[name] = func;
  1104. return this;
  1105. };
  1106. _proto.getTest = function getTest(name) {
  1107. if (!this.tests[name]) {
  1108. throw new Error('test not found: ' + name);
  1109. }
  1110. return this.tests[name];
  1111. };
  1112. _proto.resolveTemplate = function resolveTemplate(loader, parentName, filename) {
  1113. var isRelative = loader.isRelative && parentName ? loader.isRelative(filename) : false;
  1114. return isRelative && loader.resolve ? loader.resolve(parentName, filename) : filename;
  1115. };
  1116. _proto.getTemplate = function getTemplate(name, eagerCompile, parentName, ignoreMissing, cb) {
  1117. var _this3 = this;
  1118. var that = this;
  1119. var tmpl = null;
  1120. if (name && name.raw) {
  1121. // this fixes autoescape for templates referenced in symbols
  1122. name = name.raw;
  1123. }
  1124. if (lib.isFunction(parentName)) {
  1125. cb = parentName;
  1126. parentName = null;
  1127. eagerCompile = eagerCompile || false;
  1128. }
  1129. if (lib.isFunction(eagerCompile)) {
  1130. cb = eagerCompile;
  1131. eagerCompile = false;
  1132. }
  1133. if (name instanceof Template) {
  1134. tmpl = name;
  1135. } else if (typeof name !== 'string') {
  1136. throw new Error('template names must be a string: ' + name);
  1137. } else {
  1138. for (var i = 0; i < this.loaders.length; i++) {
  1139. var loader = this.loaders[i];
  1140. tmpl = loader.cache[this.resolveTemplate(loader, parentName, name)];
  1141. if (tmpl) {
  1142. break;
  1143. }
  1144. }
  1145. }
  1146. if (tmpl) {
  1147. if (eagerCompile) {
  1148. tmpl.compile();
  1149. }
  1150. if (cb) {
  1151. cb(null, tmpl);
  1152. return undefined;
  1153. } else {
  1154. return tmpl;
  1155. }
  1156. }
  1157. var syncResult;
  1158. var createTemplate = function createTemplate(err, info) {
  1159. if (!info && !err && !ignoreMissing) {
  1160. err = new Error('template not found: ' + name);
  1161. }
  1162. if (err) {
  1163. if (cb) {
  1164. cb(err);
  1165. return;
  1166. } else {
  1167. throw err;
  1168. }
  1169. }
  1170. var newTmpl;
  1171. if (!info) {
  1172. newTmpl = new Template(noopTmplSrc, _this3, '', eagerCompile);
  1173. } else {
  1174. newTmpl = new Template(info.src, _this3, info.path, eagerCompile);
  1175. if (!info.noCache) {
  1176. info.loader.cache[name] = newTmpl;
  1177. }
  1178. }
  1179. if (cb) {
  1180. cb(null, newTmpl);
  1181. } else {
  1182. syncResult = newTmpl;
  1183. }
  1184. };
  1185. lib.asyncIter(this.loaders, function (loader, i, next, done) {
  1186. function handle(err, src) {
  1187. if (err) {
  1188. done(err);
  1189. } else if (src) {
  1190. src.loader = loader;
  1191. done(null, src);
  1192. } else {
  1193. next();
  1194. }
  1195. } // Resolve name relative to parentName
  1196. name = that.resolveTemplate(loader, parentName, name);
  1197. if (loader.async) {
  1198. loader.getSource(name, handle);
  1199. } else {
  1200. handle(null, loader.getSource(name));
  1201. }
  1202. }, createTemplate);
  1203. return syncResult;
  1204. };
  1205. _proto.express = function express(app) {
  1206. return expressApp(this, app);
  1207. };
  1208. _proto.render = function render(name, ctx, cb) {
  1209. if (lib.isFunction(ctx)) {
  1210. cb = ctx;
  1211. ctx = null;
  1212. } // We support a synchronous API to make it easier to migrate
  1213. // existing code to async. This works because if you don't do
  1214. // anything async work, the whole thing is actually run
  1215. // synchronously.
  1216. var syncResult = null;
  1217. this.getTemplate(name, function (err, tmpl) {
  1218. if (err && cb) {
  1219. callbackAsap(cb, err);
  1220. } else if (err) {
  1221. throw err;
  1222. } else {
  1223. syncResult = tmpl.render(ctx, cb);
  1224. }
  1225. });
  1226. return syncResult;
  1227. };
  1228. _proto.renderString = function renderString(src, ctx, opts, cb) {
  1229. if (lib.isFunction(opts)) {
  1230. cb = opts;
  1231. opts = {};
  1232. }
  1233. opts = opts || {};
  1234. var tmpl = new Template(src, this, opts.path);
  1235. return tmpl.render(ctx, cb);
  1236. };
  1237. _proto.waterfall = function waterfall(tasks, callback, forceAsync) {
  1238. return _waterfall(tasks, callback, forceAsync);
  1239. };
  1240. return Environment;
  1241. }(EmitterObj);
  1242. var Context =
  1243. /*#__PURE__*/
  1244. function (_Obj) {
  1245. _inheritsLoose(Context, _Obj);
  1246. function Context() {
  1247. return _Obj.apply(this, arguments) || this;
  1248. }
  1249. var _proto2 = Context.prototype;
  1250. _proto2.init = function init(ctx, blocks, env) {
  1251. var _this4 = this;
  1252. // Has to be tied to an environment so we can tap into its globals.
  1253. this.env = env || new Environment(); // Make a duplicate of ctx
  1254. this.ctx = lib.extend({}, ctx);
  1255. this.blocks = {};
  1256. this.exported = [];
  1257. lib.keys(blocks).forEach(function (name) {
  1258. _this4.addBlock(name, blocks[name]);
  1259. });
  1260. };
  1261. _proto2.lookup = function lookup(name) {
  1262. // This is one of the most called functions, so optimize for
  1263. // the typical case where the name isn't in the globals
  1264. if (name in this.env.globals && !(name in this.ctx)) {
  1265. return this.env.globals[name];
  1266. } else {
  1267. return this.ctx[name];
  1268. }
  1269. };
  1270. _proto2.setVariable = function setVariable(name, val) {
  1271. this.ctx[name] = val;
  1272. };
  1273. _proto2.getVariables = function getVariables() {
  1274. return this.ctx;
  1275. };
  1276. _proto2.addBlock = function addBlock(name, block) {
  1277. this.blocks[name] = this.blocks[name] || [];
  1278. this.blocks[name].push(block);
  1279. return this;
  1280. };
  1281. _proto2.getBlock = function getBlock(name) {
  1282. if (!this.blocks[name]) {
  1283. throw new Error('unknown block "' + name + '"');
  1284. }
  1285. return this.blocks[name][0];
  1286. };
  1287. _proto2.getSuper = function getSuper(env, name, block, frame, runtime, cb) {
  1288. var idx = lib.indexOf(this.blocks[name] || [], block);
  1289. var blk = this.blocks[name][idx + 1];
  1290. var context = this;
  1291. if (idx === -1 || !blk) {
  1292. throw new Error('no super block available for "' + name + '"');
  1293. }
  1294. blk(env, context, frame, runtime, cb);
  1295. };
  1296. _proto2.addExport = function addExport(name) {
  1297. this.exported.push(name);
  1298. };
  1299. _proto2.getExported = function getExported() {
  1300. var _this5 = this;
  1301. var exported = {};
  1302. this.exported.forEach(function (name) {
  1303. exported[name] = _this5.ctx[name];
  1304. });
  1305. return exported;
  1306. };
  1307. return Context;
  1308. }(Obj);
  1309. var Template =
  1310. /*#__PURE__*/
  1311. function (_Obj2) {
  1312. _inheritsLoose(Template, _Obj2);
  1313. function Template() {
  1314. return _Obj2.apply(this, arguments) || this;
  1315. }
  1316. var _proto3 = Template.prototype;
  1317. _proto3.init = function init(src, env, path, eagerCompile) {
  1318. this.env = env || new Environment();
  1319. if (lib.isObject(src)) {
  1320. switch (src.type) {
  1321. case 'code':
  1322. this.tmplProps = src.obj;
  1323. break;
  1324. case 'string':
  1325. this.tmplStr = src.obj;
  1326. break;
  1327. default:
  1328. throw new Error("Unexpected template object type " + src.type + "; expected 'code', or 'string'");
  1329. }
  1330. } else if (lib.isString(src)) {
  1331. this.tmplStr = src;
  1332. } else {
  1333. throw new Error('src must be a string or an object describing the source');
  1334. }
  1335. this.path = path;
  1336. if (eagerCompile) {
  1337. try {
  1338. this._compile();
  1339. } catch (err) {
  1340. throw lib._prettifyError(this.path, this.env.opts.dev, err);
  1341. }
  1342. } else {
  1343. this.compiled = false;
  1344. }
  1345. };
  1346. _proto3.render = function render(ctx, parentFrame, cb) {
  1347. var _this6 = this;
  1348. if (typeof ctx === 'function') {
  1349. cb = ctx;
  1350. ctx = {};
  1351. } else if (typeof parentFrame === 'function') {
  1352. cb = parentFrame;
  1353. parentFrame = null;
  1354. } // If there is a parent frame, we are being called from internal
  1355. // code of another template, and the internal system
  1356. // depends on the sync/async nature of the parent template
  1357. // to be inherited, so force an async callback
  1358. var forceAsync = !parentFrame; // Catch compile errors for async rendering
  1359. try {
  1360. this.compile();
  1361. } catch (e) {
  1362. var err = lib._prettifyError(this.path, this.env.opts.dev, e);
  1363. if (cb) {
  1364. return callbackAsap(cb, err);
  1365. } else {
  1366. throw err;
  1367. }
  1368. }
  1369. var context = new Context(ctx || {}, this.blocks, this.env);
  1370. var frame = parentFrame ? parentFrame.push(true) : new Frame();
  1371. frame.topLevel = true;
  1372. var syncResult = null;
  1373. var didError = false;
  1374. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err, res) {
  1375. if (didError) {
  1376. // prevent multiple calls to cb
  1377. if (cb) {
  1378. return;
  1379. } else {
  1380. throw err;
  1381. }
  1382. }
  1383. if (err) {
  1384. err = lib._prettifyError(_this6.path, _this6.env.opts.dev, err);
  1385. didError = true;
  1386. }
  1387. if (cb) {
  1388. if (forceAsync) {
  1389. callbackAsap(cb, err, res);
  1390. } else {
  1391. cb(err, res);
  1392. }
  1393. } else {
  1394. if (err) {
  1395. throw err;
  1396. }
  1397. syncResult = res;
  1398. }
  1399. });
  1400. return syncResult;
  1401. };
  1402. _proto3.getExported = function getExported(ctx, parentFrame, cb) {
  1403. // eslint-disable-line consistent-return
  1404. if (typeof ctx === 'function') {
  1405. cb = ctx;
  1406. ctx = {};
  1407. }
  1408. if (typeof parentFrame === 'function') {
  1409. cb = parentFrame;
  1410. parentFrame = null;
  1411. } // Catch compile errors for async rendering
  1412. try {
  1413. this.compile();
  1414. } catch (e) {
  1415. if (cb) {
  1416. return cb(e);
  1417. } else {
  1418. throw e;
  1419. }
  1420. }
  1421. var frame = parentFrame ? parentFrame.push() : new Frame();
  1422. frame.topLevel = true; // Run the rootRenderFunc to populate the context with exported vars
  1423. var context = new Context(ctx || {}, this.blocks, this.env);
  1424. this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err) {
  1425. if (err) {
  1426. cb(err, null);
  1427. } else {
  1428. cb(null, context.getExported());
  1429. }
  1430. });
  1431. };
  1432. _proto3.compile = function compile() {
  1433. if (!this.compiled) {
  1434. this._compile();
  1435. }
  1436. };
  1437. _proto3._compile = function _compile() {
  1438. var props;
  1439. if (this.tmplProps) {
  1440. props = this.tmplProps;
  1441. } else {
  1442. var source = compiler.compile(this.tmplStr, this.env.asyncFilters, this.env.extensionsList, this.path, this.env.opts);
  1443. var func = new Function(source); // eslint-disable-line no-new-func
  1444. props = func();
  1445. }
  1446. this.blocks = this._getBlocks(props);
  1447. this.rootRenderFunc = props.root;
  1448. this.compiled = true;
  1449. };
  1450. _proto3._getBlocks = function _getBlocks(props) {
  1451. var blocks = {};
  1452. lib.keys(props).forEach(function (k) {
  1453. if (k.slice(0, 2) === 'b_') {
  1454. blocks[k.slice(2)] = props[k];
  1455. }
  1456. });
  1457. return blocks;
  1458. };
  1459. return Template;
  1460. }(Obj);
  1461. module.exports = {
  1462. Environment: Environment,
  1463. Template: Template
  1464. };
  1465. /***/ }),
  1466. /* 8 */
  1467. /***/ (function(module, exports, __webpack_require__) {
  1468. "use strict";
  1469. // rawAsap provides everything we need except exception management.
  1470. var rawAsap = __webpack_require__(9);
  1471. // RawTasks are recycled to reduce GC churn.
  1472. var freeTasks = [];
  1473. // We queue errors to ensure they are thrown in right order (FIFO).
  1474. // Array-as-queue is good enough here, since we are just dealing with exceptions.
  1475. var pendingErrors = [];
  1476. var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
  1477. function throwFirstError() {
  1478. if (pendingErrors.length) {
  1479. throw pendingErrors.shift();
  1480. }
  1481. }
  1482. /**
  1483. * Calls a task as soon as possible after returning, in its own event, with priority
  1484. * over other events like animation, reflow, and repaint. An error thrown from an
  1485. * event will not interrupt, nor even substantially slow down the processing of
  1486. * other events, but will be rather postponed to a lower priority event.
  1487. * @param {{call}} task A callable object, typically a function that takes no
  1488. * arguments.
  1489. */
  1490. module.exports = asap;
  1491. function asap(task) {
  1492. var rawTask;
  1493. if (freeTasks.length) {
  1494. rawTask = freeTasks.pop();
  1495. } else {
  1496. rawTask = new RawTask();
  1497. }
  1498. rawTask.task = task;
  1499. rawAsap(rawTask);
  1500. }
  1501. // We wrap tasks with recyclable task objects. A task object implements
  1502. // `call`, just like a function.
  1503. function RawTask() {
  1504. this.task = null;
  1505. }
  1506. // The sole purpose of wrapping the task is to catch the exception and recycle
  1507. // the task object after its single use.
  1508. RawTask.prototype.call = function () {
  1509. try {
  1510. this.task.call();
  1511. } catch (error) {
  1512. if (asap.onerror) {
  1513. // This hook exists purely for testing purposes.
  1514. // Its name will be periodically randomized to break any code that
  1515. // depends on its existence.
  1516. asap.onerror(error);
  1517. } else {
  1518. // In a web browser, exceptions are not fatal. However, to avoid
  1519. // slowing down the queue of pending tasks, we rethrow the error in a
  1520. // lower priority turn.
  1521. pendingErrors.push(error);
  1522. requestErrorThrow();
  1523. }
  1524. } finally {
  1525. this.task = null;
  1526. freeTasks[freeTasks.length] = this;
  1527. }
  1528. };
  1529. /***/ }),
  1530. /* 9 */
  1531. /***/ (function(module, exports, __webpack_require__) {
  1532. "use strict";
  1533. /* WEBPACK VAR INJECTION */(function(global) {
  1534. // Use the fastest means possible to execute a task in its own turn, with
  1535. // priority over other events including IO, animation, reflow, and redraw
  1536. // events in browsers.
  1537. //
  1538. // An exception thrown by a task will permanently interrupt the processing of
  1539. // subsequent tasks. The higher level `asap` function ensures that if an
  1540. // exception is thrown by a task, that the task queue will continue flushing as
  1541. // soon as possible, but if you use `rawAsap` directly, you are responsible to
  1542. // either ensure that no exceptions are thrown from your task, or to manually
  1543. // call `rawAsap.requestFlush` if an exception is thrown.
  1544. module.exports = rawAsap;
  1545. function rawAsap(task) {
  1546. if (!queue.length) {
  1547. requestFlush();
  1548. flushing = true;
  1549. }
  1550. // Equivalent to push, but avoids a function call.
  1551. queue[queue.length] = task;
  1552. }
  1553. var queue = [];
  1554. // Once a flush has been requested, no further calls to `requestFlush` are
  1555. // necessary until the next `flush` completes.
  1556. var flushing = false;
  1557. // `requestFlush` is an implementation-specific method that attempts to kick
  1558. // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
  1559. // the event queue before yielding to the browser's own event loop.
  1560. var requestFlush;
  1561. // The position of the next task to execute in the task queue. This is
  1562. // preserved between calls to `flush` so that it can be resumed if
  1563. // a task throws an exception.
  1564. var index = 0;
  1565. // If a task schedules additional tasks recursively, the task queue can grow
  1566. // unbounded. To prevent memory exhaustion, the task queue will periodically
  1567. // truncate already-completed tasks.
  1568. var capacity = 1024;
  1569. // The flush function processes all tasks that have been scheduled with
  1570. // `rawAsap` unless and until one of those tasks throws an exception.
  1571. // If a task throws an exception, `flush` ensures that its state will remain
  1572. // consistent and will resume where it left off when called again.
  1573. // However, `flush` does not make any arrangements to be called again if an
  1574. // exception is thrown.
  1575. function flush() {
  1576. while (index < queue.length) {
  1577. var currentIndex = index;
  1578. // Advance the index before calling the task. This ensures that we will
  1579. // begin flushing on the next task the task throws an error.
  1580. index = index + 1;
  1581. queue[currentIndex].call();
  1582. // Prevent leaking memory for long chains of recursive calls to `asap`.
  1583. // If we call `asap` within tasks scheduled by `asap`, the queue will
  1584. // grow, but to avoid an O(n) walk for every task we execute, we don't
  1585. // shift tasks off the queue after they have been executed.
  1586. // Instead, we periodically shift 1024 tasks off the queue.
  1587. if (index > capacity) {
  1588. // Manually shift all values starting at the index back to the
  1589. // beginning of the queue.
  1590. for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
  1591. queue[scan] = queue[scan + index];
  1592. }
  1593. queue.length -= index;
  1594. index = 0;
  1595. }
  1596. }
  1597. queue.length = 0;
  1598. index = 0;
  1599. flushing = false;
  1600. }
  1601. // `requestFlush` is implemented using a strategy based on data collected from
  1602. // every available SauceLabs Selenium web driver worker at time of writing.
  1603. // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
  1604. // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
  1605. // have WebKitMutationObserver but not un-prefixed MutationObserver.
  1606. // Must use `global` or `self` instead of `window` to work in both frames and web
  1607. // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
  1608. /* globals self */
  1609. var scope = typeof global !== "undefined" ? global : self;
  1610. var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
  1611. // MutationObservers are desirable because they have high priority and work
  1612. // reliably everywhere they are implemented.
  1613. // They are implemented in all modern browsers.
  1614. //
  1615. // - Android 4-4.3
  1616. // - Chrome 26-34
  1617. // - Firefox 14-29
  1618. // - Internet Explorer 11
  1619. // - iPad Safari 6-7.1
  1620. // - iPhone Safari 7-7.1
  1621. // - Safari 6-7
  1622. if (typeof BrowserMutationObserver === "function") {
  1623. requestFlush = makeRequestCallFromMutationObserver(flush);
  1624. // MessageChannels are desirable because they give direct access to the HTML
  1625. // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
  1626. // 11-12, and in web workers in many engines.
  1627. // Although message channels yield to any queued rendering and IO tasks, they
  1628. // would be better than imposing the 4ms delay of timers.
  1629. // However, they do not work reliably in Internet Explorer or Safari.
  1630. // Internet Explorer 10 is the only browser that has setImmediate but does
  1631. // not have MutationObservers.
  1632. // Although setImmediate yields to the browser's renderer, it would be
  1633. // preferrable to falling back to setTimeout since it does not have
  1634. // the minimum 4ms penalty.
  1635. // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
  1636. // Desktop to a lesser extent) that renders both setImmediate and
  1637. // MessageChannel useless for the purposes of ASAP.
  1638. // https://github.com/kriskowal/q/issues/396
  1639. // Timers are implemented universally.
  1640. // We fall back to timers in workers in most engines, and in foreground
  1641. // contexts in the following browsers.
  1642. // However, note that even this simple case requires nuances to operate in a
  1643. // broad spectrum of browsers.
  1644. //
  1645. // - Firefox 3-13
  1646. // - Internet Explorer 6-9
  1647. // - iPad Safari 4.3
  1648. // - Lynx 2.8.7
  1649. } else {
  1650. requestFlush = makeRequestCallFromTimer(flush);
  1651. }
  1652. // `requestFlush` requests that the high priority event queue be flushed as
  1653. // soon as possible.
  1654. // This is useful to prevent an error thrown in a task from stalling the event
  1655. // queue if the exception handled by Node.js’s
  1656. // `process.on("uncaughtException")` or by a domain.
  1657. rawAsap.requestFlush = requestFlush;
  1658. // To request a high priority event, we induce a mutation observer by toggling
  1659. // the text of a text node between "1" and "-1".
  1660. function makeRequestCallFromMutationObserver(callback) {
  1661. var toggle = 1;
  1662. var observer = new BrowserMutationObserver(callback);
  1663. var node = document.createTextNode("");
  1664. observer.observe(node, {characterData: true});
  1665. return function requestCall() {
  1666. toggle = -toggle;
  1667. node.data = toggle;
  1668. };
  1669. }
  1670. // The message channel technique was discovered by Malte Ubl and was the
  1671. // original foundation for this library.
  1672. // http://www.nonblocking.io/2011/06/windownexttick.html
  1673. // Safari 6.0.5 (at least) intermittently fails to create message ports on a
  1674. // page's first load. Thankfully, this version of Safari supports
  1675. // MutationObservers, so we don't need to fall back in that case.
  1676. // function makeRequestCallFromMessageChannel(callback) {
  1677. // var channel = new MessageChannel();
  1678. // channel.port1.onmessage = callback;
  1679. // return function requestCall() {
  1680. // channel.port2.postMessage(0);
  1681. // };
  1682. // }
  1683. // For reasons explained above, we are also unable to use `setImmediate`
  1684. // under any circumstances.
  1685. // Even if we were, there is another bug in Internet Explorer 10.
  1686. // It is not sufficient to assign `setImmediate` to `requestFlush` because
  1687. // `setImmediate` must be called *by name* and therefore must be wrapped in a
  1688. // closure.
  1689. // Never forget.
  1690. // function makeRequestCallFromSetImmediate(callback) {
  1691. // return function requestCall() {
  1692. // setImmediate(callback);
  1693. // };
  1694. // }
  1695. // Safari 6.0 has a problem where timers will get lost while the user is
  1696. // scrolling. This problem does not impact ASAP because Safari 6.0 supports
  1697. // mutation observers, so that implementation is used instead.
  1698. // However, if we ever elect to use timers in Safari, the prevalent work-around
  1699. // is to add a scroll event listener that calls for a flush.
  1700. // `setTimeout` does not call the passed callback if the delay is less than
  1701. // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
  1702. // even then.
  1703. function makeRequestCallFromTimer(callback) {
  1704. return function requestCall() {
  1705. // We dispatch a timeout with a specified delay of 0 for engines that
  1706. // can reliably accommodate that request. This will usually be snapped
  1707. // to a 4 milisecond delay, but once we're flushing, there's no delay
  1708. // between events.
  1709. var timeoutHandle = setTimeout(handleTimer, 0);
  1710. // However, since this timer gets frequently dropped in Firefox
  1711. // workers, we enlist an interval handle that will try to fire
  1712. // an event 20 times per second until it succeeds.
  1713. var intervalHandle = setInterval(handleTimer, 50);
  1714. function handleTimer() {
  1715. // Whichever timer succeeds will cancel both timers and
  1716. // execute the callback.
  1717. clearTimeout(timeoutHandle);
  1718. clearInterval(intervalHandle);
  1719. callback();
  1720. }
  1721. };
  1722. }
  1723. // This is for `asap.js` only.
  1724. // Its name will be periodically randomized to break any code that depends on
  1725. // its existence.
  1726. rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
  1727. // ASAP was originally a nextTick shim included in Q. This was factored out
  1728. // into this ASAP package. It was later adapted to RSVP which made further
  1729. // amendments. These decisions, particularly to marginalize MessageChannel and
  1730. // to capture the MutationObserver implementation in a closure, were integrated
  1731. // back into ASAP proper.
  1732. // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
  1733. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10)))
  1734. /***/ }),
  1735. /* 10 */
  1736. /***/ (function(module, exports) {
  1737. var g;
  1738. // This works in non-strict mode
  1739. g = (function() {
  1740. return this;
  1741. })();
  1742. try {
  1743. // This works if eval is allowed (see CSP)
  1744. g = g || Function("return this")() || (1,eval)("this");
  1745. } catch(e) {
  1746. // This works if the window reference is available
  1747. if(typeof window === "object")
  1748. g = window;
  1749. }
  1750. // g can still be undefined, but nothing to do about it...
  1751. // We return undefined, instead of nothing here, so it's
  1752. // easier to handle this case. if(!global) { ...}
  1753. module.exports = g;
  1754. /***/ }),
  1755. /* 11 */
  1756. /***/ (function(module, exports, __webpack_require__) {
  1757. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// MIT license (by Elan Shanker).
  1758. (function(globals) {
  1759. 'use strict';
  1760. var executeSync = function(){
  1761. var args = Array.prototype.slice.call(arguments);
  1762. if (typeof args[0] === 'function'){
  1763. args[0].apply(null, args.splice(1));
  1764. }
  1765. };
  1766. var executeAsync = function(fn){
  1767. if (typeof setImmediate === 'function') {
  1768. setImmediate(fn);
  1769. } else if (typeof process !== 'undefined' && process.nextTick) {
  1770. process.nextTick(fn);
  1771. } else {
  1772. setTimeout(fn, 0);
  1773. }
  1774. };
  1775. var makeIterator = function (tasks) {
  1776. var makeCallback = function (index) {
  1777. var fn = function () {
  1778. if (tasks.length) {
  1779. tasks[index].apply(null, arguments);
  1780. }
  1781. return fn.next();
  1782. };
  1783. fn.next = function () {
  1784. return (index < tasks.length - 1) ? makeCallback(index + 1): null;
  1785. };
  1786. return fn;
  1787. };
  1788. return makeCallback(0);
  1789. };
  1790. var _isArray = Array.isArray || function(maybeArray){
  1791. return Object.prototype.toString.call(maybeArray) === '[object Array]';
  1792. };
  1793. var waterfall = function (tasks, callback, forceAsync) {
  1794. var nextTick = forceAsync ? executeAsync : executeSync;
  1795. callback = callback || function () {};
  1796. if (!_isArray(tasks)) {
  1797. var err = new Error('First argument to waterfall must be an array of functions');
  1798. return callback(err);
  1799. }
  1800. if (!tasks.length) {
  1801. return callback();
  1802. }
  1803. var wrapIterator = function (iterator) {
  1804. return function (err) {
  1805. if (err) {
  1806. callback.apply(null, arguments);
  1807. callback = function () {};
  1808. } else {
  1809. var args = Array.prototype.slice.call(arguments, 1);
  1810. var next = iterator.next();
  1811. if (next) {
  1812. args.push(wrapIterator(next));
  1813. } else {
  1814. args.push(callback);
  1815. }
  1816. nextTick(function () {
  1817. iterator.apply(null, args);
  1818. });
  1819. }
  1820. };
  1821. };
  1822. wrapIterator(makeIterator(tasks))();
  1823. };
  1824. if (true) {
  1825. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
  1826. return waterfall;
  1827. }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  1828. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // RequireJS
  1829. } else if (typeof module !== 'undefined' && module.exports) {
  1830. module.exports = waterfall; // CommonJS
  1831. } else {
  1832. globals.waterfall = waterfall; // <script>
  1833. }
  1834. })(this);
  1835. /***/ }),
  1836. /* 12 */
  1837. /***/ (function(module, exports, __webpack_require__) {
  1838. "use strict";
  1839. var lib = __webpack_require__(1);
  1840. var r = __webpack_require__(2);
  1841. var exports = module.exports = {};
  1842. function normalize(value, defaultValue) {
  1843. if (value === null || value === undefined || value === false) {
  1844. return defaultValue;
  1845. }
  1846. return value;
  1847. }
  1848. exports.abs = Math.abs;
  1849. function isNaN(num) {
  1850. return num !== num; // eslint-disable-line no-self-compare
  1851. }
  1852. function batch(arr, linecount, fillWith) {
  1853. var i;
  1854. var res = [];
  1855. var tmp = [];
  1856. for (i = 0; i < arr.length; i++) {
  1857. if (i % linecount === 0 && tmp.length) {
  1858. res.push(tmp);
  1859. tmp = [];
  1860. }
  1861. tmp.push(arr[i]);
  1862. }
  1863. if (tmp.length) {
  1864. if (fillWith) {
  1865. for (i = tmp.length; i < linecount; i++) {
  1866. tmp.push(fillWith);
  1867. }
  1868. }
  1869. res.push(tmp);
  1870. }
  1871. return res;
  1872. }
  1873. exports.batch = batch;
  1874. function capitalize(str) {
  1875. str = normalize(str, '');
  1876. var ret = str.toLowerCase();
  1877. return r.copySafeness(str, ret.charAt(0).toUpperCase() + ret.slice(1));
  1878. }
  1879. exports.capitalize = capitalize;
  1880. function center(str, width) {
  1881. str = normalize(str, '');
  1882. width = width || 80;
  1883. if (str.length >= width) {
  1884. return str;
  1885. }
  1886. var spaces = width - str.length;
  1887. var pre = lib.repeat(' ', spaces / 2 - spaces % 2);
  1888. var post = lib.repeat(' ', spaces / 2);
  1889. return r.copySafeness(str, pre + str + post);
  1890. }
  1891. exports.center = center;
  1892. function default_(val, def, bool) {
  1893. if (bool) {
  1894. return val || def;
  1895. } else {
  1896. return val !== undefined ? val : def;
  1897. }
  1898. } // TODO: it is confusing to export something called 'default'
  1899. exports['default'] = default_; // eslint-disable-line dot-notation
  1900. function dictsort(val, caseSensitive, by) {
  1901. if (!lib.isObject(val)) {
  1902. throw new lib.TemplateError('dictsort filter: val must be an object');
  1903. }
  1904. var array = []; // deliberately include properties from the object's prototype
  1905. for (var k in val) {
  1906. // eslint-disable-line guard-for-in, no-restricted-syntax
  1907. array.push([k, val[k]]);
  1908. }
  1909. var si;
  1910. if (by === undefined || by === 'key') {
  1911. si = 0;
  1912. } else if (by === 'value') {
  1913. si = 1;
  1914. } else {
  1915. throw new lib.TemplateError('dictsort filter: You can only sort by either key or value');
  1916. }
  1917. array.sort(function (t1, t2) {
  1918. var a = t1[si];
  1919. var b = t2[si];
  1920. if (!caseSensitive) {
  1921. if (lib.isString(a)) {
  1922. a = a.toUpperCase();
  1923. }
  1924. if (lib.isString(b)) {
  1925. b = b.toUpperCase();
  1926. }
  1927. }
  1928. return a > b ? 1 : a === b ? 0 : -1; // eslint-disable-line no-nested-ternary
  1929. });
  1930. return array;
  1931. }
  1932. exports.dictsort = dictsort;
  1933. function dump(obj, spaces) {
  1934. return JSON.stringify(obj, null, spaces);
  1935. }
  1936. exports.dump = dump;
  1937. function escape(str) {
  1938. if (str instanceof r.SafeString) {
  1939. return str;
  1940. }
  1941. str = str === null || str === undefined ? '' : str;
  1942. return r.markSafe(lib.escape(str.toString()));
  1943. }
  1944. exports.escape = escape;
  1945. function safe(str) {
  1946. if (str instanceof r.SafeString) {
  1947. return str;
  1948. }
  1949. str = str === null || str === undefined ? '' : str;
  1950. return r.markSafe(str.toString());
  1951. }
  1952. exports.safe = safe;
  1953. function first(arr) {
  1954. return arr[0];
  1955. }
  1956. exports.first = first;
  1957. function forceescape(str) {
  1958. str = str === null || str === undefined ? '' : str;
  1959. return r.markSafe(lib.escape(str.toString()));
  1960. }
  1961. exports.forceescape = forceescape;
  1962. function groupby(arr, attr) {
  1963. return lib.groupBy(arr, attr);
  1964. }
  1965. exports.groupby = groupby;
  1966. function indent(str, width, indentfirst) {
  1967. str = normalize(str, '');
  1968. if (str === '') {
  1969. return '';
  1970. }
  1971. width = width || 4; // let res = '';
  1972. var lines = str.split('\n');
  1973. var sp = lib.repeat(' ', width);
  1974. var res = lines.map(function (l, i) {
  1975. return i === 0 && !indentfirst ? l + "\n" : "" + sp + l + "\n";
  1976. }).join('');
  1977. return r.copySafeness(str, res);
  1978. }
  1979. exports.indent = indent;
  1980. function join(arr, del, attr) {
  1981. del = del || '';
  1982. if (attr) {
  1983. arr = lib.map(arr, function (v) {
  1984. return v[attr];
  1985. });
  1986. }
  1987. return arr.join(del);
  1988. }
  1989. exports.join = join;
  1990. function last(arr) {
  1991. return arr[arr.length - 1];
  1992. }
  1993. exports.last = last;
  1994. function lengthFilter(val) {
  1995. var value = normalize(val, '');
  1996. if (value !== undefined) {
  1997. if (typeof Map === 'function' && value instanceof Map || typeof Set === 'function' && value instanceof Set) {
  1998. // ECMAScript 2015 Maps and Sets
  1999. return value.size;
  2000. }
  2001. if (lib.isObject(value) && !(value instanceof r.SafeString)) {
  2002. // Objects (besides SafeStrings), non-primative Arrays
  2003. return lib.keys(value).length;
  2004. }
  2005. return value.length;
  2006. }
  2007. return 0;
  2008. }
  2009. exports.length = lengthFilter;
  2010. function list(val) {
  2011. if (lib.isString(val)) {
  2012. return val.split('');
  2013. } else if (lib.isObject(val)) {
  2014. return lib._entries(val || {}).map(function (_ref) {
  2015. var key = _ref[0],
  2016. value = _ref[1];
  2017. return {
  2018. key: key,
  2019. value: value
  2020. };
  2021. });
  2022. } else if (lib.isArray(val)) {
  2023. return val;
  2024. } else {
  2025. throw new lib.TemplateError('list filter: type not iterable');
  2026. }
  2027. }
  2028. exports.list = list;
  2029. function lower(str) {
  2030. str = normalize(str, '');
  2031. return str.toLowerCase();
  2032. }
  2033. exports.lower = lower;
  2034. function nl2br(str) {
  2035. if (str === null || str === undefined) {
  2036. return '';
  2037. }
  2038. return r.copySafeness(str, str.replace(/\r\n|\n/g, '<br />\n'));
  2039. }
  2040. exports.nl2br = nl2br;
  2041. function random(arr) {
  2042. return arr[Math.floor(Math.random() * arr.length)];
  2043. }
  2044. exports.random = random;
  2045. function rejectattr(arr, attr) {
  2046. return arr.filter(function (item) {
  2047. return !item[attr];
  2048. });
  2049. }
  2050. exports.rejectattr = rejectattr;
  2051. function selectattr(arr, attr) {
  2052. return arr.filter(function (item) {
  2053. return !!item[attr];
  2054. });
  2055. }
  2056. exports.selectattr = selectattr;
  2057. function replace(str, old, new_, maxCount) {
  2058. var originalStr = str;
  2059. if (old instanceof RegExp) {
  2060. return str.replace(old, new_);
  2061. }
  2062. if (typeof maxCount === 'undefined') {
  2063. maxCount = -1;
  2064. }
  2065. var res = ''; // Output
  2066. // Cast Numbers in the search term to string
  2067. if (typeof old === 'number') {
  2068. old = '' + old;
  2069. } else if (typeof old !== 'string') {
  2070. // If it is something other than number or string,
  2071. // return the original string
  2072. return str;
  2073. } // Cast numbers in the replacement to string
  2074. if (typeof str === 'number') {
  2075. str = '' + str;
  2076. } // If by now, we don't have a string, throw it back
  2077. if (typeof str !== 'string' && !(str instanceof r.SafeString)) {
  2078. return str;
  2079. } // ShortCircuits
  2080. if (old === '') {
  2081. // Mimic the python behaviour: empty string is replaced
  2082. // by replacement e.g. "abc"|replace("", ".") -> .a.b.c.
  2083. res = new_ + str.split('').join(new_) + new_;
  2084. return r.copySafeness(str, res);
  2085. }
  2086. var nextIndex = str.indexOf(old); // if # of replacements to perform is 0, or the string to does
  2087. // not contain the old value, return the string
  2088. if (maxCount === 0 || nextIndex === -1) {
  2089. return str;
  2090. }
  2091. var pos = 0;
  2092. var count = 0; // # of replacements made
  2093. while (nextIndex > -1 && (maxCount === -1 || count < maxCount)) {
  2094. // Grab the next chunk of src string and add it with the
  2095. // replacement, to the result
  2096. res += str.substring(pos, nextIndex) + new_; // Increment our pointer in the src string
  2097. pos = nextIndex + old.length;
  2098. count++; // See if there are any more replacements to be made
  2099. nextIndex = str.indexOf(old, pos);
  2100. } // We've either reached the end, or done the max # of
  2101. // replacements, tack on any remaining string
  2102. if (pos < str.length) {
  2103. res += str.substring(pos);
  2104. }
  2105. return r.copySafeness(originalStr, res);
  2106. }
  2107. exports.replace = replace;
  2108. function reverse(val) {
  2109. var arr;
  2110. if (lib.isString(val)) {
  2111. arr = list(val);
  2112. } else {
  2113. // Copy it
  2114. arr = lib.map(val, function (v) {
  2115. return v;
  2116. });
  2117. }
  2118. arr.reverse();
  2119. if (lib.isString(val)) {
  2120. return r.copySafeness(val, arr.join(''));
  2121. }
  2122. return arr;
  2123. }
  2124. exports.reverse = reverse;
  2125. function round(val, precision, method) {
  2126. precision = precision || 0;
  2127. var factor = Math.pow(10, precision);
  2128. var rounder;
  2129. if (method === 'ceil') {
  2130. rounder = Math.ceil;
  2131. } else if (method === 'floor') {
  2132. rounder = Math.floor;
  2133. } else {
  2134. rounder = Math.round;
  2135. }
  2136. return rounder(val * factor) / factor;
  2137. }
  2138. exports.round = round;
  2139. function slice(arr, slices, fillWith) {
  2140. var sliceLength = Math.floor(arr.length / slices);
  2141. var extra = arr.length % slices;
  2142. var res = [];
  2143. var offset = 0;
  2144. for (var i = 0; i < slices; i++) {
  2145. var start = offset + i * sliceLength;
  2146. if (i < extra) {
  2147. offset++;
  2148. }
  2149. var end = offset + (i + 1) * sliceLength;
  2150. var currSlice = arr.slice(start, end);
  2151. if (fillWith && i >= extra) {
  2152. currSlice.push(fillWith);
  2153. }
  2154. res.push(currSlice);
  2155. }
  2156. return res;
  2157. }
  2158. exports.slice = slice;
  2159. function sum(arr, attr, start) {
  2160. if (start === void 0) {
  2161. start = 0;
  2162. }
  2163. if (attr) {
  2164. arr = lib.map(arr, function (v) {
  2165. return v[attr];
  2166. });
  2167. }
  2168. return start + arr.reduce(function (a, b) {
  2169. return a + b;
  2170. }, 0);
  2171. }
  2172. exports.sum = sum;
  2173. exports.sort = r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function (arr, reversed, caseSens, attr) {
  2174. // Copy it
  2175. var array = lib.map(arr, function (v) {
  2176. return v;
  2177. });
  2178. array.sort(function (a, b) {
  2179. var x = attr ? a[attr] : a;
  2180. var y = attr ? b[attr] : b;
  2181. if (!caseSens && lib.isString(x) && lib.isString(y)) {
  2182. x = x.toLowerCase();
  2183. y = y.toLowerCase();
  2184. }
  2185. if (x < y) {
  2186. return reversed ? 1 : -1;
  2187. } else if (x > y) {
  2188. return reversed ? -1 : 1;
  2189. } else {
  2190. return 0;
  2191. }
  2192. });
  2193. return array;
  2194. });
  2195. function string(obj) {
  2196. return r.copySafeness(obj, obj);
  2197. }
  2198. exports.string = string;
  2199. function striptags(input, preserveLinebreaks) {
  2200. input = normalize(input, '');
  2201. var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;
  2202. var trimmedInput = trim(input.replace(tags, ''));
  2203. var res = '';
  2204. if (preserveLinebreaks) {
  2205. res = trimmedInput.replace(/^ +| +$/gm, '') // remove leading and trailing spaces
  2206. .replace(/ +/g, ' ') // squash adjacent spaces
  2207. .replace(/(\r\n)/g, '\n') // normalize linebreaks (CRLF -> LF)
  2208. .replace(/\n\n\n+/g, '\n\n'); // squash abnormal adjacent linebreaks
  2209. } else {
  2210. res = trimmedInput.replace(/\s+/gi, ' ');
  2211. }
  2212. return r.copySafeness(input, res);
  2213. }
  2214. exports.striptags = striptags;
  2215. function title(str) {
  2216. str = normalize(str, '');
  2217. var words = str.split(' ').map(function (word) {
  2218. return capitalize(word);
  2219. });
  2220. return r.copySafeness(str, words.join(' '));
  2221. }
  2222. exports.title = title;
  2223. function trim(str) {
  2224. return r.copySafeness(str, str.replace(/^\s*|\s*$/g, ''));
  2225. }
  2226. exports.trim = trim;
  2227. function truncate(input, length, killwords, end) {
  2228. var orig = input;
  2229. input = normalize(input, '');
  2230. length = length || 255;
  2231. if (input.length <= length) {
  2232. return input;
  2233. }
  2234. if (killwords) {
  2235. input = input.substring(0, length);
  2236. } else {
  2237. var idx = input.lastIndexOf(' ', length);
  2238. if (idx === -1) {
  2239. idx = length;
  2240. }
  2241. input = input.substring(0, idx);
  2242. }
  2243. input += end !== undefined && end !== null ? end : '...';
  2244. return r.copySafeness(orig, input);
  2245. }
  2246. exports.truncate = truncate;
  2247. function upper(str) {
  2248. str = normalize(str, '');
  2249. return str.toUpperCase();
  2250. }
  2251. exports.upper = upper;
  2252. function urlencode(obj) {
  2253. var enc = encodeURIComponent;
  2254. if (lib.isString(obj)) {
  2255. return enc(obj);
  2256. } else {
  2257. var keyvals = lib.isArray(obj) ? obj : lib._entries(obj);
  2258. return keyvals.map(function (_ref2) {
  2259. var k = _ref2[0],
  2260. v = _ref2[1];
  2261. return enc(k) + "=" + enc(v);
  2262. }).join('&');
  2263. }
  2264. }
  2265. exports.urlencode = urlencode; // For the jinja regexp, see
  2266. // https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
  2267. var puncRe = /^(?:\(|<|&lt;)?(.*?)(?:\.|,|\)|\n|&gt;)?$/; // from http://blog.gerv.net/2011/05/html5_email_address_regexp/
  2268. var emailRe = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
  2269. var httpHttpsRe = /^https?:\/\/.*$/;
  2270. var wwwRe = /^www\./;
  2271. var tldRe = /\.(?:org|net|com)(?:\:|\/|$)/;
  2272. function urlize(str, length, nofollow) {
  2273. if (isNaN(length)) {
  2274. length = Infinity;
  2275. }
  2276. var noFollowAttr = nofollow === true ? ' rel="nofollow"' : '';
  2277. var words = str.split(/(\s+)/).filter(function (word) {
  2278. // If the word has no length, bail. This can happen for str with
  2279. // trailing whitespace.
  2280. return word && word.length;
  2281. }).map(function (word) {
  2282. var matches = word.match(puncRe);
  2283. var possibleUrl = matches ? matches[1] : word;
  2284. var shortUrl = possibleUrl.substr(0, length); // url that starts with http or https
  2285. if (httpHttpsRe.test(possibleUrl)) {
  2286. return "<a href=\"" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2287. } // url that starts with www.
  2288. if (wwwRe.test(possibleUrl)) {
  2289. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2290. } // an email address of the form username@domain.tld
  2291. if (emailRe.test(possibleUrl)) {
  2292. return "<a href=\"mailto:" + possibleUrl + "\">" + possibleUrl + "</a>";
  2293. } // url that ends in .com, .org or .net that is not an email address
  2294. if (tldRe.test(possibleUrl)) {
  2295. return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
  2296. }
  2297. return word;
  2298. });
  2299. return words.join('');
  2300. }
  2301. exports.urlize = urlize;
  2302. function wordcount(str) {
  2303. str = normalize(str, '');
  2304. var words = str ? str.match(/\w+/g) : null;
  2305. return words ? words.length : null;
  2306. }
  2307. exports.wordcount = wordcount;
  2308. function float(val, def) {
  2309. var res = parseFloat(val);
  2310. return isNaN(res) ? def : res;
  2311. }
  2312. exports.float = float;
  2313. function int(val, def) {
  2314. var res = parseInt(val, 10);
  2315. return isNaN(res) ? def : res;
  2316. }
  2317. exports.int = int; // Aliases
  2318. exports.d = exports.default;
  2319. exports.e = exports.escape;
  2320. /***/ }),
  2321. /* 13 */
  2322. /***/ (function(module, exports, __webpack_require__) {
  2323. "use strict";
  2324. // Copyright Joyent, Inc. and other Node contributors.
  2325. //
  2326. // Permission is hereby granted, free of charge, to any person obtaining a
  2327. // copy of this software and associated documentation files (the
  2328. // "Software"), to deal in the Software without restriction, including
  2329. // without limitation the rights to use, copy, modify, merge, publish,
  2330. // distribute, sublicense, and/or sell copies of the Software, and to permit
  2331. // persons to whom the Software is furnished to do so, subject to the
  2332. // following conditions:
  2333. //
  2334. // The above copyright notice and this permission notice shall be included
  2335. // in all copies or substantial portions of the Software.
  2336. //
  2337. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  2338. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  2339. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  2340. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  2341. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  2342. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  2343. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  2344. var R = typeof Reflect === 'object' ? Reflect : null
  2345. var ReflectApply = R && typeof R.apply === 'function'
  2346. ? R.apply
  2347. : function ReflectApply(target, receiver, args) {
  2348. return Function.prototype.apply.call(target, receiver, args);
  2349. }
  2350. var ReflectOwnKeys
  2351. if (R && typeof R.ownKeys === 'function') {
  2352. ReflectOwnKeys = R.ownKeys
  2353. } else if (Object.getOwnPropertySymbols) {
  2354. ReflectOwnKeys = function ReflectOwnKeys(target) {
  2355. return Object.getOwnPropertyNames(target)
  2356. .concat(Object.getOwnPropertySymbols(target));
  2357. };
  2358. } else {
  2359. ReflectOwnKeys = function ReflectOwnKeys(target) {
  2360. return Object.getOwnPropertyNames(target);
  2361. };
  2362. }
  2363. function ProcessEmitWarning(warning) {
  2364. if (console && console.warn) console.warn(warning);
  2365. }
  2366. var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
  2367. return value !== value;
  2368. }
  2369. function EventEmitter() {
  2370. EventEmitter.init.call(this);
  2371. }
  2372. module.exports = EventEmitter;
  2373. // Backwards-compat with node 0.10.x
  2374. EventEmitter.EventEmitter = EventEmitter;
  2375. EventEmitter.prototype._events = undefined;
  2376. EventEmitter.prototype._eventsCount = 0;
  2377. EventEmitter.prototype._maxListeners = undefined;
  2378. // By default EventEmitters will print a warning if more than 10 listeners are
  2379. // added to it. This is a useful default which helps finding memory leaks.
  2380. var defaultMaxListeners = 10;
  2381. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  2382. enumerable: true,
  2383. get: function() {
  2384. return defaultMaxListeners;
  2385. },
  2386. set: function(arg) {
  2387. if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
  2388. throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
  2389. }
  2390. defaultMaxListeners = arg;
  2391. }
  2392. });
  2393. EventEmitter.init = function() {
  2394. if (this._events === undefined ||
  2395. this._events === Object.getPrototypeOf(this)._events) {
  2396. this._events = Object.create(null);
  2397. this._eventsCount = 0;
  2398. }
  2399. this._maxListeners = this._maxListeners || undefined;
  2400. };
  2401. // Obviously not all Emitters should be limited to 10. This function allows
  2402. // that to be increased. Set to zero for unlimited.
  2403. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  2404. if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
  2405. throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
  2406. }
  2407. this._maxListeners = n;
  2408. return this;
  2409. };
  2410. function $getMaxListeners(that) {
  2411. if (that._maxListeners === undefined)
  2412. return EventEmitter.defaultMaxListeners;
  2413. return that._maxListeners;
  2414. }
  2415. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  2416. return $getMaxListeners(this);
  2417. };
  2418. EventEmitter.prototype.emit = function emit(type) {
  2419. var args = [];
  2420. for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
  2421. var doError = (type === 'error');
  2422. var events = this._events;
  2423. if (events !== undefined)
  2424. doError = (doError && events.error === undefined);
  2425. else if (!doError)
  2426. return false;
  2427. // If there is no 'error' event listener then throw.
  2428. if (doError) {
  2429. var er;
  2430. if (args.length > 0)
  2431. er = args[0];
  2432. if (er instanceof Error) {
  2433. // Note: The comments on the `throw` lines are intentional, they show
  2434. // up in Node's output if this results in an unhandled exception.
  2435. throw er; // Unhandled 'error' event
  2436. }
  2437. // At least give some kind of context to the user
  2438. var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
  2439. err.context = er;
  2440. throw err; // Unhandled 'error' event
  2441. }
  2442. var handler = events[type];
  2443. if (handler === undefined)
  2444. return false;
  2445. if (typeof handler === 'function') {
  2446. ReflectApply(handler, this, args);
  2447. } else {
  2448. var len = handler.length;
  2449. var listeners = arrayClone(handler, len);
  2450. for (var i = 0; i < len; ++i)
  2451. ReflectApply(listeners[i], this, args);
  2452. }
  2453. return true;
  2454. };
  2455. function _addListener(target, type, listener, prepend) {
  2456. var m;
  2457. var events;
  2458. var existing;
  2459. if (typeof listener !== 'function') {
  2460. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  2461. }
  2462. events = target._events;
  2463. if (events === undefined) {
  2464. events = target._events = Object.create(null);
  2465. target._eventsCount = 0;
  2466. } else {
  2467. // To avoid recursion in the case that type === "newListener"! Before
  2468. // adding it to the listeners, first emit "newListener".
  2469. if (events.newListener !== undefined) {
  2470. target.emit('newListener', type,
  2471. listener.listener ? listener.listener : listener);
  2472. // Re-assign `events` because a newListener handler could have caused the
  2473. // this._events to be assigned to a new object
  2474. events = target._events;
  2475. }
  2476. existing = events[type];
  2477. }
  2478. if (existing === undefined) {
  2479. // Optimize the case of one listener. Don't need the extra array object.
  2480. existing = events[type] = listener;
  2481. ++target._eventsCount;
  2482. } else {
  2483. if (typeof existing === 'function') {
  2484. // Adding the second element, need to change to array.
  2485. existing = events[type] =
  2486. prepend ? [listener, existing] : [existing, listener];
  2487. // If we've already got an array, just append.
  2488. } else if (prepend) {
  2489. existing.unshift(listener);
  2490. } else {
  2491. existing.push(listener);
  2492. }
  2493. // Check for listener leak
  2494. m = $getMaxListeners(target);
  2495. if (m > 0 && existing.length > m && !existing.warned) {
  2496. existing.warned = true;
  2497. // No error code for this since it is a Warning
  2498. // eslint-disable-next-line no-restricted-syntax
  2499. var w = new Error('Possible EventEmitter memory leak detected. ' +
  2500. existing.length + ' ' + String(type) + ' listeners ' +
  2501. 'added. Use emitter.setMaxListeners() to ' +
  2502. 'increase limit');
  2503. w.name = 'MaxListenersExceededWarning';
  2504. w.emitter = target;
  2505. w.type = type;
  2506. w.count = existing.length;
  2507. ProcessEmitWarning(w);
  2508. }
  2509. }
  2510. return target;
  2511. }
  2512. EventEmitter.prototype.addListener = function addListener(type, listener) {
  2513. return _addListener(this, type, listener, false);
  2514. };
  2515. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  2516. EventEmitter.prototype.prependListener =
  2517. function prependListener(type, listener) {
  2518. return _addListener(this, type, listener, true);
  2519. };
  2520. function onceWrapper() {
  2521. var args = [];
  2522. for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
  2523. if (!this.fired) {
  2524. this.target.removeListener(this.type, this.wrapFn);
  2525. this.fired = true;
  2526. ReflectApply(this.listener, this.target, args);
  2527. }
  2528. }
  2529. function _onceWrap(target, type, listener) {
  2530. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  2531. var wrapped = onceWrapper.bind(state);
  2532. wrapped.listener = listener;
  2533. state.wrapFn = wrapped;
  2534. return wrapped;
  2535. }
  2536. EventEmitter.prototype.once = function once(type, listener) {
  2537. if (typeof listener !== 'function') {
  2538. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  2539. }
  2540. this.on(type, _onceWrap(this, type, listener));
  2541. return this;
  2542. };
  2543. EventEmitter.prototype.prependOnceListener =
  2544. function prependOnceListener(type, listener) {
  2545. if (typeof listener !== 'function') {
  2546. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  2547. }
  2548. this.prependListener(type, _onceWrap(this, type, listener));
  2549. return this;
  2550. };
  2551. // Emits a 'removeListener' event if and only if the listener was removed.
  2552. EventEmitter.prototype.removeListener =
  2553. function removeListener(type, listener) {
  2554. var list, events, position, i, originalListener;
  2555. if (typeof listener !== 'function') {
  2556. throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
  2557. }
  2558. events = this._events;
  2559. if (events === undefined)
  2560. return this;
  2561. list = events[type];
  2562. if (list === undefined)
  2563. return this;
  2564. if (list === listener || list.listener === listener) {
  2565. if (--this._eventsCount === 0)
  2566. this._events = Object.create(null);
  2567. else {
  2568. delete events[type];
  2569. if (events.removeListener)
  2570. this.emit('removeListener', type, list.listener || listener);
  2571. }
  2572. } else if (typeof list !== 'function') {
  2573. position = -1;
  2574. for (i = list.length - 1; i >= 0; i--) {
  2575. if (list[i] === listener || list[i].listener === listener) {
  2576. originalListener = list[i].listener;
  2577. position = i;
  2578. break;
  2579. }
  2580. }
  2581. if (position < 0)
  2582. return this;
  2583. if (position === 0)
  2584. list.shift();
  2585. else {
  2586. spliceOne(list, position);
  2587. }
  2588. if (list.length === 1)
  2589. events[type] = list[0];
  2590. if (events.removeListener !== undefined)
  2591. this.emit('removeListener', type, originalListener || listener);
  2592. }
  2593. return this;
  2594. };
  2595. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  2596. EventEmitter.prototype.removeAllListeners =
  2597. function removeAllListeners(type) {
  2598. var listeners, events, i;
  2599. events = this._events;
  2600. if (events === undefined)
  2601. return this;
  2602. // not listening for removeListener, no need to emit
  2603. if (events.removeListener === undefined) {
  2604. if (arguments.length === 0) {
  2605. this._events = Object.create(null);
  2606. this._eventsCount = 0;
  2607. } else if (events[type] !== undefined) {
  2608. if (--this._eventsCount === 0)
  2609. this._events = Object.create(null);
  2610. else
  2611. delete events[type];
  2612. }
  2613. return this;
  2614. }
  2615. // emit removeListener for all listeners on all events
  2616. if (arguments.length === 0) {
  2617. var keys = Object.keys(events);
  2618. var key;
  2619. for (i = 0; i < keys.length; ++i) {
  2620. key = keys[i];
  2621. if (key === 'removeListener') continue;
  2622. this.removeAllListeners(key);
  2623. }
  2624. this.removeAllListeners('removeListener');
  2625. this._events = Object.create(null);
  2626. this._eventsCount = 0;
  2627. return this;
  2628. }
  2629. listeners = events[type];
  2630. if (typeof listeners === 'function') {
  2631. this.removeListener(type, listeners);
  2632. } else if (listeners !== undefined) {
  2633. // LIFO order
  2634. for (i = listeners.length - 1; i >= 0; i--) {
  2635. this.removeListener(type, listeners[i]);
  2636. }
  2637. }
  2638. return this;
  2639. };
  2640. function _listeners(target, type, unwrap) {
  2641. var events = target._events;
  2642. if (events === undefined)
  2643. return [];
  2644. var evlistener = events[type];
  2645. if (evlistener === undefined)
  2646. return [];
  2647. if (typeof evlistener === 'function')
  2648. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  2649. return unwrap ?
  2650. unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  2651. }
  2652. EventEmitter.prototype.listeners = function listeners(type) {
  2653. return _listeners(this, type, true);
  2654. };
  2655. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  2656. return _listeners(this, type, false);
  2657. };
  2658. EventEmitter.listenerCount = function(emitter, type) {
  2659. if (typeof emitter.listenerCount === 'function') {
  2660. return emitter.listenerCount(type);
  2661. } else {
  2662. return listenerCount.call(emitter, type);
  2663. }
  2664. };
  2665. EventEmitter.prototype.listenerCount = listenerCount;
  2666. function listenerCount(type) {
  2667. var events = this._events;
  2668. if (events !== undefined) {
  2669. var evlistener = events[type];
  2670. if (typeof evlistener === 'function') {
  2671. return 1;
  2672. } else if (evlistener !== undefined) {
  2673. return evlistener.length;
  2674. }
  2675. }
  2676. return 0;
  2677. }
  2678. EventEmitter.prototype.eventNames = function eventNames() {
  2679. return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
  2680. };
  2681. function arrayClone(arr, n) {
  2682. var copy = new Array(n);
  2683. for (var i = 0; i < n; ++i)
  2684. copy[i] = arr[i];
  2685. return copy;
  2686. }
  2687. function spliceOne(list, index) {
  2688. for (; index + 1 < list.length; index++)
  2689. list[index] = list[index + 1];
  2690. list.pop();
  2691. }
  2692. function unwrapListeners(arr) {
  2693. var ret = new Array(arr.length);
  2694. for (var i = 0; i < ret.length; ++i) {
  2695. ret[i] = arr[i].listener || arr[i];
  2696. }
  2697. return ret;
  2698. }
  2699. /***/ }),
  2700. /* 14 */
  2701. /***/ (function(module, exports, __webpack_require__) {
  2702. "use strict";
  2703. var SafeString = __webpack_require__(2).SafeString;
  2704. /**
  2705. * Returns `true` if the object is a function, otherwise `false`.
  2706. * @param { any } value
  2707. * @returns { boolean }
  2708. */
  2709. function callable(value) {
  2710. return typeof value === 'function';
  2711. }
  2712. exports.callable = callable;
  2713. /**
  2714. * Returns `true` if the object is strictly not `undefined`.
  2715. * @param { any } value
  2716. * @returns { boolean }
  2717. */
  2718. function defined(value) {
  2719. return value !== undefined;
  2720. }
  2721. exports.defined = defined;
  2722. /**
  2723. * Returns `true` if the operand (one) is divisble by the test's argument
  2724. * (two).
  2725. * @param { number } one
  2726. * @param { number } two
  2727. * @returns { boolean }
  2728. */
  2729. function divisibleby(one, two) {
  2730. return one % two === 0;
  2731. }
  2732. exports.divisibleby = divisibleby;
  2733. /**
  2734. * Returns true if the string has been escaped (i.e., is a SafeString).
  2735. * @param { any } value
  2736. * @returns { boolean }
  2737. */
  2738. function escaped(value) {
  2739. return value instanceof SafeString;
  2740. }
  2741. exports.escaped = escaped;
  2742. /**
  2743. * Returns `true` if the arguments are strictly equal.
  2744. * @param { any } one
  2745. * @param { any } two
  2746. */
  2747. function equalto(one, two) {
  2748. return one === two;
  2749. }
  2750. exports.equalto = equalto; // Aliases
  2751. exports.eq = exports.equalto;
  2752. exports.sameas = exports.equalto;
  2753. /**
  2754. * Returns `true` if the value is evenly divisible by 2.
  2755. * @param { number } value
  2756. * @returns { boolean }
  2757. */
  2758. function even(value) {
  2759. return value % 2 === 0;
  2760. }
  2761. exports.even = even;
  2762. /**
  2763. * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
  2764. * undefined, NaN or null. I don't know if we should stick to the default JS
  2765. * behavior or attempt to replicate what Python believes should be falsy (i.e.,
  2766. * empty arrays, empty dicts, not 0...).
  2767. * @param { any } value
  2768. * @returns { boolean }
  2769. */
  2770. function falsy(value) {
  2771. return !value;
  2772. }
  2773. exports.falsy = falsy;
  2774. /**
  2775. * Returns `true` if the operand (one) is greater or equal to the test's
  2776. * argument (two).
  2777. * @param { number } one
  2778. * @param { number } two
  2779. * @returns { boolean }
  2780. */
  2781. function ge(one, two) {
  2782. return one >= two;
  2783. }
  2784. exports.ge = ge;
  2785. /**
  2786. * Returns `true` if the operand (one) is greater than the test's argument
  2787. * (two).
  2788. * @param { number } one
  2789. * @param { number } two
  2790. * @returns { boolean }
  2791. */
  2792. function greaterthan(one, two) {
  2793. return one > two;
  2794. }
  2795. exports.greaterthan = greaterthan; // alias
  2796. exports.gt = exports.greaterthan;
  2797. /**
  2798. * Returns `true` if the operand (one) is less than or equal to the test's
  2799. * argument (two).
  2800. * @param { number } one
  2801. * @param { number } two
  2802. * @returns { boolean }
  2803. */
  2804. function le(one, two) {
  2805. return one <= two;
  2806. }
  2807. exports.le = le;
  2808. /**
  2809. * Returns `true` if the operand (one) is less than the test's passed argument
  2810. * (two).
  2811. * @param { number } one
  2812. * @param { number } two
  2813. * @returns { boolean }
  2814. */
  2815. function lessthan(one, two) {
  2816. return one < two;
  2817. }
  2818. exports.lessthan = lessthan; // alias
  2819. exports.lt = exports.lessthan;
  2820. /**
  2821. * Returns `true` if the string is lowercased.
  2822. * @param { string } value
  2823. * @returns { boolean }
  2824. */
  2825. function lower(value) {
  2826. return value.toLowerCase() === value;
  2827. }
  2828. exports.lower = lower;
  2829. /**
  2830. * Returns `true` if the operand (one) is less than or equal to the test's
  2831. * argument (two).
  2832. * @param { number } one
  2833. * @param { number } two
  2834. * @returns { boolean }
  2835. */
  2836. function ne(one, two) {
  2837. return one !== two;
  2838. }
  2839. exports.ne = ne;
  2840. /**
  2841. * Returns true if the value is strictly equal to `null`.
  2842. * @param { any }
  2843. * @returns { boolean }
  2844. */
  2845. function nullTest(value) {
  2846. return value === null;
  2847. }
  2848. exports.null = nullTest;
  2849. /**
  2850. * Returns true if value is a number.
  2851. * @param { any }
  2852. * @returns { boolean }
  2853. */
  2854. function number(value) {
  2855. return typeof value === 'number';
  2856. }
  2857. exports.number = number;
  2858. /**
  2859. * Returns `true` if the value is *not* evenly divisible by 2.
  2860. * @param { number } value
  2861. * @returns { boolean }
  2862. */
  2863. function odd(value) {
  2864. return value % 2 === 1;
  2865. }
  2866. exports.odd = odd;
  2867. /**
  2868. * Returns `true` if the value is a string, `false` if not.
  2869. * @param { any } value
  2870. * @returns { boolean }
  2871. */
  2872. function string(value) {
  2873. return typeof value === 'string';
  2874. }
  2875. exports.string = string;
  2876. /**
  2877. * Returns `true` if the value is not in the list of things considered falsy:
  2878. * '', null, undefined, 0, NaN and false.
  2879. * @param { any } value
  2880. * @returns { boolean }
  2881. */
  2882. function truthy(value) {
  2883. return !!value;
  2884. }
  2885. exports.truthy = truthy;
  2886. /**
  2887. * Returns `true` if the value is undefined.
  2888. * @param { any } value
  2889. * @returns { boolean }
  2890. */
  2891. function undefinedTest(value) {
  2892. return value === undefined;
  2893. }
  2894. exports.undefined = undefinedTest;
  2895. /**
  2896. * Returns `true` if the string is uppercased.
  2897. * @param { string } value
  2898. * @returns { boolean }
  2899. */
  2900. function upper(value) {
  2901. return value.toUpperCase() === value;
  2902. }
  2903. exports.upper = upper;
  2904. /**
  2905. * If ES6 features are available, returns `true` if the value implements the
  2906. * `Symbol.iterator` method. If not, it's a string or Array.
  2907. *
  2908. * Could potentially cause issues if a browser exists that has Set and Map but
  2909. * not Symbol.
  2910. *
  2911. * @param { any } value
  2912. * @returns { boolean }
  2913. */
  2914. function iterable(value) {
  2915. if (typeof Symbol !== 'undefined') {
  2916. return !!value[Symbol.iterator];
  2917. } else {
  2918. return Array.isArray(value) || typeof value === 'string';
  2919. }
  2920. }
  2921. exports.iterable = iterable;
  2922. /**
  2923. * If ES6 features are available, returns `true` if the value is an object hash
  2924. * or an ES6 Map. Otherwise just return if it's an object hash.
  2925. * @param { any } value
  2926. * @returns { boolean }
  2927. */
  2928. function mapping(value) {
  2929. // only maps and object hashes
  2930. var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
  2931. if (Set) {
  2932. return bool && !(value instanceof Set);
  2933. } else {
  2934. return bool;
  2935. }
  2936. }
  2937. exports.mapping = mapping;
  2938. /***/ }),
  2939. /* 15 */
  2940. /***/ (function(module, exports, __webpack_require__) {
  2941. "use strict";
  2942. function _cycler(items) {
  2943. var index = -1;
  2944. return {
  2945. current: null,
  2946. reset: function reset() {
  2947. index = -1;
  2948. this.current = null;
  2949. },
  2950. next: function next() {
  2951. index++;
  2952. if (index >= items.length) {
  2953. index = 0;
  2954. }
  2955. this.current = items[index];
  2956. return this.current;
  2957. }
  2958. };
  2959. }
  2960. function _joiner(sep) {
  2961. sep = sep || ',';
  2962. var first = true;
  2963. return function () {
  2964. var val = first ? '' : sep;
  2965. first = false;
  2966. return val;
  2967. };
  2968. } // Making this a function instead so it returns a new object
  2969. // each time it's called. That way, if something like an environment
  2970. // uses it, they will each have their own copy.
  2971. function globals() {
  2972. return {
  2973. range: function range(start, stop, step) {
  2974. if (typeof stop === 'undefined') {
  2975. stop = start;
  2976. start = 0;
  2977. step = 1;
  2978. } else if (!step) {
  2979. step = 1;
  2980. }
  2981. var arr = [];
  2982. if (step > 0) {
  2983. for (var i = start; i < stop; i += step) {
  2984. arr.push(i);
  2985. }
  2986. } else {
  2987. for (var _i = start; _i > stop; _i += step) {
  2988. // eslint-disable-line for-direction
  2989. arr.push(_i);
  2990. }
  2991. }
  2992. return arr;
  2993. },
  2994. cycler: function cycler() {
  2995. return _cycler(Array.prototype.slice.call(arguments));
  2996. },
  2997. joiner: function joiner(sep) {
  2998. return _joiner(sep);
  2999. }
  3000. };
  3001. }
  3002. module.exports = globals;
  3003. /***/ }),
  3004. /* 16 */
  3005. /***/ (function(module, exports, __webpack_require__) {
  3006. var path = __webpack_require__(0);
  3007. module.exports = function express(env, app) {
  3008. function NunjucksView(name, opts) {
  3009. this.name = name;
  3010. this.path = name;
  3011. this.defaultEngine = opts.defaultEngine;
  3012. this.ext = path.extname(name);
  3013. if (!this.ext && !this.defaultEngine) {
  3014. throw new Error('No default engine was specified and no extension was provided.');
  3015. }
  3016. if (!this.ext) {
  3017. this.name += this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine;
  3018. }
  3019. }
  3020. NunjucksView.prototype.render = function render(opts, cb) {
  3021. env.render(this.name, opts, cb);
  3022. };
  3023. app.set('view', NunjucksView);
  3024. app.set('nunjucksEnv', env);
  3025. return env;
  3026. };
  3027. /***/ }),
  3028. /* 17 */
  3029. /***/ (function(module, exports, __webpack_require__) {
  3030. function installCompat() {
  3031. 'use strict';
  3032. /* eslint-disable camelcase */
  3033. // This must be called like `nunjucks.installCompat` so that `this`
  3034. // references the nunjucks instance
  3035. var runtime = this.runtime;
  3036. var lib = this.lib; // Handle slim case where these 'modules' are excluded from the built source
  3037. var Compiler = this.compiler.Compiler;
  3038. var Parser = this.parser.Parser;
  3039. var nodes = this.nodes;
  3040. var lexer = this.lexer;
  3041. var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
  3042. var orig_memberLookup = runtime.memberLookup;
  3043. var orig_Compiler_assertType;
  3044. var orig_Parser_parseAggregate;
  3045. if (Compiler) {
  3046. orig_Compiler_assertType = Compiler.prototype.assertType;
  3047. }
  3048. if (Parser) {
  3049. orig_Parser_parseAggregate = Parser.prototype.parseAggregate;
  3050. }
  3051. function uninstall() {
  3052. runtime.contextOrFrameLookup = orig_contextOrFrameLookup;
  3053. runtime.memberLookup = orig_memberLookup;
  3054. if (Compiler) {
  3055. Compiler.prototype.assertType = orig_Compiler_assertType;
  3056. }
  3057. if (Parser) {
  3058. Parser.prototype.parseAggregate = orig_Parser_parseAggregate;
  3059. }
  3060. }
  3061. runtime.contextOrFrameLookup = function contextOrFrameLookup(context, frame, key) {
  3062. var val = orig_contextOrFrameLookup.apply(this, arguments);
  3063. if (val !== undefined) {
  3064. return val;
  3065. }
  3066. switch (key) {
  3067. case 'True':
  3068. return true;
  3069. case 'False':
  3070. return false;
  3071. case 'None':
  3072. return null;
  3073. default:
  3074. return undefined;
  3075. }
  3076. };
  3077. function getTokensState(tokens) {
  3078. return {
  3079. index: tokens.index,
  3080. lineno: tokens.lineno,
  3081. colno: tokens.colno
  3082. };
  3083. }
  3084. if (false) {
  3085. // i.e., not slim mode
  3086. var Slice = nodes.Node.extend('Slice', {
  3087. fields: ['start', 'stop', 'step'],
  3088. init: function init(lineno, colno, start, stop, step) {
  3089. start = start || new nodes.Literal(lineno, colno, null);
  3090. stop = stop || new nodes.Literal(lineno, colno, null);
  3091. step = step || new nodes.Literal(lineno, colno, 1);
  3092. this.parent(lineno, colno, start, stop, step);
  3093. }
  3094. });
  3095. Compiler.prototype.assertType = function assertType(node) {
  3096. if (node instanceof Slice) {
  3097. return;
  3098. }
  3099. orig_Compiler_assertType.apply(this, arguments);
  3100. };
  3101. Compiler.prototype.compileSlice = function compileSlice(node, frame) {
  3102. this._emit('(');
  3103. this._compileExpression(node.start, frame);
  3104. this._emit('),(');
  3105. this._compileExpression(node.stop, frame);
  3106. this._emit('),(');
  3107. this._compileExpression(node.step, frame);
  3108. this._emit(')');
  3109. };
  3110. Parser.prototype.parseAggregate = function parseAggregate() {
  3111. var _this = this;
  3112. var origState = getTokensState(this.tokens); // Set back one accounting for opening bracket/parens
  3113. origState.colno--;
  3114. origState.index--;
  3115. try {
  3116. return orig_Parser_parseAggregate.apply(this);
  3117. } catch (e) {
  3118. var errState = getTokensState(this.tokens);
  3119. var rethrow = function rethrow() {
  3120. lib._assign(_this.tokens, errState);
  3121. return e;
  3122. }; // Reset to state before original parseAggregate called
  3123. lib._assign(this.tokens, origState);
  3124. this.peeked = false;
  3125. var tok = this.peekToken();
  3126. if (tok.type !== lexer.TOKEN_LEFT_BRACKET) {
  3127. throw rethrow();
  3128. } else {
  3129. this.nextToken();
  3130. }
  3131. var node = new Slice(tok.lineno, tok.colno); // If we don't encounter a colon while parsing, this is not a slice,
  3132. // so re-raise the original exception.
  3133. var isSlice = false;
  3134. for (var i = 0; i <= node.fields.length; i++) {
  3135. if (this.skip(lexer.TOKEN_RIGHT_BRACKET)) {
  3136. break;
  3137. }
  3138. if (i === node.fields.length) {
  3139. if (isSlice) {
  3140. this.fail('parseSlice: too many slice components', tok.lineno, tok.colno);
  3141. } else {
  3142. break;
  3143. }
  3144. }
  3145. if (this.skip(lexer.TOKEN_COLON)) {
  3146. isSlice = true;
  3147. } else {
  3148. var field = node.fields[i];
  3149. node[field] = this.parseExpression();
  3150. isSlice = this.skip(lexer.TOKEN_COLON) || isSlice;
  3151. }
  3152. }
  3153. if (!isSlice) {
  3154. throw rethrow();
  3155. }
  3156. return new nodes.Array(tok.lineno, tok.colno, [node]);
  3157. }
  3158. };
  3159. }
  3160. function sliceLookup(obj, start, stop, step) {
  3161. obj = obj || [];
  3162. if (start === null) {
  3163. start = step < 0 ? obj.length - 1 : 0;
  3164. }
  3165. if (stop === null) {
  3166. stop = step < 0 ? -1 : obj.length;
  3167. } else if (stop < 0) {
  3168. stop += obj.length;
  3169. }
  3170. if (start < 0) {
  3171. start += obj.length;
  3172. }
  3173. var results = [];
  3174. for (var i = start;; i += step) {
  3175. if (i < 0 || i > obj.length) {
  3176. break;
  3177. }
  3178. if (step > 0 && i >= stop) {
  3179. break;
  3180. }
  3181. if (step < 0 && i <= stop) {
  3182. break;
  3183. }
  3184. results.push(runtime.memberLookup(obj, i));
  3185. }
  3186. return results;
  3187. }
  3188. function hasOwnProp(obj, key) {
  3189. return Object.prototype.hasOwnProperty.call(obj, key);
  3190. }
  3191. var ARRAY_MEMBERS = {
  3192. pop: function pop(index) {
  3193. if (index === undefined) {
  3194. return this.pop();
  3195. }
  3196. if (index >= this.length || index < 0) {
  3197. throw new Error('KeyError');
  3198. }
  3199. return this.splice(index, 1);
  3200. },
  3201. append: function append(element) {
  3202. return this.push(element);
  3203. },
  3204. remove: function remove(element) {
  3205. for (var i = 0; i < this.length; i++) {
  3206. if (this[i] === element) {
  3207. return this.splice(i, 1);
  3208. }
  3209. }
  3210. throw new Error('ValueError');
  3211. },
  3212. count: function count(element) {
  3213. var count = 0;
  3214. for (var i = 0; i < this.length; i++) {
  3215. if (this[i] === element) {
  3216. count++;
  3217. }
  3218. }
  3219. return count;
  3220. },
  3221. index: function index(element) {
  3222. var i;
  3223. if ((i = this.indexOf(element)) === -1) {
  3224. throw new Error('ValueError');
  3225. }
  3226. return i;
  3227. },
  3228. find: function find(element) {
  3229. return this.indexOf(element);
  3230. },
  3231. insert: function insert(index, elem) {
  3232. return this.splice(index, 0, elem);
  3233. }
  3234. };
  3235. var OBJECT_MEMBERS = {
  3236. items: function items() {
  3237. return lib._entries(this);
  3238. },
  3239. values: function values() {
  3240. return lib._values(this);
  3241. },
  3242. keys: function keys() {
  3243. return lib.keys(this);
  3244. },
  3245. get: function get(key, def) {
  3246. var output = this[key];
  3247. if (output === undefined) {
  3248. output = def;
  3249. }
  3250. return output;
  3251. },
  3252. has_key: function has_key(key) {
  3253. return hasOwnProp(this, key);
  3254. },
  3255. pop: function pop(key, def) {
  3256. var output = this[key];
  3257. if (output === undefined && def !== undefined) {
  3258. output = def;
  3259. } else if (output === undefined) {
  3260. throw new Error('KeyError');
  3261. } else {
  3262. delete this[key];
  3263. }
  3264. return output;
  3265. },
  3266. popitem: function popitem() {
  3267. var keys = lib.keys(this);
  3268. if (!keys.length) {
  3269. throw new Error('KeyError');
  3270. }
  3271. var k = keys[0];
  3272. var val = this[k];
  3273. delete this[k];
  3274. return [k, val];
  3275. },
  3276. setdefault: function setdefault(key, def) {
  3277. if (def === void 0) {
  3278. def = null;
  3279. }
  3280. if (!(key in this)) {
  3281. this[key] = def;
  3282. }
  3283. return this[key];
  3284. },
  3285. update: function update(kwargs) {
  3286. lib._assign(this, kwargs);
  3287. return null; // Always returns None
  3288. }
  3289. };
  3290. OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
  3291. OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
  3292. OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
  3293. runtime.memberLookup = function memberLookup(obj, val, autoescape) {
  3294. if (arguments.length === 4) {
  3295. return sliceLookup.apply(this, arguments);
  3296. }
  3297. obj = obj || {}; // If the object is an object, return any of the methods that Python would
  3298. // otherwise provide.
  3299. if (lib.isArray(obj) && hasOwnProp(ARRAY_MEMBERS, val)) {
  3300. return ARRAY_MEMBERS[val].bind(obj);
  3301. }
  3302. if (lib.isObject(obj) && hasOwnProp(OBJECT_MEMBERS, val)) {
  3303. return OBJECT_MEMBERS[val].bind(obj);
  3304. }
  3305. return orig_memberLookup.apply(this, arguments);
  3306. };
  3307. return uninstall;
  3308. }
  3309. module.exports = installCompat;
  3310. /***/ })
  3311. /******/ ]);
  3312. });
  3313. //# sourceMappingURL=nunjucks-slim.js.map