| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165 |
- /*! Browser bundle of nunjucks 3.2.0 (slim, only works with precompiled templates) */
- (function webpackUniversalModuleDefinition(root, factory) {
- if(typeof exports === 'object' && typeof module === 'object')
- module.exports = factory();
- else if(typeof define === 'function' && define.amd)
- define([], factory);
- else if(typeof exports === 'object')
- exports["nunjucks"] = factory();
- else
- root["nunjucks"] = factory();
- })(typeof self !== 'undefined' ? self : this, function() {
- return /******/ (function(modules) { // webpackBootstrap
- /******/ // The module cache
- /******/ var installedModules = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/
- /******/ // Check if module is in cache
- /******/ if(installedModules[moduleId]) {
- /******/ return installedModules[moduleId].exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = installedModules[moduleId] = {
- /******/ i: moduleId,
- /******/ l: false,
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
- /******/
- /******/ // Flag the module as loaded
- /******/ module.l = true;
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /******/
- /******/ // expose the modules object (__webpack_modules__)
- /******/ __webpack_require__.m = modules;
- /******/
- /******/ // expose the module cache
- /******/ __webpack_require__.c = installedModules;
- /******/
- /******/ // define getter function for harmony exports
- /******/ __webpack_require__.d = function(exports, name, getter) {
- /******/ if(!__webpack_require__.o(exports, name)) {
- /******/ Object.defineProperty(exports, name, {
- /******/ configurable: false,
- /******/ enumerable: true,
- /******/ get: getter
- /******/ });
- /******/ }
- /******/ };
- /******/
- /******/ // getDefaultExport function for compatibility with non-harmony modules
- /******/ __webpack_require__.n = function(module) {
- /******/ var getter = module && module.__esModule ?
- /******/ function getDefault() { return module['default']; } :
- /******/ function getModuleExports() { return module; };
- /******/ __webpack_require__.d(getter, 'a', getter);
- /******/ return getter;
- /******/ };
- /******/
- /******/ // Object.prototype.hasOwnProperty.call
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
- /******/
- /******/ // __webpack_public_path__
- /******/ __webpack_require__.p = "";
- /******/
- /******/ // Load entry module and return exports
- /******/ return __webpack_require__(__webpack_require__.s = 6);
- /******/ })
- /************************************************************************/
- /******/ ([
- /* 0 */
- /***/ (function(module, exports) {
- /***/ }),
- /* 1 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var ArrayProto = Array.prototype;
- var ObjProto = Object.prototype;
- var escapeMap = {
- '&': '&',
- '"': '"',
- '\'': ''',
- '<': '<',
- '>': '>'
- };
- var escapeRegex = /[&"'<>]/g;
- var exports = module.exports = {};
- function hasOwnProp(obj, k) {
- return ObjProto.hasOwnProperty.call(obj, k);
- }
- exports.hasOwnProp = hasOwnProp;
- function lookupEscape(ch) {
- return escapeMap[ch];
- }
- function _prettifyError(path, withInternals, err) {
- if (!err.Update) {
- // not one of ours, cast it
- err = new exports.TemplateError(err);
- }
- err.Update(path); // Unless they marked the dev flag, show them a trace from here
- if (!withInternals) {
- var old = err;
- err = new Error(old.message);
- err.name = old.name;
- }
- return err;
- }
- exports._prettifyError = _prettifyError;
- function TemplateError(message, lineno, colno) {
- var err;
- var cause;
- if (message instanceof Error) {
- cause = message;
- message = cause.name + ": " + cause.message;
- }
- if (Object.setPrototypeOf) {
- err = new Error(message);
- Object.setPrototypeOf(err, TemplateError.prototype);
- } else {
- err = this;
- Object.defineProperty(err, 'message', {
- enumerable: false,
- writable: true,
- value: message
- });
- }
- Object.defineProperty(err, 'name', {
- value: 'Template render error'
- });
- if (Error.captureStackTrace) {
- Error.captureStackTrace(err, this.constructor);
- }
- var getStack;
- if (cause) {
- var stackDescriptor = Object.getOwnPropertyDescriptor(cause, 'stack');
- getStack = stackDescriptor && (stackDescriptor.get || function () {
- return stackDescriptor.value;
- });
- if (!getStack) {
- getStack = function getStack() {
- return cause.stack;
- };
- }
- } else {
- var stack = new Error(message).stack;
- getStack = function getStack() {
- return stack;
- };
- }
- Object.defineProperty(err, 'stack', {
- get: function get() {
- return getStack.call(err);
- }
- });
- Object.defineProperty(err, 'cause', {
- value: cause
- });
- err.lineno = lineno;
- err.colno = colno;
- err.firstUpdate = true;
- err.Update = function Update(path) {
- var msg = '(' + (path || 'unknown path') + ')'; // only show lineno + colno next to path of template
- // where error occurred
- if (this.firstUpdate) {
- if (this.lineno && this.colno) {
- msg += " [Line " + this.lineno + ", Column " + this.colno + "]";
- } else if (this.lineno) {
- msg += " [Line " + this.lineno + "]";
- }
- }
- msg += '\n ';
- if (this.firstUpdate) {
- msg += ' ';
- }
- this.message = msg + (this.message || '');
- this.firstUpdate = false;
- return this;
- };
- return err;
- }
- if (Object.setPrototypeOf) {
- Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
- } else {
- TemplateError.prototype = Object.create(Error.prototype, {
- constructor: {
- value: TemplateError
- }
- });
- }
- exports.TemplateError = TemplateError;
- function escape(val) {
- return val.replace(escapeRegex, lookupEscape);
- }
- exports.escape = escape;
- function isFunction(obj) {
- return ObjProto.toString.call(obj) === '[object Function]';
- }
- exports.isFunction = isFunction;
- function isArray(obj) {
- return ObjProto.toString.call(obj) === '[object Array]';
- }
- exports.isArray = isArray;
- function isString(obj) {
- return ObjProto.toString.call(obj) === '[object String]';
- }
- exports.isString = isString;
- function isObject(obj) {
- return ObjProto.toString.call(obj) === '[object Object]';
- }
- exports.isObject = isObject;
- function groupBy(obj, val) {
- var result = {};
- var iterator = isFunction(val) ? val : function (o) {
- return o[val];
- };
- for (var i = 0; i < obj.length; i++) {
- var value = obj[i];
- var key = iterator(value, i);
- (result[key] || (result[key] = [])).push(value);
- }
- return result;
- }
- exports.groupBy = groupBy;
- function toArray(obj) {
- return Array.prototype.slice.call(obj);
- }
- exports.toArray = toArray;
- function without(array) {
- var result = [];
- if (!array) {
- return result;
- }
- var length = array.length;
- var contains = toArray(arguments).slice(1);
- var index = -1;
- while (++index < length) {
- if (indexOf(contains, array[index]) === -1) {
- result.push(array[index]);
- }
- }
- return result;
- }
- exports.without = without;
- function repeat(char_, n) {
- var str = '';
- for (var i = 0; i < n; i++) {
- str += char_;
- }
- return str;
- }
- exports.repeat = repeat;
- function each(obj, func, context) {
- if (obj == null) {
- return;
- }
- if (ArrayProto.forEach && obj.forEach === ArrayProto.forEach) {
- obj.forEach(func, context);
- } else if (obj.length === +obj.length) {
- for (var i = 0, l = obj.length; i < l; i++) {
- func.call(context, obj[i], i, obj);
- }
- }
- }
- exports.each = each;
- function map(obj, func) {
- var results = [];
- if (obj == null) {
- return results;
- }
- if (ArrayProto.map && obj.map === ArrayProto.map) {
- return obj.map(func);
- }
- for (var i = 0; i < obj.length; i++) {
- results[results.length] = func(obj[i], i);
- }
- if (obj.length === +obj.length) {
- results.length = obj.length;
- }
- return results;
- }
- exports.map = map;
- function asyncIter(arr, iter, cb) {
- var i = -1;
- function next() {
- i++;
- if (i < arr.length) {
- iter(arr[i], i, next, cb);
- } else {
- cb();
- }
- }
- next();
- }
- exports.asyncIter = asyncIter;
- function asyncFor(obj, iter, cb) {
- var keys = keys_(obj || {});
- var len = keys.length;
- var i = -1;
- function next() {
- i++;
- var k = keys[i];
- if (i < len) {
- iter(k, obj[k], i, len, next);
- } else {
- cb();
- }
- }
- next();
- }
- exports.asyncFor = asyncFor;
- function indexOf(arr, searchElement, fromIndex) {
- return Array.prototype.indexOf.call(arr || [], searchElement, fromIndex);
- }
- exports.indexOf = indexOf;
- function keys_(obj) {
- /* eslint-disable no-restricted-syntax */
- var arr = [];
- for (var k in obj) {
- if (hasOwnProp(obj, k)) {
- arr.push(k);
- }
- }
- return arr;
- }
- exports.keys = keys_;
- function _entries(obj) {
- return keys_(obj).map(function (k) {
- return [k, obj[k]];
- });
- }
- exports._entries = _entries;
- function _values(obj) {
- return keys_(obj).map(function (k) {
- return obj[k];
- });
- }
- exports._values = _values;
- function extend(obj1, obj2) {
- obj1 = obj1 || {};
- keys_(obj2).forEach(function (k) {
- obj1[k] = obj2[k];
- });
- return obj1;
- }
- exports._assign = exports.extend = extend;
- function inOperator(key, val) {
- if (isArray(val) || isString(val)) {
- return val.indexOf(key) !== -1;
- } else if (isObject(val)) {
- return key in val;
- }
- throw new Error('Cannot use "in" operator to search for "' + key + '" in unexpected types.');
- }
- exports.inOperator = inOperator;
- /***/ }),
- /* 2 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var lib = __webpack_require__(1);
- var arrayFrom = Array.from;
- var supportsIterators = typeof Symbol === 'function' && Symbol.iterator && typeof arrayFrom === 'function'; // Frames keep track of scoping both at compile-time and run-time so
- // we know how to access variables. Block tags can introduce special
- // variables, for example.
- var Frame =
- /*#__PURE__*/
- function () {
- function Frame(parent, isolateWrites) {
- this.variables = {};
- this.parent = parent;
- this.topLevel = false; // if this is true, writes (set) should never propagate upwards past
- // this frame to its parent (though reads may).
- this.isolateWrites = isolateWrites;
- }
- var _proto = Frame.prototype;
- _proto.set = function set(name, val, resolveUp) {
- // Allow variables with dots by automatically creating the
- // nested structure
- var parts = name.split('.');
- var obj = this.variables;
- var frame = this;
- if (resolveUp) {
- if (frame = this.resolve(parts[0], true)) {
- frame.set(name, val);
- return;
- }
- }
- for (var i = 0; i < parts.length - 1; i++) {
- var id = parts[i];
- if (!obj[id]) {
- obj[id] = {};
- }
- obj = obj[id];
- }
- obj[parts[parts.length - 1]] = val;
- };
- _proto.get = function get(name) {
- var val = this.variables[name];
- if (val !== undefined) {
- return val;
- }
- return null;
- };
- _proto.lookup = function lookup(name) {
- var p = this.parent;
- var val = this.variables[name];
- if (val !== undefined) {
- return val;
- }
- return p && p.lookup(name);
- };
- _proto.resolve = function resolve(name, forWrite) {
- var p = forWrite && this.isolateWrites ? undefined : this.parent;
- var val = this.variables[name];
- if (val !== undefined) {
- return this;
- }
- return p && p.resolve(name);
- };
- _proto.push = function push(isolateWrites) {
- return new Frame(this, isolateWrites);
- };
- _proto.pop = function pop() {
- return this.parent;
- };
- return Frame;
- }();
- function makeMacro(argNames, kwargNames, func) {
- var _this = this;
- return function () {
- for (var _len = arguments.length, macroArgs = new Array(_len), _key = 0; _key < _len; _key++) {
- macroArgs[_key] = arguments[_key];
- }
- var argCount = numArgs(macroArgs);
- var args;
- var kwargs = getKeywordArgs(macroArgs);
- if (argCount > argNames.length) {
- args = macroArgs.slice(0, argNames.length); // Positional arguments that should be passed in as
- // keyword arguments (essentially default values)
- macroArgs.slice(args.length, argCount).forEach(function (val, i) {
- if (i < kwargNames.length) {
- kwargs[kwargNames[i]] = val;
- }
- });
- args.push(kwargs);
- } else if (argCount < argNames.length) {
- args = macroArgs.slice(0, argCount);
- for (var i = argCount; i < argNames.length; i++) {
- var arg = argNames[i]; // Keyword arguments that should be passed as
- // positional arguments, i.e. the caller explicitly
- // used the name of a positional arg
- args.push(kwargs[arg]);
- delete kwargs[arg];
- }
- args.push(kwargs);
- } else {
- args = macroArgs;
- }
- return func.apply(_this, args);
- };
- }
- function makeKeywordArgs(obj) {
- obj.__keywords = true;
- return obj;
- }
- function isKeywordArgs(obj) {
- return obj && Object.prototype.hasOwnProperty.call(obj, '__keywords');
- }
- function getKeywordArgs(args) {
- var len = args.length;
- if (len) {
- var lastArg = args[len - 1];
- if (isKeywordArgs(lastArg)) {
- return lastArg;
- }
- }
- return {};
- }
- function numArgs(args) {
- var len = args.length;
- if (len === 0) {
- return 0;
- }
- var lastArg = args[len - 1];
- if (isKeywordArgs(lastArg)) {
- return len - 1;
- } else {
- return len;
- }
- } // A SafeString object indicates that the string should not be
- // autoescaped. This happens magically because autoescaping only
- // occurs on primitive string objects.
- function SafeString(val) {
- if (typeof val !== 'string') {
- return val;
- }
- this.val = val;
- this.length = val.length;
- }
- SafeString.prototype = Object.create(String.prototype, {
- length: {
- writable: true,
- configurable: true,
- value: 0
- }
- });
- SafeString.prototype.valueOf = function valueOf() {
- return this.val;
- };
- SafeString.prototype.toString = function toString() {
- return this.val;
- };
- function copySafeness(dest, target) {
- if (dest instanceof SafeString) {
- return new SafeString(target);
- }
- return target.toString();
- }
- function markSafe(val) {
- var type = typeof val;
- if (type === 'string') {
- return new SafeString(val);
- } else if (type !== 'function') {
- return val;
- } else {
- return function wrapSafe(args) {
- var ret = val.apply(this, arguments);
- if (typeof ret === 'string') {
- return new SafeString(ret);
- }
- return ret;
- };
- }
- }
- function suppressValue(val, autoescape) {
- val = val !== undefined && val !== null ? val : '';
- if (autoescape && !(val instanceof SafeString)) {
- val = lib.escape(val.toString());
- }
- return val;
- }
- function ensureDefined(val, lineno, colno) {
- if (val === null || val === undefined) {
- throw new lib.TemplateError('attempted to output null or undefined value', lineno + 1, colno + 1);
- }
- return val;
- }
- function memberLookup(obj, val) {
- if (obj === undefined || obj === null) {
- return undefined;
- }
- if (typeof obj[val] === 'function') {
- return function () {
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- args[_key2] = arguments[_key2];
- }
- return obj[val].apply(obj, args);
- };
- }
- return obj[val];
- }
- function callWrap(obj, name, context, args) {
- if (!obj) {
- throw new Error('Unable to call `' + name + '`, which is undefined or falsey');
- } else if (typeof obj !== 'function') {
- throw new Error('Unable to call `' + name + '`, which is not a function');
- }
- return obj.apply(context, args);
- }
- function contextOrFrameLookup(context, frame, name) {
- var val = frame.lookup(name);
- return val !== undefined ? val : context.lookup(name);
- }
- function handleError(error, lineno, colno) {
- if (error.lineno) {
- return error;
- } else {
- return new lib.TemplateError(error, lineno, colno);
- }
- }
- function asyncEach(arr, dimen, iter, cb) {
- if (lib.isArray(arr)) {
- var len = arr.length;
- lib.asyncIter(arr, function iterCallback(item, i, next) {
- switch (dimen) {
- case 1:
- iter(item, i, len, next);
- break;
- case 2:
- iter(item[0], item[1], i, len, next);
- break;
- case 3:
- iter(item[0], item[1], item[2], i, len, next);
- break;
- default:
- item.push(i, len, next);
- iter.apply(this, item);
- }
- }, cb);
- } else {
- lib.asyncFor(arr, function iterCallback(key, val, i, len, next) {
- iter(key, val, i, len, next);
- }, cb);
- }
- }
- function asyncAll(arr, dimen, func, cb) {
- var finished = 0;
- var len;
- var outputArr;
- function done(i, output) {
- finished++;
- outputArr[i] = output;
- if (finished === len) {
- cb(null, outputArr.join(''));
- }
- }
- if (lib.isArray(arr)) {
- len = arr.length;
- outputArr = new Array(len);
- if (len === 0) {
- cb(null, '');
- } else {
- for (var i = 0; i < arr.length; i++) {
- var item = arr[i];
- switch (dimen) {
- case 1:
- func(item, i, len, done);
- break;
- case 2:
- func(item[0], item[1], i, len, done);
- break;
- case 3:
- func(item[0], item[1], item[2], i, len, done);
- break;
- default:
- item.push(i, len, done);
- func.apply(this, item);
- }
- }
- }
- } else {
- var keys = lib.keys(arr || {});
- len = keys.length;
- outputArr = new Array(len);
- if (len === 0) {
- cb(null, '');
- } else {
- for (var _i = 0; _i < keys.length; _i++) {
- var k = keys[_i];
- func(k, arr[k], _i, len, done);
- }
- }
- }
- }
- function fromIterator(arr) {
- if (typeof arr !== 'object' || arr === null || lib.isArray(arr)) {
- return arr;
- } else if (supportsIterators && Symbol.iterator in arr) {
- return arrayFrom(arr);
- } else {
- return arr;
- }
- }
- module.exports = {
- Frame: Frame,
- makeMacro: makeMacro,
- makeKeywordArgs: makeKeywordArgs,
- numArgs: numArgs,
- suppressValue: suppressValue,
- ensureDefined: ensureDefined,
- memberLookup: memberLookup,
- contextOrFrameLookup: contextOrFrameLookup,
- callWrap: callWrap,
- handleError: handleError,
- isArray: lib.isArray,
- keys: lib.keys,
- SafeString: SafeString,
- copySafeness: copySafeness,
- markSafe: markSafe,
- asyncEach: asyncEach,
- asyncAll: asyncAll,
- inOperator: lib.inOperator,
- fromIterator: fromIterator
- };
- /***/ }),
- /* 3 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- var Loader = __webpack_require__(4);
- var PrecompiledLoader =
- /*#__PURE__*/
- function (_Loader) {
- _inheritsLoose(PrecompiledLoader, _Loader);
- function PrecompiledLoader(compiledTemplates) {
- var _this;
- _this = _Loader.call(this) || this;
- _this.precompiled = compiledTemplates || {};
- return _this;
- }
- var _proto = PrecompiledLoader.prototype;
- _proto.getSource = function getSource(name) {
- if (this.precompiled[name]) {
- return {
- src: {
- type: 'code',
- obj: this.precompiled[name]
- },
- path: name
- };
- }
- return null;
- };
- return PrecompiledLoader;
- }(Loader);
- module.exports = {
- PrecompiledLoader: PrecompiledLoader
- };
- /***/ }),
- /* 4 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- var path = __webpack_require__(0);
- var _require = __webpack_require__(5),
- EmitterObj = _require.EmitterObj;
- module.exports =
- /*#__PURE__*/
- function (_EmitterObj) {
- _inheritsLoose(Loader, _EmitterObj);
- function Loader() {
- return _EmitterObj.apply(this, arguments) || this;
- }
- var _proto = Loader.prototype;
- _proto.resolve = function resolve(from, to) {
- return path.resolve(path.dirname(from), to);
- };
- _proto.isRelative = function isRelative(filename) {
- return filename.indexOf('./') === 0 || filename.indexOf('../') === 0;
- };
- return Loader;
- }(EmitterObj);
- /***/ }),
- /* 5 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- // A simple class system, more documentation to come
- 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); } }
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- var EventEmitter = __webpack_require__(13);
- var lib = __webpack_require__(1);
- function parentWrap(parent, prop) {
- if (typeof parent !== 'function' || typeof prop !== 'function') {
- return prop;
- }
- return function wrap() {
- // Save the current parent method
- var tmp = this.parent; // Set parent to the previous method, call, and restore
- this.parent = parent;
- var res = prop.apply(this, arguments);
- this.parent = tmp;
- return res;
- };
- }
- function extendClass(cls, name, props) {
- props = props || {};
- lib.keys(props).forEach(function (k) {
- props[k] = parentWrap(cls.prototype[k], props[k]);
- });
- var subclass =
- /*#__PURE__*/
- function (_cls) {
- _inheritsLoose(subclass, _cls);
- function subclass() {
- return _cls.apply(this, arguments) || this;
- }
- _createClass(subclass, [{
- key: "typename",
- get: function get() {
- return name;
- }
- }]);
- return subclass;
- }(cls);
- lib._assign(subclass.prototype, props);
- return subclass;
- }
- var Obj =
- /*#__PURE__*/
- function () {
- function Obj() {
- // Unfortunately necessary for backwards compatibility
- this.init.apply(this, arguments);
- }
- var _proto = Obj.prototype;
- _proto.init = function init() {};
- Obj.extend = function extend(name, props) {
- if (typeof name === 'object') {
- props = name;
- name = 'anonymous';
- }
- return extendClass(this, name, props);
- };
- _createClass(Obj, [{
- key: "typename",
- get: function get() {
- return this.constructor.name;
- }
- }]);
- return Obj;
- }();
- var EmitterObj =
- /*#__PURE__*/
- function (_EventEmitter) {
- _inheritsLoose(EmitterObj, _EventEmitter);
- function EmitterObj() {
- var _this2;
- var _this;
- _this = _EventEmitter.call(this) || this; // Unfortunately necessary for backwards compatibility
- (_this2 = _this).init.apply(_this2, arguments);
- return _this;
- }
- var _proto2 = EmitterObj.prototype;
- _proto2.init = function init() {};
- EmitterObj.extend = function extend(name, props) {
- if (typeof name === 'object') {
- props = name;
- name = 'anonymous';
- }
- return extendClass(this, name, props);
- };
- _createClass(EmitterObj, [{
- key: "typename",
- get: function get() {
- return this.constructor.name;
- }
- }]);
- return EmitterObj;
- }(EventEmitter);
- module.exports = {
- Obj: Obj,
- EmitterObj: EmitterObj
- };
- /***/ }),
- /* 6 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var lib = __webpack_require__(1);
- var _require = __webpack_require__(7),
- Environment = _require.Environment,
- Template = _require.Template;
- var Loader = __webpack_require__(4);
- var loaders = __webpack_require__(3);
- var precompile = __webpack_require__(0);
- var compiler = __webpack_require__(0);
- var parser = __webpack_require__(0);
- var lexer = __webpack_require__(0);
- var runtime = __webpack_require__(2);
- var nodes = __webpack_require__(0);
- var installJinjaCompat = __webpack_require__(17); // A single instance of an environment, since this is so commonly used
- var e;
- function configure(templatesPath, opts) {
- opts = opts || {};
- if (lib.isObject(templatesPath)) {
- opts = templatesPath;
- templatesPath = null;
- }
- var TemplateLoader;
- if (loaders.FileSystemLoader) {
- TemplateLoader = new loaders.FileSystemLoader(templatesPath, {
- watch: opts.watch,
- noCache: opts.noCache
- });
- } else if (loaders.WebLoader) {
- TemplateLoader = new loaders.WebLoader(templatesPath, {
- useCache: opts.web && opts.web.useCache,
- async: opts.web && opts.web.async
- });
- }
- e = new Environment(TemplateLoader, opts);
- if (opts && opts.express) {
- e.express(opts.express);
- }
- return e;
- }
- module.exports = {
- Environment: Environment,
- Template: Template,
- Loader: Loader,
- FileSystemLoader: loaders.FileSystemLoader,
- NodeResolveLoader: loaders.NodeResolveLoader,
- PrecompiledLoader: loaders.PrecompiledLoader,
- WebLoader: loaders.WebLoader,
- compiler: compiler,
- parser: parser,
- lexer: lexer,
- runtime: runtime,
- lib: lib,
- nodes: nodes,
- installJinjaCompat: installJinjaCompat,
- configure: configure,
- reset: function reset() {
- e = undefined;
- },
- compile: function compile(src, env, path, eagerCompile) {
- if (!e) {
- configure();
- }
- return new Template(src, env, path, eagerCompile);
- },
- render: function render(name, ctx, cb) {
- if (!e) {
- configure();
- }
- return e.render(name, ctx, cb);
- },
- renderString: function renderString(src, ctx, cb) {
- if (!e) {
- configure();
- }
- return e.renderString(src, ctx, cb);
- },
- precompile: precompile ? precompile.precompile : undefined,
- precompileString: precompile ? precompile.precompileString : undefined
- };
- /***/ }),
- /* 7 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
- var asap = __webpack_require__(8);
- var _waterfall = __webpack_require__(11);
- var lib = __webpack_require__(1);
- var compiler = __webpack_require__(0);
- var filters = __webpack_require__(12);
- var _require = __webpack_require__(3),
- FileSystemLoader = _require.FileSystemLoader,
- WebLoader = _require.WebLoader,
- PrecompiledLoader = _require.PrecompiledLoader;
- var tests = __webpack_require__(14);
- var globals = __webpack_require__(15);
- var _require2 = __webpack_require__(5),
- Obj = _require2.Obj,
- EmitterObj = _require2.EmitterObj;
- var globalRuntime = __webpack_require__(2);
- var handleError = globalRuntime.handleError,
- Frame = globalRuntime.Frame;
- var expressApp = __webpack_require__(16); // If the user is using the async API, *always* call it
- // asynchronously even if the template was synchronous.
- function callbackAsap(cb, err, res) {
- asap(function () {
- cb(err, res);
- });
- }
- /**
- * A no-op template, for use with {% include ignore missing %}
- */
- var noopTmplSrc = {
- type: 'code',
- obj: {
- root: function root(env, context, frame, runtime, cb) {
- try {
- cb(null, '');
- } catch (e) {
- cb(handleError(e, null, null));
- }
- }
- }
- };
- var Environment =
- /*#__PURE__*/
- function (_EmitterObj) {
- _inheritsLoose(Environment, _EmitterObj);
- function Environment() {
- return _EmitterObj.apply(this, arguments) || this;
- }
- var _proto = Environment.prototype;
- _proto.init = function init(loaders, opts) {
- var _this = this;
- // The dev flag determines the trace that'll be shown on errors.
- // If set to true, returns the full trace from the error point,
- // otherwise will return trace starting from Template.render
- // (the full trace from within nunjucks may confuse developers using
- // the library)
- // defaults to false
- opts = this.opts = opts || {};
- this.opts.dev = !!opts.dev; // The autoescape flag sets global autoescaping. If true,
- // every string variable will be escaped by default.
- // If false, strings can be manually escaped using the `escape` filter.
- // defaults to true
- this.opts.autoescape = opts.autoescape != null ? opts.autoescape : true; // If true, this will make the system throw errors if trying
- // to output a null or undefined value
- this.opts.throwOnUndefined = !!opts.throwOnUndefined;
- this.opts.trimBlocks = !!opts.trimBlocks;
- this.opts.lstripBlocks = !!opts.lstripBlocks;
- this.loaders = [];
- if (!loaders) {
- // The filesystem loader is only available server-side
- if (FileSystemLoader) {
- this.loaders = [new FileSystemLoader('views')];
- } else if (WebLoader) {
- this.loaders = [new WebLoader('/views')];
- }
- } else {
- this.loaders = lib.isArray(loaders) ? loaders : [loaders];
- } // It's easy to use precompiled templates: just include them
- // before you configure nunjucks and this will automatically
- // pick it up and use it
- if (typeof window !== 'undefined' && window.nunjucksPrecompiled) {
- this.loaders.unshift(new PrecompiledLoader(window.nunjucksPrecompiled));
- }
- this._initLoaders();
- this.globals = globals();
- this.filters = {};
- this.tests = {};
- this.asyncFilters = [];
- this.extensions = {};
- this.extensionsList = [];
- lib._entries(filters).forEach(function (_ref) {
- var name = _ref[0],
- filter = _ref[1];
- return _this.addFilter(name, filter);
- });
- lib._entries(tests).forEach(function (_ref2) {
- var name = _ref2[0],
- test = _ref2[1];
- return _this.addTest(name, test);
- });
- };
- _proto._initLoaders = function _initLoaders() {
- var _this2 = this;
- this.loaders.forEach(function (loader) {
- // Caching and cache busting
- loader.cache = {};
- if (typeof loader.on === 'function') {
- loader.on('update', function (name, fullname) {
- loader.cache[name] = null;
- _this2.emit('update', name, fullname, loader);
- });
- loader.on('load', function (name, source) {
- _this2.emit('load', name, source, loader);
- });
- }
- });
- };
- _proto.invalidateCache = function invalidateCache() {
- this.loaders.forEach(function (loader) {
- loader.cache = {};
- });
- };
- _proto.addExtension = function addExtension(name, extension) {
- extension.__name = name;
- this.extensions[name] = extension;
- this.extensionsList.push(extension);
- return this;
- };
- _proto.removeExtension = function removeExtension(name) {
- var extension = this.getExtension(name);
- if (!extension) {
- return;
- }
- this.extensionsList = lib.without(this.extensionsList, extension);
- delete this.extensions[name];
- };
- _proto.getExtension = function getExtension(name) {
- return this.extensions[name];
- };
- _proto.hasExtension = function hasExtension(name) {
- return !!this.extensions[name];
- };
- _proto.addGlobal = function addGlobal(name, value) {
- this.globals[name] = value;
- return this;
- };
- _proto.getGlobal = function getGlobal(name) {
- if (typeof this.globals[name] === 'undefined') {
- throw new Error('global not found: ' + name);
- }
- return this.globals[name];
- };
- _proto.addFilter = function addFilter(name, func, async) {
- var wrapped = func;
- if (async) {
- this.asyncFilters.push(name);
- }
- this.filters[name] = wrapped;
- return this;
- };
- _proto.getFilter = function getFilter(name) {
- if (!this.filters[name]) {
- throw new Error('filter not found: ' + name);
- }
- return this.filters[name];
- };
- _proto.addTest = function addTest(name, func) {
- this.tests[name] = func;
- return this;
- };
- _proto.getTest = function getTest(name) {
- if (!this.tests[name]) {
- throw new Error('test not found: ' + name);
- }
- return this.tests[name];
- };
- _proto.resolveTemplate = function resolveTemplate(loader, parentName, filename) {
- var isRelative = loader.isRelative && parentName ? loader.isRelative(filename) : false;
- return isRelative && loader.resolve ? loader.resolve(parentName, filename) : filename;
- };
- _proto.getTemplate = function getTemplate(name, eagerCompile, parentName, ignoreMissing, cb) {
- var _this3 = this;
- var that = this;
- var tmpl = null;
- if (name && name.raw) {
- // this fixes autoescape for templates referenced in symbols
- name = name.raw;
- }
- if (lib.isFunction(parentName)) {
- cb = parentName;
- parentName = null;
- eagerCompile = eagerCompile || false;
- }
- if (lib.isFunction(eagerCompile)) {
- cb = eagerCompile;
- eagerCompile = false;
- }
- if (name instanceof Template) {
- tmpl = name;
- } else if (typeof name !== 'string') {
- throw new Error('template names must be a string: ' + name);
- } else {
- for (var i = 0; i < this.loaders.length; i++) {
- var loader = this.loaders[i];
- tmpl = loader.cache[this.resolveTemplate(loader, parentName, name)];
- if (tmpl) {
- break;
- }
- }
- }
- if (tmpl) {
- if (eagerCompile) {
- tmpl.compile();
- }
- if (cb) {
- cb(null, tmpl);
- return undefined;
- } else {
- return tmpl;
- }
- }
- var syncResult;
- var createTemplate = function createTemplate(err, info) {
- if (!info && !err && !ignoreMissing) {
- err = new Error('template not found: ' + name);
- }
- if (err) {
- if (cb) {
- cb(err);
- return;
- } else {
- throw err;
- }
- }
- var newTmpl;
- if (!info) {
- newTmpl = new Template(noopTmplSrc, _this3, '', eagerCompile);
- } else {
- newTmpl = new Template(info.src, _this3, info.path, eagerCompile);
- if (!info.noCache) {
- info.loader.cache[name] = newTmpl;
- }
- }
- if (cb) {
- cb(null, newTmpl);
- } else {
- syncResult = newTmpl;
- }
- };
- lib.asyncIter(this.loaders, function (loader, i, next, done) {
- function handle(err, src) {
- if (err) {
- done(err);
- } else if (src) {
- src.loader = loader;
- done(null, src);
- } else {
- next();
- }
- } // Resolve name relative to parentName
- name = that.resolveTemplate(loader, parentName, name);
- if (loader.async) {
- loader.getSource(name, handle);
- } else {
- handle(null, loader.getSource(name));
- }
- }, createTemplate);
- return syncResult;
- };
- _proto.express = function express(app) {
- return expressApp(this, app);
- };
- _proto.render = function render(name, ctx, cb) {
- if (lib.isFunction(ctx)) {
- cb = ctx;
- ctx = null;
- } // We support a synchronous API to make it easier to migrate
- // existing code to async. This works because if you don't do
- // anything async work, the whole thing is actually run
- // synchronously.
- var syncResult = null;
- this.getTemplate(name, function (err, tmpl) {
- if (err && cb) {
- callbackAsap(cb, err);
- } else if (err) {
- throw err;
- } else {
- syncResult = tmpl.render(ctx, cb);
- }
- });
- return syncResult;
- };
- _proto.renderString = function renderString(src, ctx, opts, cb) {
- if (lib.isFunction(opts)) {
- cb = opts;
- opts = {};
- }
- opts = opts || {};
- var tmpl = new Template(src, this, opts.path);
- return tmpl.render(ctx, cb);
- };
- _proto.waterfall = function waterfall(tasks, callback, forceAsync) {
- return _waterfall(tasks, callback, forceAsync);
- };
- return Environment;
- }(EmitterObj);
- var Context =
- /*#__PURE__*/
- function (_Obj) {
- _inheritsLoose(Context, _Obj);
- function Context() {
- return _Obj.apply(this, arguments) || this;
- }
- var _proto2 = Context.prototype;
- _proto2.init = function init(ctx, blocks, env) {
- var _this4 = this;
- // Has to be tied to an environment so we can tap into its globals.
- this.env = env || new Environment(); // Make a duplicate of ctx
- this.ctx = lib.extend({}, ctx);
- this.blocks = {};
- this.exported = [];
- lib.keys(blocks).forEach(function (name) {
- _this4.addBlock(name, blocks[name]);
- });
- };
- _proto2.lookup = function lookup(name) {
- // This is one of the most called functions, so optimize for
- // the typical case where the name isn't in the globals
- if (name in this.env.globals && !(name in this.ctx)) {
- return this.env.globals[name];
- } else {
- return this.ctx[name];
- }
- };
- _proto2.setVariable = function setVariable(name, val) {
- this.ctx[name] = val;
- };
- _proto2.getVariables = function getVariables() {
- return this.ctx;
- };
- _proto2.addBlock = function addBlock(name, block) {
- this.blocks[name] = this.blocks[name] || [];
- this.blocks[name].push(block);
- return this;
- };
- _proto2.getBlock = function getBlock(name) {
- if (!this.blocks[name]) {
- throw new Error('unknown block "' + name + '"');
- }
- return this.blocks[name][0];
- };
- _proto2.getSuper = function getSuper(env, name, block, frame, runtime, cb) {
- var idx = lib.indexOf(this.blocks[name] || [], block);
- var blk = this.blocks[name][idx + 1];
- var context = this;
- if (idx === -1 || !blk) {
- throw new Error('no super block available for "' + name + '"');
- }
- blk(env, context, frame, runtime, cb);
- };
- _proto2.addExport = function addExport(name) {
- this.exported.push(name);
- };
- _proto2.getExported = function getExported() {
- var _this5 = this;
- var exported = {};
- this.exported.forEach(function (name) {
- exported[name] = _this5.ctx[name];
- });
- return exported;
- };
- return Context;
- }(Obj);
- var Template =
- /*#__PURE__*/
- function (_Obj2) {
- _inheritsLoose(Template, _Obj2);
- function Template() {
- return _Obj2.apply(this, arguments) || this;
- }
- var _proto3 = Template.prototype;
- _proto3.init = function init(src, env, path, eagerCompile) {
- this.env = env || new Environment();
- if (lib.isObject(src)) {
- switch (src.type) {
- case 'code':
- this.tmplProps = src.obj;
- break;
- case 'string':
- this.tmplStr = src.obj;
- break;
- default:
- throw new Error("Unexpected template object type " + src.type + "; expected 'code', or 'string'");
- }
- } else if (lib.isString(src)) {
- this.tmplStr = src;
- } else {
- throw new Error('src must be a string or an object describing the source');
- }
- this.path = path;
- if (eagerCompile) {
- try {
- this._compile();
- } catch (err) {
- throw lib._prettifyError(this.path, this.env.opts.dev, err);
- }
- } else {
- this.compiled = false;
- }
- };
- _proto3.render = function render(ctx, parentFrame, cb) {
- var _this6 = this;
- if (typeof ctx === 'function') {
- cb = ctx;
- ctx = {};
- } else if (typeof parentFrame === 'function') {
- cb = parentFrame;
- parentFrame = null;
- } // If there is a parent frame, we are being called from internal
- // code of another template, and the internal system
- // depends on the sync/async nature of the parent template
- // to be inherited, so force an async callback
- var forceAsync = !parentFrame; // Catch compile errors for async rendering
- try {
- this.compile();
- } catch (e) {
- var err = lib._prettifyError(this.path, this.env.opts.dev, e);
- if (cb) {
- return callbackAsap(cb, err);
- } else {
- throw err;
- }
- }
- var context = new Context(ctx || {}, this.blocks, this.env);
- var frame = parentFrame ? parentFrame.push(true) : new Frame();
- frame.topLevel = true;
- var syncResult = null;
- var didError = false;
- this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err, res) {
- if (didError) {
- // prevent multiple calls to cb
- if (cb) {
- return;
- } else {
- throw err;
- }
- }
- if (err) {
- err = lib._prettifyError(_this6.path, _this6.env.opts.dev, err);
- didError = true;
- }
- if (cb) {
- if (forceAsync) {
- callbackAsap(cb, err, res);
- } else {
- cb(err, res);
- }
- } else {
- if (err) {
- throw err;
- }
- syncResult = res;
- }
- });
- return syncResult;
- };
- _proto3.getExported = function getExported(ctx, parentFrame, cb) {
- // eslint-disable-line consistent-return
- if (typeof ctx === 'function') {
- cb = ctx;
- ctx = {};
- }
- if (typeof parentFrame === 'function') {
- cb = parentFrame;
- parentFrame = null;
- } // Catch compile errors for async rendering
- try {
- this.compile();
- } catch (e) {
- if (cb) {
- return cb(e);
- } else {
- throw e;
- }
- }
- var frame = parentFrame ? parentFrame.push() : new Frame();
- frame.topLevel = true; // Run the rootRenderFunc to populate the context with exported vars
- var context = new Context(ctx || {}, this.blocks, this.env);
- this.rootRenderFunc(this.env, context, frame, globalRuntime, function (err) {
- if (err) {
- cb(err, null);
- } else {
- cb(null, context.getExported());
- }
- });
- };
- _proto3.compile = function compile() {
- if (!this.compiled) {
- this._compile();
- }
- };
- _proto3._compile = function _compile() {
- var props;
- if (this.tmplProps) {
- props = this.tmplProps;
- } else {
- var source = compiler.compile(this.tmplStr, this.env.asyncFilters, this.env.extensionsList, this.path, this.env.opts);
- var func = new Function(source); // eslint-disable-line no-new-func
- props = func();
- }
- this.blocks = this._getBlocks(props);
- this.rootRenderFunc = props.root;
- this.compiled = true;
- };
- _proto3._getBlocks = function _getBlocks(props) {
- var blocks = {};
- lib.keys(props).forEach(function (k) {
- if (k.slice(0, 2) === 'b_') {
- blocks[k.slice(2)] = props[k];
- }
- });
- return blocks;
- };
- return Template;
- }(Obj);
- module.exports = {
- Environment: Environment,
- Template: Template
- };
- /***/ }),
- /* 8 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- // rawAsap provides everything we need except exception management.
- var rawAsap = __webpack_require__(9);
- // RawTasks are recycled to reduce GC churn.
- var freeTasks = [];
- // We queue errors to ensure they are thrown in right order (FIFO).
- // Array-as-queue is good enough here, since we are just dealing with exceptions.
- var pendingErrors = [];
- var requestErrorThrow = rawAsap.makeRequestCallFromTimer(throwFirstError);
- function throwFirstError() {
- if (pendingErrors.length) {
- throw pendingErrors.shift();
- }
- }
- /**
- * Calls a task as soon as possible after returning, in its own event, with priority
- * over other events like animation, reflow, and repaint. An error thrown from an
- * event will not interrupt, nor even substantially slow down the processing of
- * other events, but will be rather postponed to a lower priority event.
- * @param {{call}} task A callable object, typically a function that takes no
- * arguments.
- */
- module.exports = asap;
- function asap(task) {
- var rawTask;
- if (freeTasks.length) {
- rawTask = freeTasks.pop();
- } else {
- rawTask = new RawTask();
- }
- rawTask.task = task;
- rawAsap(rawTask);
- }
- // We wrap tasks with recyclable task objects. A task object implements
- // `call`, just like a function.
- function RawTask() {
- this.task = null;
- }
- // The sole purpose of wrapping the task is to catch the exception and recycle
- // the task object after its single use.
- RawTask.prototype.call = function () {
- try {
- this.task.call();
- } catch (error) {
- if (asap.onerror) {
- // This hook exists purely for testing purposes.
- // Its name will be periodically randomized to break any code that
- // depends on its existence.
- asap.onerror(error);
- } else {
- // In a web browser, exceptions are not fatal. However, to avoid
- // slowing down the queue of pending tasks, we rethrow the error in a
- // lower priority turn.
- pendingErrors.push(error);
- requestErrorThrow();
- }
- } finally {
- this.task = null;
- freeTasks[freeTasks.length] = this;
- }
- };
- /***/ }),
- /* 9 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- /* WEBPACK VAR INJECTION */(function(global) {
- // Use the fastest means possible to execute a task in its own turn, with
- // priority over other events including IO, animation, reflow, and redraw
- // events in browsers.
- //
- // An exception thrown by a task will permanently interrupt the processing of
- // subsequent tasks. The higher level `asap` function ensures that if an
- // exception is thrown by a task, that the task queue will continue flushing as
- // soon as possible, but if you use `rawAsap` directly, you are responsible to
- // either ensure that no exceptions are thrown from your task, or to manually
- // call `rawAsap.requestFlush` if an exception is thrown.
- module.exports = rawAsap;
- function rawAsap(task) {
- if (!queue.length) {
- requestFlush();
- flushing = true;
- }
- // Equivalent to push, but avoids a function call.
- queue[queue.length] = task;
- }
- var queue = [];
- // Once a flush has been requested, no further calls to `requestFlush` are
- // necessary until the next `flush` completes.
- var flushing = false;
- // `requestFlush` is an implementation-specific method that attempts to kick
- // off a `flush` event as quickly as possible. `flush` will attempt to exhaust
- // the event queue before yielding to the browser's own event loop.
- var requestFlush;
- // The position of the next task to execute in the task queue. This is
- // preserved between calls to `flush` so that it can be resumed if
- // a task throws an exception.
- var index = 0;
- // If a task schedules additional tasks recursively, the task queue can grow
- // unbounded. To prevent memory exhaustion, the task queue will periodically
- // truncate already-completed tasks.
- var capacity = 1024;
- // The flush function processes all tasks that have been scheduled with
- // `rawAsap` unless and until one of those tasks throws an exception.
- // If a task throws an exception, `flush` ensures that its state will remain
- // consistent and will resume where it left off when called again.
- // However, `flush` does not make any arrangements to be called again if an
- // exception is thrown.
- function flush() {
- while (index < queue.length) {
- var currentIndex = index;
- // Advance the index before calling the task. This ensures that we will
- // begin flushing on the next task the task throws an error.
- index = index + 1;
- queue[currentIndex].call();
- // Prevent leaking memory for long chains of recursive calls to `asap`.
- // If we call `asap` within tasks scheduled by `asap`, the queue will
- // grow, but to avoid an O(n) walk for every task we execute, we don't
- // shift tasks off the queue after they have been executed.
- // Instead, we periodically shift 1024 tasks off the queue.
- if (index > capacity) {
- // Manually shift all values starting at the index back to the
- // beginning of the queue.
- for (var scan = 0, newLength = queue.length - index; scan < newLength; scan++) {
- queue[scan] = queue[scan + index];
- }
- queue.length -= index;
- index = 0;
- }
- }
- queue.length = 0;
- index = 0;
- flushing = false;
- }
- // `requestFlush` is implemented using a strategy based on data collected from
- // every available SauceLabs Selenium web driver worker at time of writing.
- // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
- // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
- // have WebKitMutationObserver but not un-prefixed MutationObserver.
- // Must use `global` or `self` instead of `window` to work in both frames and web
- // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
- /* globals self */
- var scope = typeof global !== "undefined" ? global : self;
- var BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
- // MutationObservers are desirable because they have high priority and work
- // reliably everywhere they are implemented.
- // They are implemented in all modern browsers.
- //
- // - Android 4-4.3
- // - Chrome 26-34
- // - Firefox 14-29
- // - Internet Explorer 11
- // - iPad Safari 6-7.1
- // - iPhone Safari 7-7.1
- // - Safari 6-7
- if (typeof BrowserMutationObserver === "function") {
- requestFlush = makeRequestCallFromMutationObserver(flush);
- // MessageChannels are desirable because they give direct access to the HTML
- // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
- // 11-12, and in web workers in many engines.
- // Although message channels yield to any queued rendering and IO tasks, they
- // would be better than imposing the 4ms delay of timers.
- // However, they do not work reliably in Internet Explorer or Safari.
- // Internet Explorer 10 is the only browser that has setImmediate but does
- // not have MutationObservers.
- // Although setImmediate yields to the browser's renderer, it would be
- // preferrable to falling back to setTimeout since it does not have
- // the minimum 4ms penalty.
- // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
- // Desktop to a lesser extent) that renders both setImmediate and
- // MessageChannel useless for the purposes of ASAP.
- // https://github.com/kriskowal/q/issues/396
- // Timers are implemented universally.
- // We fall back to timers in workers in most engines, and in foreground
- // contexts in the following browsers.
- // However, note that even this simple case requires nuances to operate in a
- // broad spectrum of browsers.
- //
- // - Firefox 3-13
- // - Internet Explorer 6-9
- // - iPad Safari 4.3
- // - Lynx 2.8.7
- } else {
- requestFlush = makeRequestCallFromTimer(flush);
- }
- // `requestFlush` requests that the high priority event queue be flushed as
- // soon as possible.
- // This is useful to prevent an error thrown in a task from stalling the event
- // queue if the exception handled by Node.js’s
- // `process.on("uncaughtException")` or by a domain.
- rawAsap.requestFlush = requestFlush;
- // To request a high priority event, we induce a mutation observer by toggling
- // the text of a text node between "1" and "-1".
- function makeRequestCallFromMutationObserver(callback) {
- var toggle = 1;
- var observer = new BrowserMutationObserver(callback);
- var node = document.createTextNode("");
- observer.observe(node, {characterData: true});
- return function requestCall() {
- toggle = -toggle;
- node.data = toggle;
- };
- }
- // The message channel technique was discovered by Malte Ubl and was the
- // original foundation for this library.
- // http://www.nonblocking.io/2011/06/windownexttick.html
- // Safari 6.0.5 (at least) intermittently fails to create message ports on a
- // page's first load. Thankfully, this version of Safari supports
- // MutationObservers, so we don't need to fall back in that case.
- // function makeRequestCallFromMessageChannel(callback) {
- // var channel = new MessageChannel();
- // channel.port1.onmessage = callback;
- // return function requestCall() {
- // channel.port2.postMessage(0);
- // };
- // }
- // For reasons explained above, we are also unable to use `setImmediate`
- // under any circumstances.
- // Even if we were, there is another bug in Internet Explorer 10.
- // It is not sufficient to assign `setImmediate` to `requestFlush` because
- // `setImmediate` must be called *by name* and therefore must be wrapped in a
- // closure.
- // Never forget.
- // function makeRequestCallFromSetImmediate(callback) {
- // return function requestCall() {
- // setImmediate(callback);
- // };
- // }
- // Safari 6.0 has a problem where timers will get lost while the user is
- // scrolling. This problem does not impact ASAP because Safari 6.0 supports
- // mutation observers, so that implementation is used instead.
- // However, if we ever elect to use timers in Safari, the prevalent work-around
- // is to add a scroll event listener that calls for a flush.
- // `setTimeout` does not call the passed callback if the delay is less than
- // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
- // even then.
- function makeRequestCallFromTimer(callback) {
- return function requestCall() {
- // We dispatch a timeout with a specified delay of 0 for engines that
- // can reliably accommodate that request. This will usually be snapped
- // to a 4 milisecond delay, but once we're flushing, there's no delay
- // between events.
- var timeoutHandle = setTimeout(handleTimer, 0);
- // However, since this timer gets frequently dropped in Firefox
- // workers, we enlist an interval handle that will try to fire
- // an event 20 times per second until it succeeds.
- var intervalHandle = setInterval(handleTimer, 50);
- function handleTimer() {
- // Whichever timer succeeds will cancel both timers and
- // execute the callback.
- clearTimeout(timeoutHandle);
- clearInterval(intervalHandle);
- callback();
- }
- };
- }
- // This is for `asap.js` only.
- // Its name will be periodically randomized to break any code that depends on
- // its existence.
- rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer;
- // ASAP was originally a nextTick shim included in Q. This was factored out
- // into this ASAP package. It was later adapted to RSVP which made further
- // amendments. These decisions, particularly to marginalize MessageChannel and
- // to capture the MutationObserver implementation in a closure, were integrated
- // back into ASAP proper.
- // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
- /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(10)))
- /***/ }),
- /* 10 */
- /***/ (function(module, exports) {
- var g;
- // This works in non-strict mode
- g = (function() {
- return this;
- })();
- try {
- // This works if eval is allowed (see CSP)
- g = g || Function("return this")() || (1,eval)("this");
- } catch(e) {
- // This works if the window reference is available
- if(typeof window === "object")
- g = window;
- }
- // g can still be undefined, but nothing to do about it...
- // We return undefined, instead of nothing here, so it's
- // easier to handle this case. if(!global) { ...}
- module.exports = g;
- /***/ }),
- /* 11 */
- /***/ (function(module, exports, __webpack_require__) {
- var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// MIT license (by Elan Shanker).
- (function(globals) {
- 'use strict';
- var executeSync = function(){
- var args = Array.prototype.slice.call(arguments);
- if (typeof args[0] === 'function'){
- args[0].apply(null, args.splice(1));
- }
- };
- var executeAsync = function(fn){
- if (typeof setImmediate === 'function') {
- setImmediate(fn);
- } else if (typeof process !== 'undefined' && process.nextTick) {
- process.nextTick(fn);
- } else {
- setTimeout(fn, 0);
- }
- };
- var makeIterator = function (tasks) {
- var makeCallback = function (index) {
- var fn = function () {
- if (tasks.length) {
- tasks[index].apply(null, arguments);
- }
- return fn.next();
- };
- fn.next = function () {
- return (index < tasks.length - 1) ? makeCallback(index + 1): null;
- };
- return fn;
- };
- return makeCallback(0);
- };
-
- var _isArray = Array.isArray || function(maybeArray){
- return Object.prototype.toString.call(maybeArray) === '[object Array]';
- };
- var waterfall = function (tasks, callback, forceAsync) {
- var nextTick = forceAsync ? executeAsync : executeSync;
- callback = callback || function () {};
- if (!_isArray(tasks)) {
- var err = new Error('First argument to waterfall must be an array of functions');
- return callback(err);
- }
- if (!tasks.length) {
- return callback();
- }
- var wrapIterator = function (iterator) {
- return function (err) {
- if (err) {
- callback.apply(null, arguments);
- callback = function () {};
- } else {
- var args = Array.prototype.slice.call(arguments, 1);
- var next = iterator.next();
- if (next) {
- args.push(wrapIterator(next));
- } else {
- args.push(callback);
- }
- nextTick(function () {
- iterator.apply(null, args);
- });
- }
- };
- };
- wrapIterator(makeIterator(tasks))();
- };
- if (true) {
- !(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () {
- return waterfall;
- }).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
- __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); // RequireJS
- } else if (typeof module !== 'undefined' && module.exports) {
- module.exports = waterfall; // CommonJS
- } else {
- globals.waterfall = waterfall; // <script>
- }
- })(this);
- /***/ }),
- /* 12 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var lib = __webpack_require__(1);
- var r = __webpack_require__(2);
- var exports = module.exports = {};
- function normalize(value, defaultValue) {
- if (value === null || value === undefined || value === false) {
- return defaultValue;
- }
- return value;
- }
- exports.abs = Math.abs;
- function isNaN(num) {
- return num !== num; // eslint-disable-line no-self-compare
- }
- function batch(arr, linecount, fillWith) {
- var i;
- var res = [];
- var tmp = [];
- for (i = 0; i < arr.length; i++) {
- if (i % linecount === 0 && tmp.length) {
- res.push(tmp);
- tmp = [];
- }
- tmp.push(arr[i]);
- }
- if (tmp.length) {
- if (fillWith) {
- for (i = tmp.length; i < linecount; i++) {
- tmp.push(fillWith);
- }
- }
- res.push(tmp);
- }
- return res;
- }
- exports.batch = batch;
- function capitalize(str) {
- str = normalize(str, '');
- var ret = str.toLowerCase();
- return r.copySafeness(str, ret.charAt(0).toUpperCase() + ret.slice(1));
- }
- exports.capitalize = capitalize;
- function center(str, width) {
- str = normalize(str, '');
- width = width || 80;
- if (str.length >= width) {
- return str;
- }
- var spaces = width - str.length;
- var pre = lib.repeat(' ', spaces / 2 - spaces % 2);
- var post = lib.repeat(' ', spaces / 2);
- return r.copySafeness(str, pre + str + post);
- }
- exports.center = center;
- function default_(val, def, bool) {
- if (bool) {
- return val || def;
- } else {
- return val !== undefined ? val : def;
- }
- } // TODO: it is confusing to export something called 'default'
- exports['default'] = default_; // eslint-disable-line dot-notation
- function dictsort(val, caseSensitive, by) {
- if (!lib.isObject(val)) {
- throw new lib.TemplateError('dictsort filter: val must be an object');
- }
- var array = []; // deliberately include properties from the object's prototype
- for (var k in val) {
- // eslint-disable-line guard-for-in, no-restricted-syntax
- array.push([k, val[k]]);
- }
- var si;
- if (by === undefined || by === 'key') {
- si = 0;
- } else if (by === 'value') {
- si = 1;
- } else {
- throw new lib.TemplateError('dictsort filter: You can only sort by either key or value');
- }
- array.sort(function (t1, t2) {
- var a = t1[si];
- var b = t2[si];
- if (!caseSensitive) {
- if (lib.isString(a)) {
- a = a.toUpperCase();
- }
- if (lib.isString(b)) {
- b = b.toUpperCase();
- }
- }
- return a > b ? 1 : a === b ? 0 : -1; // eslint-disable-line no-nested-ternary
- });
- return array;
- }
- exports.dictsort = dictsort;
- function dump(obj, spaces) {
- return JSON.stringify(obj, null, spaces);
- }
- exports.dump = dump;
- function escape(str) {
- if (str instanceof r.SafeString) {
- return str;
- }
- str = str === null || str === undefined ? '' : str;
- return r.markSafe(lib.escape(str.toString()));
- }
- exports.escape = escape;
- function safe(str) {
- if (str instanceof r.SafeString) {
- return str;
- }
- str = str === null || str === undefined ? '' : str;
- return r.markSafe(str.toString());
- }
- exports.safe = safe;
- function first(arr) {
- return arr[0];
- }
- exports.first = first;
- function forceescape(str) {
- str = str === null || str === undefined ? '' : str;
- return r.markSafe(lib.escape(str.toString()));
- }
- exports.forceescape = forceescape;
- function groupby(arr, attr) {
- return lib.groupBy(arr, attr);
- }
- exports.groupby = groupby;
- function indent(str, width, indentfirst) {
- str = normalize(str, '');
- if (str === '') {
- return '';
- }
- width = width || 4; // let res = '';
- var lines = str.split('\n');
- var sp = lib.repeat(' ', width);
- var res = lines.map(function (l, i) {
- return i === 0 && !indentfirst ? l + "\n" : "" + sp + l + "\n";
- }).join('');
- return r.copySafeness(str, res);
- }
- exports.indent = indent;
- function join(arr, del, attr) {
- del = del || '';
- if (attr) {
- arr = lib.map(arr, function (v) {
- return v[attr];
- });
- }
- return arr.join(del);
- }
- exports.join = join;
- function last(arr) {
- return arr[arr.length - 1];
- }
- exports.last = last;
- function lengthFilter(val) {
- var value = normalize(val, '');
- if (value !== undefined) {
- if (typeof Map === 'function' && value instanceof Map || typeof Set === 'function' && value instanceof Set) {
- // ECMAScript 2015 Maps and Sets
- return value.size;
- }
- if (lib.isObject(value) && !(value instanceof r.SafeString)) {
- // Objects (besides SafeStrings), non-primative Arrays
- return lib.keys(value).length;
- }
- return value.length;
- }
- return 0;
- }
- exports.length = lengthFilter;
- function list(val) {
- if (lib.isString(val)) {
- return val.split('');
- } else if (lib.isObject(val)) {
- return lib._entries(val || {}).map(function (_ref) {
- var key = _ref[0],
- value = _ref[1];
- return {
- key: key,
- value: value
- };
- });
- } else if (lib.isArray(val)) {
- return val;
- } else {
- throw new lib.TemplateError('list filter: type not iterable');
- }
- }
- exports.list = list;
- function lower(str) {
- str = normalize(str, '');
- return str.toLowerCase();
- }
- exports.lower = lower;
- function nl2br(str) {
- if (str === null || str === undefined) {
- return '';
- }
- return r.copySafeness(str, str.replace(/\r\n|\n/g, '<br />\n'));
- }
- exports.nl2br = nl2br;
- function random(arr) {
- return arr[Math.floor(Math.random() * arr.length)];
- }
- exports.random = random;
- function rejectattr(arr, attr) {
- return arr.filter(function (item) {
- return !item[attr];
- });
- }
- exports.rejectattr = rejectattr;
- function selectattr(arr, attr) {
- return arr.filter(function (item) {
- return !!item[attr];
- });
- }
- exports.selectattr = selectattr;
- function replace(str, old, new_, maxCount) {
- var originalStr = str;
- if (old instanceof RegExp) {
- return str.replace(old, new_);
- }
- if (typeof maxCount === 'undefined') {
- maxCount = -1;
- }
- var res = ''; // Output
- // Cast Numbers in the search term to string
- if (typeof old === 'number') {
- old = '' + old;
- } else if (typeof old !== 'string') {
- // If it is something other than number or string,
- // return the original string
- return str;
- } // Cast numbers in the replacement to string
- if (typeof str === 'number') {
- str = '' + str;
- } // If by now, we don't have a string, throw it back
- if (typeof str !== 'string' && !(str instanceof r.SafeString)) {
- return str;
- } // ShortCircuits
- if (old === '') {
- // Mimic the python behaviour: empty string is replaced
- // by replacement e.g. "abc"|replace("", ".") -> .a.b.c.
- res = new_ + str.split('').join(new_) + new_;
- return r.copySafeness(str, res);
- }
- var nextIndex = str.indexOf(old); // if # of replacements to perform is 0, or the string to does
- // not contain the old value, return the string
- if (maxCount === 0 || nextIndex === -1) {
- return str;
- }
- var pos = 0;
- var count = 0; // # of replacements made
- while (nextIndex > -1 && (maxCount === -1 || count < maxCount)) {
- // Grab the next chunk of src string and add it with the
- // replacement, to the result
- res += str.substring(pos, nextIndex) + new_; // Increment our pointer in the src string
- pos = nextIndex + old.length;
- count++; // See if there are any more replacements to be made
- nextIndex = str.indexOf(old, pos);
- } // We've either reached the end, or done the max # of
- // replacements, tack on any remaining string
- if (pos < str.length) {
- res += str.substring(pos);
- }
- return r.copySafeness(originalStr, res);
- }
- exports.replace = replace;
- function reverse(val) {
- var arr;
- if (lib.isString(val)) {
- arr = list(val);
- } else {
- // Copy it
- arr = lib.map(val, function (v) {
- return v;
- });
- }
- arr.reverse();
- if (lib.isString(val)) {
- return r.copySafeness(val, arr.join(''));
- }
- return arr;
- }
- exports.reverse = reverse;
- function round(val, precision, method) {
- precision = precision || 0;
- var factor = Math.pow(10, precision);
- var rounder;
- if (method === 'ceil') {
- rounder = Math.ceil;
- } else if (method === 'floor') {
- rounder = Math.floor;
- } else {
- rounder = Math.round;
- }
- return rounder(val * factor) / factor;
- }
- exports.round = round;
- function slice(arr, slices, fillWith) {
- var sliceLength = Math.floor(arr.length / slices);
- var extra = arr.length % slices;
- var res = [];
- var offset = 0;
- for (var i = 0; i < slices; i++) {
- var start = offset + i * sliceLength;
- if (i < extra) {
- offset++;
- }
- var end = offset + (i + 1) * sliceLength;
- var currSlice = arr.slice(start, end);
- if (fillWith && i >= extra) {
- currSlice.push(fillWith);
- }
- res.push(currSlice);
- }
- return res;
- }
- exports.slice = slice;
- function sum(arr, attr, start) {
- if (start === void 0) {
- start = 0;
- }
- if (attr) {
- arr = lib.map(arr, function (v) {
- return v[attr];
- });
- }
- return start + arr.reduce(function (a, b) {
- return a + b;
- }, 0);
- }
- exports.sum = sum;
- exports.sort = r.makeMacro(['value', 'reverse', 'case_sensitive', 'attribute'], [], function (arr, reversed, caseSens, attr) {
- // Copy it
- var array = lib.map(arr, function (v) {
- return v;
- });
- array.sort(function (a, b) {
- var x = attr ? a[attr] : a;
- var y = attr ? b[attr] : b;
- if (!caseSens && lib.isString(x) && lib.isString(y)) {
- x = x.toLowerCase();
- y = y.toLowerCase();
- }
- if (x < y) {
- return reversed ? 1 : -1;
- } else if (x > y) {
- return reversed ? -1 : 1;
- } else {
- return 0;
- }
- });
- return array;
- });
- function string(obj) {
- return r.copySafeness(obj, obj);
- }
- exports.string = string;
- function striptags(input, preserveLinebreaks) {
- input = normalize(input, '');
- var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>|<!--[\s\S]*?-->/gi;
- var trimmedInput = trim(input.replace(tags, ''));
- var res = '';
- if (preserveLinebreaks) {
- res = trimmedInput.replace(/^ +| +$/gm, '') // remove leading and trailing spaces
- .replace(/ +/g, ' ') // squash adjacent spaces
- .replace(/(\r\n)/g, '\n') // normalize linebreaks (CRLF -> LF)
- .replace(/\n\n\n+/g, '\n\n'); // squash abnormal adjacent linebreaks
- } else {
- res = trimmedInput.replace(/\s+/gi, ' ');
- }
- return r.copySafeness(input, res);
- }
- exports.striptags = striptags;
- function title(str) {
- str = normalize(str, '');
- var words = str.split(' ').map(function (word) {
- return capitalize(word);
- });
- return r.copySafeness(str, words.join(' '));
- }
- exports.title = title;
- function trim(str) {
- return r.copySafeness(str, str.replace(/^\s*|\s*$/g, ''));
- }
- exports.trim = trim;
- function truncate(input, length, killwords, end) {
- var orig = input;
- input = normalize(input, '');
- length = length || 255;
- if (input.length <= length) {
- return input;
- }
- if (killwords) {
- input = input.substring(0, length);
- } else {
- var idx = input.lastIndexOf(' ', length);
- if (idx === -1) {
- idx = length;
- }
- input = input.substring(0, idx);
- }
- input += end !== undefined && end !== null ? end : '...';
- return r.copySafeness(orig, input);
- }
- exports.truncate = truncate;
- function upper(str) {
- str = normalize(str, '');
- return str.toUpperCase();
- }
- exports.upper = upper;
- function urlencode(obj) {
- var enc = encodeURIComponent;
- if (lib.isString(obj)) {
- return enc(obj);
- } else {
- var keyvals = lib.isArray(obj) ? obj : lib._entries(obj);
- return keyvals.map(function (_ref2) {
- var k = _ref2[0],
- v = _ref2[1];
- return enc(k) + "=" + enc(v);
- }).join('&');
- }
- }
- exports.urlencode = urlencode; // For the jinja regexp, see
- // https://github.com/mitsuhiko/jinja2/blob/f15b814dcba6aa12bc74d1f7d0c881d55f7126be/jinja2/utils.py#L20-L23
- var puncRe = /^(?:\(|<|<)?(.*?)(?:\.|,|\)|\n|>)?$/; // from http://blog.gerv.net/2011/05/html5_email_address_regexp/
- var emailRe = /^[\w.!#$%&'*+\-\/=?\^`{|}~]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
- var httpHttpsRe = /^https?:\/\/.*$/;
- var wwwRe = /^www\./;
- var tldRe = /\.(?:org|net|com)(?:\:|\/|$)/;
- function urlize(str, length, nofollow) {
- if (isNaN(length)) {
- length = Infinity;
- }
- var noFollowAttr = nofollow === true ? ' rel="nofollow"' : '';
- var words = str.split(/(\s+)/).filter(function (word) {
- // If the word has no length, bail. This can happen for str with
- // trailing whitespace.
- return word && word.length;
- }).map(function (word) {
- var matches = word.match(puncRe);
- var possibleUrl = matches ? matches[1] : word;
- var shortUrl = possibleUrl.substr(0, length); // url that starts with http or https
- if (httpHttpsRe.test(possibleUrl)) {
- return "<a href=\"" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
- } // url that starts with www.
- if (wwwRe.test(possibleUrl)) {
- return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
- } // an email address of the form username@domain.tld
- if (emailRe.test(possibleUrl)) {
- return "<a href=\"mailto:" + possibleUrl + "\">" + possibleUrl + "</a>";
- } // url that ends in .com, .org or .net that is not an email address
- if (tldRe.test(possibleUrl)) {
- return "<a href=\"http://" + possibleUrl + "\"" + noFollowAttr + ">" + shortUrl + "</a>";
- }
- return word;
- });
- return words.join('');
- }
- exports.urlize = urlize;
- function wordcount(str) {
- str = normalize(str, '');
- var words = str ? str.match(/\w+/g) : null;
- return words ? words.length : null;
- }
- exports.wordcount = wordcount;
- function float(val, def) {
- var res = parseFloat(val);
- return isNaN(res) ? def : res;
- }
- exports.float = float;
- function int(val, def) {
- var res = parseInt(val, 10);
- return isNaN(res) ? def : res;
- }
- exports.int = int; // Aliases
- exports.d = exports.default;
- exports.e = exports.escape;
- /***/ }),
- /* 13 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- // Copyright Joyent, Inc. and other Node contributors.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a
- // copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to permit
- // persons to whom the Software is furnished to do so, subject to the
- // following conditions:
- //
- // The above copyright notice and this permission notice shall be included
- // in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
- var R = typeof Reflect === 'object' ? Reflect : null
- var ReflectApply = R && typeof R.apply === 'function'
- ? R.apply
- : function ReflectApply(target, receiver, args) {
- return Function.prototype.apply.call(target, receiver, args);
- }
- var ReflectOwnKeys
- if (R && typeof R.ownKeys === 'function') {
- ReflectOwnKeys = R.ownKeys
- } else if (Object.getOwnPropertySymbols) {
- ReflectOwnKeys = function ReflectOwnKeys(target) {
- return Object.getOwnPropertyNames(target)
- .concat(Object.getOwnPropertySymbols(target));
- };
- } else {
- ReflectOwnKeys = function ReflectOwnKeys(target) {
- return Object.getOwnPropertyNames(target);
- };
- }
- function ProcessEmitWarning(warning) {
- if (console && console.warn) console.warn(warning);
- }
- var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
- return value !== value;
- }
- function EventEmitter() {
- EventEmitter.init.call(this);
- }
- module.exports = EventEmitter;
- // Backwards-compat with node 0.10.x
- EventEmitter.EventEmitter = EventEmitter;
- EventEmitter.prototype._events = undefined;
- EventEmitter.prototype._eventsCount = 0;
- EventEmitter.prototype._maxListeners = undefined;
- // By default EventEmitters will print a warning if more than 10 listeners are
- // added to it. This is a useful default which helps finding memory leaks.
- var defaultMaxListeners = 10;
- Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
- enumerable: true,
- get: function() {
- return defaultMaxListeners;
- },
- set: function(arg) {
- if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
- throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
- }
- defaultMaxListeners = arg;
- }
- });
- EventEmitter.init = function() {
- if (this._events === undefined ||
- this._events === Object.getPrototypeOf(this)._events) {
- this._events = Object.create(null);
- this._eventsCount = 0;
- }
- this._maxListeners = this._maxListeners || undefined;
- };
- // Obviously not all Emitters should be limited to 10. This function allows
- // that to be increased. Set to zero for unlimited.
- EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
- if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
- throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
- }
- this._maxListeners = n;
- return this;
- };
- function $getMaxListeners(that) {
- if (that._maxListeners === undefined)
- return EventEmitter.defaultMaxListeners;
- return that._maxListeners;
- }
- EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
- return $getMaxListeners(this);
- };
- EventEmitter.prototype.emit = function emit(type) {
- var args = [];
- for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
- var doError = (type === 'error');
- var events = this._events;
- if (events !== undefined)
- doError = (doError && events.error === undefined);
- else if (!doError)
- return false;
- // If there is no 'error' event listener then throw.
- if (doError) {
- var er;
- if (args.length > 0)
- er = args[0];
- if (er instanceof Error) {
- // Note: The comments on the `throw` lines are intentional, they show
- // up in Node's output if this results in an unhandled exception.
- throw er; // Unhandled 'error' event
- }
- // At least give some kind of context to the user
- var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
- err.context = er;
- throw err; // Unhandled 'error' event
- }
- var handler = events[type];
- if (handler === undefined)
- return false;
- if (typeof handler === 'function') {
- ReflectApply(handler, this, args);
- } else {
- var len = handler.length;
- var listeners = arrayClone(handler, len);
- for (var i = 0; i < len; ++i)
- ReflectApply(listeners[i], this, args);
- }
- return true;
- };
- function _addListener(target, type, listener, prepend) {
- var m;
- var events;
- var existing;
- if (typeof listener !== 'function') {
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
- }
- events = target._events;
- if (events === undefined) {
- events = target._events = Object.create(null);
- target._eventsCount = 0;
- } else {
- // To avoid recursion in the case that type === "newListener"! Before
- // adding it to the listeners, first emit "newListener".
- if (events.newListener !== undefined) {
- target.emit('newListener', type,
- listener.listener ? listener.listener : listener);
- // Re-assign `events` because a newListener handler could have caused the
- // this._events to be assigned to a new object
- events = target._events;
- }
- existing = events[type];
- }
- if (existing === undefined) {
- // Optimize the case of one listener. Don't need the extra array object.
- existing = events[type] = listener;
- ++target._eventsCount;
- } else {
- if (typeof existing === 'function') {
- // Adding the second element, need to change to array.
- existing = events[type] =
- prepend ? [listener, existing] : [existing, listener];
- // If we've already got an array, just append.
- } else if (prepend) {
- existing.unshift(listener);
- } else {
- existing.push(listener);
- }
- // Check for listener leak
- m = $getMaxListeners(target);
- if (m > 0 && existing.length > m && !existing.warned) {
- existing.warned = true;
- // No error code for this since it is a Warning
- // eslint-disable-next-line no-restricted-syntax
- var w = new Error('Possible EventEmitter memory leak detected. ' +
- existing.length + ' ' + String(type) + ' listeners ' +
- 'added. Use emitter.setMaxListeners() to ' +
- 'increase limit');
- w.name = 'MaxListenersExceededWarning';
- w.emitter = target;
- w.type = type;
- w.count = existing.length;
- ProcessEmitWarning(w);
- }
- }
- return target;
- }
- EventEmitter.prototype.addListener = function addListener(type, listener) {
- return _addListener(this, type, listener, false);
- };
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
- EventEmitter.prototype.prependListener =
- function prependListener(type, listener) {
- return _addListener(this, type, listener, true);
- };
- function onceWrapper() {
- var args = [];
- for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);
- if (!this.fired) {
- this.target.removeListener(this.type, this.wrapFn);
- this.fired = true;
- ReflectApply(this.listener, this.target, args);
- }
- }
- function _onceWrap(target, type, listener) {
- var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
- var wrapped = onceWrapper.bind(state);
- wrapped.listener = listener;
- state.wrapFn = wrapped;
- return wrapped;
- }
- EventEmitter.prototype.once = function once(type, listener) {
- if (typeof listener !== 'function') {
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
- }
- this.on(type, _onceWrap(this, type, listener));
- return this;
- };
- EventEmitter.prototype.prependOnceListener =
- function prependOnceListener(type, listener) {
- if (typeof listener !== 'function') {
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
- }
- this.prependListener(type, _onceWrap(this, type, listener));
- return this;
- };
- // Emits a 'removeListener' event if and only if the listener was removed.
- EventEmitter.prototype.removeListener =
- function removeListener(type, listener) {
- var list, events, position, i, originalListener;
- if (typeof listener !== 'function') {
- throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
- }
- events = this._events;
- if (events === undefined)
- return this;
- list = events[type];
- if (list === undefined)
- return this;
- if (list === listener || list.listener === listener) {
- if (--this._eventsCount === 0)
- this._events = Object.create(null);
- else {
- delete events[type];
- if (events.removeListener)
- this.emit('removeListener', type, list.listener || listener);
- }
- } else if (typeof list !== 'function') {
- position = -1;
- for (i = list.length - 1; i >= 0; i--) {
- if (list[i] === listener || list[i].listener === listener) {
- originalListener = list[i].listener;
- position = i;
- break;
- }
- }
- if (position < 0)
- return this;
- if (position === 0)
- list.shift();
- else {
- spliceOne(list, position);
- }
- if (list.length === 1)
- events[type] = list[0];
- if (events.removeListener !== undefined)
- this.emit('removeListener', type, originalListener || listener);
- }
- return this;
- };
- EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
- EventEmitter.prototype.removeAllListeners =
- function removeAllListeners(type) {
- var listeners, events, i;
- events = this._events;
- if (events === undefined)
- return this;
- // not listening for removeListener, no need to emit
- if (events.removeListener === undefined) {
- if (arguments.length === 0) {
- this._events = Object.create(null);
- this._eventsCount = 0;
- } else if (events[type] !== undefined) {
- if (--this._eventsCount === 0)
- this._events = Object.create(null);
- else
- delete events[type];
- }
- return this;
- }
- // emit removeListener for all listeners on all events
- if (arguments.length === 0) {
- var keys = Object.keys(events);
- var key;
- for (i = 0; i < keys.length; ++i) {
- key = keys[i];
- if (key === 'removeListener') continue;
- this.removeAllListeners(key);
- }
- this.removeAllListeners('removeListener');
- this._events = Object.create(null);
- this._eventsCount = 0;
- return this;
- }
- listeners = events[type];
- if (typeof listeners === 'function') {
- this.removeListener(type, listeners);
- } else if (listeners !== undefined) {
- // LIFO order
- for (i = listeners.length - 1; i >= 0; i--) {
- this.removeListener(type, listeners[i]);
- }
- }
- return this;
- };
- function _listeners(target, type, unwrap) {
- var events = target._events;
- if (events === undefined)
- return [];
- var evlistener = events[type];
- if (evlistener === undefined)
- return [];
- if (typeof evlistener === 'function')
- return unwrap ? [evlistener.listener || evlistener] : [evlistener];
- return unwrap ?
- unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
- }
- EventEmitter.prototype.listeners = function listeners(type) {
- return _listeners(this, type, true);
- };
- EventEmitter.prototype.rawListeners = function rawListeners(type) {
- return _listeners(this, type, false);
- };
- EventEmitter.listenerCount = function(emitter, type) {
- if (typeof emitter.listenerCount === 'function') {
- return emitter.listenerCount(type);
- } else {
- return listenerCount.call(emitter, type);
- }
- };
- EventEmitter.prototype.listenerCount = listenerCount;
- function listenerCount(type) {
- var events = this._events;
- if (events !== undefined) {
- var evlistener = events[type];
- if (typeof evlistener === 'function') {
- return 1;
- } else if (evlistener !== undefined) {
- return evlistener.length;
- }
- }
- return 0;
- }
- EventEmitter.prototype.eventNames = function eventNames() {
- return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
- };
- function arrayClone(arr, n) {
- var copy = new Array(n);
- for (var i = 0; i < n; ++i)
- copy[i] = arr[i];
- return copy;
- }
- function spliceOne(list, index) {
- for (; index + 1 < list.length; index++)
- list[index] = list[index + 1];
- list.pop();
- }
- function unwrapListeners(arr) {
- var ret = new Array(arr.length);
- for (var i = 0; i < ret.length; ++i) {
- ret[i] = arr[i].listener || arr[i];
- }
- return ret;
- }
- /***/ }),
- /* 14 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- var SafeString = __webpack_require__(2).SafeString;
- /**
- * Returns `true` if the object is a function, otherwise `false`.
- * @param { any } value
- * @returns { boolean }
- */
- function callable(value) {
- return typeof value === 'function';
- }
- exports.callable = callable;
- /**
- * Returns `true` if the object is strictly not `undefined`.
- * @param { any } value
- * @returns { boolean }
- */
- function defined(value) {
- return value !== undefined;
- }
- exports.defined = defined;
- /**
- * Returns `true` if the operand (one) is divisble by the test's argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function divisibleby(one, two) {
- return one % two === 0;
- }
- exports.divisibleby = divisibleby;
- /**
- * Returns true if the string has been escaped (i.e., is a SafeString).
- * @param { any } value
- * @returns { boolean }
- */
- function escaped(value) {
- return value instanceof SafeString;
- }
- exports.escaped = escaped;
- /**
- * Returns `true` if the arguments are strictly equal.
- * @param { any } one
- * @param { any } two
- */
- function equalto(one, two) {
- return one === two;
- }
- exports.equalto = equalto; // Aliases
- exports.eq = exports.equalto;
- exports.sameas = exports.equalto;
- /**
- * Returns `true` if the value is evenly divisible by 2.
- * @param { number } value
- * @returns { boolean }
- */
- function even(value) {
- return value % 2 === 0;
- }
- exports.even = even;
- /**
- * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
- * undefined, NaN or null. I don't know if we should stick to the default JS
- * behavior or attempt to replicate what Python believes should be falsy (i.e.,
- * empty arrays, empty dicts, not 0...).
- * @param { any } value
- * @returns { boolean }
- */
- function falsy(value) {
- return !value;
- }
- exports.falsy = falsy;
- /**
- * Returns `true` if the operand (one) is greater or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function ge(one, two) {
- return one >= two;
- }
- exports.ge = ge;
- /**
- * Returns `true` if the operand (one) is greater than the test's argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function greaterthan(one, two) {
- return one > two;
- }
- exports.greaterthan = greaterthan; // alias
- exports.gt = exports.greaterthan;
- /**
- * Returns `true` if the operand (one) is less than or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function le(one, two) {
- return one <= two;
- }
- exports.le = le;
- /**
- * Returns `true` if the operand (one) is less than the test's passed argument
- * (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function lessthan(one, two) {
- return one < two;
- }
- exports.lessthan = lessthan; // alias
- exports.lt = exports.lessthan;
- /**
- * Returns `true` if the string is lowercased.
- * @param { string } value
- * @returns { boolean }
- */
- function lower(value) {
- return value.toLowerCase() === value;
- }
- exports.lower = lower;
- /**
- * Returns `true` if the operand (one) is less than or equal to the test's
- * argument (two).
- * @param { number } one
- * @param { number } two
- * @returns { boolean }
- */
- function ne(one, two) {
- return one !== two;
- }
- exports.ne = ne;
- /**
- * Returns true if the value is strictly equal to `null`.
- * @param { any }
- * @returns { boolean }
- */
- function nullTest(value) {
- return value === null;
- }
- exports.null = nullTest;
- /**
- * Returns true if value is a number.
- * @param { any }
- * @returns { boolean }
- */
- function number(value) {
- return typeof value === 'number';
- }
- exports.number = number;
- /**
- * Returns `true` if the value is *not* evenly divisible by 2.
- * @param { number } value
- * @returns { boolean }
- */
- function odd(value) {
- return value % 2 === 1;
- }
- exports.odd = odd;
- /**
- * Returns `true` if the value is a string, `false` if not.
- * @param { any } value
- * @returns { boolean }
- */
- function string(value) {
- return typeof value === 'string';
- }
- exports.string = string;
- /**
- * Returns `true` if the value is not in the list of things considered falsy:
- * '', null, undefined, 0, NaN and false.
- * @param { any } value
- * @returns { boolean }
- */
- function truthy(value) {
- return !!value;
- }
- exports.truthy = truthy;
- /**
- * Returns `true` if the value is undefined.
- * @param { any } value
- * @returns { boolean }
- */
- function undefinedTest(value) {
- return value === undefined;
- }
- exports.undefined = undefinedTest;
- /**
- * Returns `true` if the string is uppercased.
- * @param { string } value
- * @returns { boolean }
- */
- function upper(value) {
- return value.toUpperCase() === value;
- }
- exports.upper = upper;
- /**
- * If ES6 features are available, returns `true` if the value implements the
- * `Symbol.iterator` method. If not, it's a string or Array.
- *
- * Could potentially cause issues if a browser exists that has Set and Map but
- * not Symbol.
- *
- * @param { any } value
- * @returns { boolean }
- */
- function iterable(value) {
- if (typeof Symbol !== 'undefined') {
- return !!value[Symbol.iterator];
- } else {
- return Array.isArray(value) || typeof value === 'string';
- }
- }
- exports.iterable = iterable;
- /**
- * If ES6 features are available, returns `true` if the value is an object hash
- * or an ES6 Map. Otherwise just return if it's an object hash.
- * @param { any } value
- * @returns { boolean }
- */
- function mapping(value) {
- // only maps and object hashes
- var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
- if (Set) {
- return bool && !(value instanceof Set);
- } else {
- return bool;
- }
- }
- exports.mapping = mapping;
- /***/ }),
- /* 15 */
- /***/ (function(module, exports, __webpack_require__) {
- "use strict";
- function _cycler(items) {
- var index = -1;
- return {
- current: null,
- reset: function reset() {
- index = -1;
- this.current = null;
- },
- next: function next() {
- index++;
- if (index >= items.length) {
- index = 0;
- }
- this.current = items[index];
- return this.current;
- }
- };
- }
- function _joiner(sep) {
- sep = sep || ',';
- var first = true;
- return function () {
- var val = first ? '' : sep;
- first = false;
- return val;
- };
- } // Making this a function instead so it returns a new object
- // each time it's called. That way, if something like an environment
- // uses it, they will each have their own copy.
- function globals() {
- return {
- range: function range(start, stop, step) {
- if (typeof stop === 'undefined') {
- stop = start;
- start = 0;
- step = 1;
- } else if (!step) {
- step = 1;
- }
- var arr = [];
- if (step > 0) {
- for (var i = start; i < stop; i += step) {
- arr.push(i);
- }
- } else {
- for (var _i = start; _i > stop; _i += step) {
- // eslint-disable-line for-direction
- arr.push(_i);
- }
- }
- return arr;
- },
- cycler: function cycler() {
- return _cycler(Array.prototype.slice.call(arguments));
- },
- joiner: function joiner(sep) {
- return _joiner(sep);
- }
- };
- }
- module.exports = globals;
- /***/ }),
- /* 16 */
- /***/ (function(module, exports, __webpack_require__) {
- var path = __webpack_require__(0);
- module.exports = function express(env, app) {
- function NunjucksView(name, opts) {
- this.name = name;
- this.path = name;
- this.defaultEngine = opts.defaultEngine;
- this.ext = path.extname(name);
- if (!this.ext && !this.defaultEngine) {
- throw new Error('No default engine was specified and no extension was provided.');
- }
- if (!this.ext) {
- this.name += this.ext = (this.defaultEngine[0] !== '.' ? '.' : '') + this.defaultEngine;
- }
- }
- NunjucksView.prototype.render = function render(opts, cb) {
- env.render(this.name, opts, cb);
- };
- app.set('view', NunjucksView);
- app.set('nunjucksEnv', env);
- return env;
- };
- /***/ }),
- /* 17 */
- /***/ (function(module, exports, __webpack_require__) {
- function installCompat() {
- 'use strict';
- /* eslint-disable camelcase */
- // This must be called like `nunjucks.installCompat` so that `this`
- // references the nunjucks instance
- var runtime = this.runtime;
- var lib = this.lib; // Handle slim case where these 'modules' are excluded from the built source
- var Compiler = this.compiler.Compiler;
- var Parser = this.parser.Parser;
- var nodes = this.nodes;
- var lexer = this.lexer;
- var orig_contextOrFrameLookup = runtime.contextOrFrameLookup;
- var orig_memberLookup = runtime.memberLookup;
- var orig_Compiler_assertType;
- var orig_Parser_parseAggregate;
- if (Compiler) {
- orig_Compiler_assertType = Compiler.prototype.assertType;
- }
- if (Parser) {
- orig_Parser_parseAggregate = Parser.prototype.parseAggregate;
- }
- function uninstall() {
- runtime.contextOrFrameLookup = orig_contextOrFrameLookup;
- runtime.memberLookup = orig_memberLookup;
- if (Compiler) {
- Compiler.prototype.assertType = orig_Compiler_assertType;
- }
- if (Parser) {
- Parser.prototype.parseAggregate = orig_Parser_parseAggregate;
- }
- }
- runtime.contextOrFrameLookup = function contextOrFrameLookup(context, frame, key) {
- var val = orig_contextOrFrameLookup.apply(this, arguments);
- if (val !== undefined) {
- return val;
- }
- switch (key) {
- case 'True':
- return true;
- case 'False':
- return false;
- case 'None':
- return null;
- default:
- return undefined;
- }
- };
- function getTokensState(tokens) {
- return {
- index: tokens.index,
- lineno: tokens.lineno,
- colno: tokens.colno
- };
- }
- if (false) {
- // i.e., not slim mode
- var Slice = nodes.Node.extend('Slice', {
- fields: ['start', 'stop', 'step'],
- init: function init(lineno, colno, start, stop, step) {
- start = start || new nodes.Literal(lineno, colno, null);
- stop = stop || new nodes.Literal(lineno, colno, null);
- step = step || new nodes.Literal(lineno, colno, 1);
- this.parent(lineno, colno, start, stop, step);
- }
- });
- Compiler.prototype.assertType = function assertType(node) {
- if (node instanceof Slice) {
- return;
- }
- orig_Compiler_assertType.apply(this, arguments);
- };
- Compiler.prototype.compileSlice = function compileSlice(node, frame) {
- this._emit('(');
- this._compileExpression(node.start, frame);
- this._emit('),(');
- this._compileExpression(node.stop, frame);
- this._emit('),(');
- this._compileExpression(node.step, frame);
- this._emit(')');
- };
- Parser.prototype.parseAggregate = function parseAggregate() {
- var _this = this;
- var origState = getTokensState(this.tokens); // Set back one accounting for opening bracket/parens
- origState.colno--;
- origState.index--;
- try {
- return orig_Parser_parseAggregate.apply(this);
- } catch (e) {
- var errState = getTokensState(this.tokens);
- var rethrow = function rethrow() {
- lib._assign(_this.tokens, errState);
- return e;
- }; // Reset to state before original parseAggregate called
- lib._assign(this.tokens, origState);
- this.peeked = false;
- var tok = this.peekToken();
- if (tok.type !== lexer.TOKEN_LEFT_BRACKET) {
- throw rethrow();
- } else {
- this.nextToken();
- }
- var node = new Slice(tok.lineno, tok.colno); // If we don't encounter a colon while parsing, this is not a slice,
- // so re-raise the original exception.
- var isSlice = false;
- for (var i = 0; i <= node.fields.length; i++) {
- if (this.skip(lexer.TOKEN_RIGHT_BRACKET)) {
- break;
- }
- if (i === node.fields.length) {
- if (isSlice) {
- this.fail('parseSlice: too many slice components', tok.lineno, tok.colno);
- } else {
- break;
- }
- }
- if (this.skip(lexer.TOKEN_COLON)) {
- isSlice = true;
- } else {
- var field = node.fields[i];
- node[field] = this.parseExpression();
- isSlice = this.skip(lexer.TOKEN_COLON) || isSlice;
- }
- }
- if (!isSlice) {
- throw rethrow();
- }
- return new nodes.Array(tok.lineno, tok.colno, [node]);
- }
- };
- }
- function sliceLookup(obj, start, stop, step) {
- obj = obj || [];
- if (start === null) {
- start = step < 0 ? obj.length - 1 : 0;
- }
- if (stop === null) {
- stop = step < 0 ? -1 : obj.length;
- } else if (stop < 0) {
- stop += obj.length;
- }
- if (start < 0) {
- start += obj.length;
- }
- var results = [];
- for (var i = start;; i += step) {
- if (i < 0 || i > obj.length) {
- break;
- }
- if (step > 0 && i >= stop) {
- break;
- }
- if (step < 0 && i <= stop) {
- break;
- }
- results.push(runtime.memberLookup(obj, i));
- }
- return results;
- }
- function hasOwnProp(obj, key) {
- return Object.prototype.hasOwnProperty.call(obj, key);
- }
- var ARRAY_MEMBERS = {
- pop: function pop(index) {
- if (index === undefined) {
- return this.pop();
- }
- if (index >= this.length || index < 0) {
- throw new Error('KeyError');
- }
- return this.splice(index, 1);
- },
- append: function append(element) {
- return this.push(element);
- },
- remove: function remove(element) {
- for (var i = 0; i < this.length; i++) {
- if (this[i] === element) {
- return this.splice(i, 1);
- }
- }
- throw new Error('ValueError');
- },
- count: function count(element) {
- var count = 0;
- for (var i = 0; i < this.length; i++) {
- if (this[i] === element) {
- count++;
- }
- }
- return count;
- },
- index: function index(element) {
- var i;
- if ((i = this.indexOf(element)) === -1) {
- throw new Error('ValueError');
- }
- return i;
- },
- find: function find(element) {
- return this.indexOf(element);
- },
- insert: function insert(index, elem) {
- return this.splice(index, 0, elem);
- }
- };
- var OBJECT_MEMBERS = {
- items: function items() {
- return lib._entries(this);
- },
- values: function values() {
- return lib._values(this);
- },
- keys: function keys() {
- return lib.keys(this);
- },
- get: function get(key, def) {
- var output = this[key];
- if (output === undefined) {
- output = def;
- }
- return output;
- },
- has_key: function has_key(key) {
- return hasOwnProp(this, key);
- },
- pop: function pop(key, def) {
- var output = this[key];
- if (output === undefined && def !== undefined) {
- output = def;
- } else if (output === undefined) {
- throw new Error('KeyError');
- } else {
- delete this[key];
- }
- return output;
- },
- popitem: function popitem() {
- var keys = lib.keys(this);
- if (!keys.length) {
- throw new Error('KeyError');
- }
- var k = keys[0];
- var val = this[k];
- delete this[k];
- return [k, val];
- },
- setdefault: function setdefault(key, def) {
- if (def === void 0) {
- def = null;
- }
- if (!(key in this)) {
- this[key] = def;
- }
- return this[key];
- },
- update: function update(kwargs) {
- lib._assign(this, kwargs);
- return null; // Always returns None
- }
- };
- OBJECT_MEMBERS.iteritems = OBJECT_MEMBERS.items;
- OBJECT_MEMBERS.itervalues = OBJECT_MEMBERS.values;
- OBJECT_MEMBERS.iterkeys = OBJECT_MEMBERS.keys;
- runtime.memberLookup = function memberLookup(obj, val, autoescape) {
- if (arguments.length === 4) {
- return sliceLookup.apply(this, arguments);
- }
- obj = obj || {}; // If the object is an object, return any of the methods that Python would
- // otherwise provide.
- if (lib.isArray(obj) && hasOwnProp(ARRAY_MEMBERS, val)) {
- return ARRAY_MEMBERS[val].bind(obj);
- }
- if (lib.isObject(obj) && hasOwnProp(OBJECT_MEMBERS, val)) {
- return OBJECT_MEMBERS[val].bind(obj);
- }
- return orig_memberLookup.apply(this, arguments);
- };
- return uninstall;
- }
- module.exports = installCompat;
- /***/ })
- /******/ ]);
- });
- //# sourceMappingURL=nunjucks-slim.js.map
|