How to use partials method in wpt

Best JavaScript code snippet using wpt

api-data.js

Source:api-data.js Github

copy

Full Screen

1angular.module('app')2.constant('API', [3 {4 "name": "app",5 "outputPath": "./partials/partials/api/app/index.html",6 "url": "/api/app"7 },8 {9 "name": "app.common.router",10 "outputPath": "./partials/partials/api/app.common.router/index.html",11 "url": "/api/app.common.router"12 },13 {14 "name": "app.core",15 "outputPath": "./partials/partials/api/app.core/index.html",16 "url": "/api/app.core"17 },18 {19 "name": "app.geo",20 "outputPath": "./partials/partials/api/app.geo/index.html",21 "url": "/api/app.geo"22 },23 {24 "name": "app.layout",25 "outputPath": "./partials/partials/api/app.layout/index.html",26 "url": "/api/app.layout"27 },28 {29 "name": "app.ui.appbar",30 "outputPath": "./partials/partials/api/app.ui.appbar/index.html",31 "url": "/api/app.ui.appbar"32 },33 {34 "name": "app.ui.basemap",35 "outputPath": "./partials/partials/api/app.ui.basemap/index.html",36 "url": "/api/app.ui.basemap"37 },38 {39 "name": "app.ui.common",40 "outputPath": "./partials/partials/api/app.ui.common/index.html",41 "url": "/api/app.ui.common"42 },43 {44 "name": "app.ui.common.stepper",45 "outputPath": "./partials/partials/api/app.ui.common.stepper/index.html",46 "url": "/api/app.ui.common.stepper"47 },48 {49 "name": "app.ui.details",50 "outputPath": "./partials/partials/api/app.ui.details/index.html",51 "url": "/api/app.ui.details"52 },53 {54 "name": "app.ui.filters",55 "outputPath": "./partials/partials/api/app.ui.filters/index.html",56 "url": "/api/app.ui.filters"57 },58 {59 "name": "app.ui.help",60 "outputPath": "./partials/partials/api/app.ui.help/index.html",61 "url": "/api/app.ui.help"62 },63 {64 "name": "app.ui.loader",65 "outputPath": "./partials/partials/api/app.ui.loader/index.html",66 "url": "/api/app.ui.loader"67 },68 {69 "name": "app.ui.mapnav",70 "outputPath": "./partials/partials/api/app.ui.mapnav/index.html",71 "url": "/api/app.ui.mapnav"72 },73 {74 "name": "app.ui.metadata",75 "outputPath": "./partials/partials/api/app.ui.metadata/index.html",76 "url": "/api/app.ui.metadata"77 },78 {79 "name": "app.ui.panels",80 "outputPath": "./partials/partials/api/app.ui.panels/index.html",81 "url": "/api/app.ui.panels"82 },83 {84 "name": "app.ui.settings",85 "outputPath": "./partials/partials/api/app.ui.settings/index.html",86 "url": "/api/app.ui.settings"87 },88 {89 "name": "app.ui.sidenav",90 "outputPath": "./partials/partials/api/app.ui.sidenav/index.html",91 "url": "/api/app.ui.sidenav"92 },93 {94 "name": "app.ui.toc",95 "outputPath": "./partials/partials/api/app.ui.toc/index.html",96 "url": "/api/app.ui.toc"97 },98 {99 "name": "app.ui.toolbox",100 "outputPath": "./partials/partials/api/app.ui.toolbox/index.html",101 "url": "/api/app.ui.toolbox"102 },103 {104 "name": "app.ui",105 "outputPath": "./partials/partials/api/app.ui/index.html",106 "url": "/api/app.ui"107 },108 {109 "name": "displayManager",110 "outputPath": "./partials/partials/api/app.common.router/service/displayManager.html",111 "url": "/api/app.common.router/service/displayManager"112 },113 {114 "name": "initialState",115 "outputPath": "./partials/partials/api/app.common.router/service/initialState.html",116 "url": "/api/app.common.router/service/initialState"117 },118 {119 "name": "initialDisplay",120 "outputPath": "./partials/partials/api/app.common.router/service/initialDisplay.html",121 "url": "/api/app.common.router/service/initialDisplay"122 },123 {124 "name": "stateManager",125 "outputPath": "./partials/partials/api/app.common/service/stateManager.html",126 "url": "/api/app.common/service/stateManager"127 },128 {129 "name": "common",130 "outputPath": "./partials/partials/api/app.core/service/common.html",131 "url": "/api/app.core/service/common"132 },133 {134 "name": "configService",135 "outputPath": "./partials/partials/api/app.core/service/configService.html",136 "url": "/api/app.core/service/configService"137 },138 {139 "name": "configDefaults",140 "outputPath": "./partials/partials/api/app.core/service/configDefaults.html",141 "url": "/api/app.core/service/configDefaults"142 },143 {144 "name": "templateRegistry",145 "outputPath": "./partials/partials/api/app.core/service/templateRegistry.html",146 "url": "/api/app.core/service/templateRegistry"147 },148 {149 "name": "configBlock",150 "outputPath": "./partials/partials/api/app.core/function/configBlock.html",151 "url": "/api/app.core/function/configBlock"152 },153 {154 "name": "runBlock",155 "outputPath": "./partials/partials/api/app.core/function/runBlock.html",156 "url": "/api/app.core/function/runBlock"157 },158 {159 "name": "globalRegistry",160 "outputPath": "./partials/partials/api/app.core/service/globalRegistry.html",161 "url": "/api/app.core/service/globalRegistry"162 },163 {164 "name": "version",165 "outputPath": "./partials/partials/api/app.core/service/version.html",166 "url": "/api/app.core/service/version"167 },168 {169 "name": "gapi",170 "outputPath": "./partials/partials/api/app.geo/service/gapi.html",171 "url": "/api/app.geo/service/gapi"172 },173 {174 "name": "Geo",175 "outputPath": "./partials/partials/api/app.geo/service/Geo.html",176 "url": "/api/app.geo/service/Geo"177 },178 {179 "name": "geoService",180 "outputPath": "./partials/partials/api/app.geo/service/geoService.html",181 "url": "/api/app.geo/service/geoService"182 },183 {184 "name": "identifyService",185 "outputPath": "./partials/partials/api/app.geo/service/identifyService.html",186 "url": "/api/app.geo/service/identifyService"187 },188 {189 "name": "rvInitMap",190 "outputPath": "./partials/partials/api/app.geo/directive/rvInitMap.html",191 "url": "/api/app.geo/directive/rvInitMap"192 },193 {194 "name": "LayerBlueprintUserOptions",195 "outputPath": "./partials/partials/api/app.geo/service/LayerBlueprintUserOptions.html",196 "url": "/api/app.geo/service/LayerBlueprintUserOptions"197 },198 {199 "name": "LayerBlueprint",200 "outputPath": "./partials/partials/api/app.geo/service/LayerBlueprint.html",201 "url": "/api/app.geo/service/LayerBlueprint"202 },203 {204 "name": "layerRegistry",205 "outputPath": "./partials/partials/api/app.geo/service/layerRegistry.html",206 "url": "/api/app.geo/service/layerRegistry"207 },208 {209 "name": "legendEntryFactory",210 "outputPath": "./partials/partials/api/app.geo/service/legendEntryFactory.html",211 "url": "/api/app.geo/service/legendEntryFactory"212 },213 {214 "name": "legendService",215 "outputPath": "./partials/partials/api/app.geo/service/legendService.html",216 "url": "/api/app.geo/service/legendService"217 },218 {219 "name": "mapService",220 "outputPath": "./partials/partials/api/app.geo/service/mapService.html",221 "url": "/api/app.geo/service/mapService"222 },223 {224 "name": "metadataService",225 "outputPath": "./partials/partials/api/app.geo/service/metadataService.html",226 "url": "/api/app.geo/service/metadataService"227 },228 {229 "name": "layoutService",230 "outputPath": "./partials/partials/api/app.layout/service/layoutService.html",231 "url": "/api/app.layout/service/layoutService"232 },233 {234 "name": "rvShell",235 "outputPath": "./partials/partials/api/app.layout/directive/rvShell.html",236 "url": "/api/app.layout/directive/rvShell"237 },238 {239 "name": "storageService",240 "outputPath": "./partials/partials/api/app.layout/service/storageService.html",241 "url": "/api/app.layout/service/storageService"242 },243 {244 "name": "rvAppbar",245 "outputPath": "./partials/partials/api/app.ui.appbar/directive/rvAppbar.html",246 "url": "/api/app.ui.appbar/directive/rvAppbar"247 },248 {249 "name": "rvBasemapItem",250 "outputPath": "./partials/partials/api/app.ui.basemap/directive/rvBasemapItem.html",251 "url": "/api/app.ui.basemap/directive/rvBasemapItem"252 },253 {254 "name": "rvBasemap",255 "outputPath": "./partials/partials/api/app.ui.basemap/directive/rvBasemap.html",256 "url": "/api/app.ui.basemap/directive/rvBasemap"257 },258 {259 "name": "rvDetectScrollbar",260 "outputPath": "./partials/partials/api/app.ui.common/directive/rvDetectScrollbar.html",261 "url": "/api/app.ui.common/directive/rvDetectScrollbar"262 },263 {264 "name": "rvDragula",265 "outputPath": "./partials/partials/api/app.ui.common/directive/rvDragula.html",266 "url": "/api/app.ui.common/directive/rvDragula"267 },268 {269 "name": "errorService",270 "outputPath": "./partials/partials/api/app.ui.common/service/errorService.html",271 "url": "/api/app.ui.common/service/errorService"272 },273 {274 "name": "fullscreen",275 "outputPath": "./partials/partials/api/app.ui.common/service/fullscreen.html",276 "url": "/api/app.ui.common/service/fullscreen"277 },278 {279 "name": "mdMenuItemDirectiveDecorator",280 "outputPath": "./partials/partials/api/material.components.menuBar/object/mdMenuItemDirectiveDecorator.html",281 "url": "/api/material.components.menuBar/object/mdMenuItemDirectiveDecorator"282 },283 {284 "name": "rvMorph",285 "outputPath": "./partials/partials/api/app.ui.common/directive/rvMorph.html",286 "url": "/api/app.ui.common/directive/rvMorph"287 },288 {289 "name": "rvPlugSlide",290 "outputPath": "./partials/partials/api/app.ui.common/service/rvPlugSlide.html",291 "url": "/api/app.ui.common/service/rvPlugSlide"292 },293 {294 "name": "rvReverse",295 "outputPath": "./partials/partials/api/app.common/filter/rvReverse.html",296 "url": "/api/app.common/filter/rvReverse"297 },298 {299 "name": "rvStepperItem",300 "outputPath": "./partials/partials/api/app.ui.common.stepper/directive/rvStepperItem.html",301 "url": "/api/app.ui.common.stepper/directive/rvStepperItem"302 },303 {304 "name": "Stepper",305 "outputPath": "./partials/partials/api/app.ui.common.stepper/object/Stepper.html",306 "url": "/api/app.ui.common.stepper/object/Stepper"307 },308 {309 "name": "rvToggleSlide",310 "outputPath": "./partials/partials/api/app.ui.common/service/rvToggleSlide.html",311 "url": "/api/app.ui.common/service/rvToggleSlide"312 },313 {314 "name": "rvTruncate",315 "outputPath": "./partials/partials/api/app.ui.common/directive/rvTruncate.html",316 "url": "/api/app.ui.common/directive/rvTruncate"317 },318 {319 "name": "rvDetailsContent",320 "outputPath": "./partials/partials/api/app.ui.details/directive/rvDetailsContent.html",321 "url": "/api/app.ui.details/directive/rvDetailsContent"322 },323 {324 "name": "rvDetailsExpand",325 "outputPath": "./partials/partials/api/app.ui.details/directive/rvDetailsExpand.html",326 "url": "/api/app.ui.details/directive/rvDetailsExpand"327 },328 {329 "name": "rvDetails",330 "outputPath": "./partials/partials/api/app.ui.details/directive/rvDetails.html",331 "url": "/api/app.ui.details/directive/rvDetails"332 },333 {334 "name": "rvFiltersDefaultMenu",335 "outputPath": "./partials/partials/api/app.ui.filters/directive/rvFiltersDefaultMenu.html",336 "url": "/api/app.ui.filters/directive/rvFiltersDefaultMenu"337 },338 {339 "name": "rvFiltersDefault",340 "outputPath": "./partials/partials/api/app.ui.filters/directive/rvFiltersDefault.html",341 "url": "/api/app.ui.filters/directive/rvFiltersDefault"342 },343 {344 "name": "rvHelpOverlay",345 "outputPath": "./partials/partials/api/app.ui.help/directive/rvHelpOverlay.html",346 "url": "/api/app.ui.help/directive/rvHelpOverlay"347 },348 {349 "name": "rvHelp",350 "outputPath": "./partials/partials/api/app.ui.help/directive/rvHelp.html",351 "url": "/api/app.ui.help/directive/rvHelp"352 },353 {354 "name": "helpService",355 "outputPath": "./partials/partials/api/app.ui.help/service/helpService.html",356 "url": "/api/app.ui.help/service/helpService"357 },358 {359 "name": "rv-loader-file",360 "outputPath": "./partials/partials/api/app.ui.loader/directive/rv-loader-file.html",361 "url": "/api/app.ui.loader/directive/rv-loader-file"362 },363 {364 "name": "rvLoaderMenu",365 "outputPath": "./partials/partials/api/app.ui.loader/directive/rvLoaderMenu.html",366 "url": "/api/app.ui.loader/directive/rvLoaderMenu"367 },368 {369 "name": "rv-loader-service",370 "outputPath": "./partials/partials/api/app.ui.loader/directive/rv-loader-service.html",371 "url": "/api/app.ui.loader/directive/rv-loader-service"372 },373 {374 "name": "rvMapnavButton",375 "outputPath": "./partials/partials/api/app.ui.mapnav/directive/rvMapnavButton.html",376 "url": "/api/app.ui.mapnav/directive/rvMapnavButton"377 },378 {379 "name": "rvMapnav",380 "outputPath": "./partials/partials/api/app.ui.mapnav/directive/rvMapnav.html",381 "url": "/api/app.ui.mapnav/directive/rvMapnav"382 },383 {384 "name": "mapNavigationService",385 "outputPath": "./partials/partials/api/app.ui.mapnav/service/mapNavigationService.html",386 "url": "/api/app.ui.mapnav/service/mapNavigationService"387 },388 {389 "name": "rvMetadataContent",390 "outputPath": "./partials/partials/api/app.ui.metadata/directive/rvMetadataContent.html",391 "url": "/api/app.ui.metadata/directive/rvMetadataContent"392 },393 {394 "name": "rvMetadataExpand",395 "outputPath": "./partials/partials/api/app.ui.metadata/directive/rvMetadataExpand.html",396 "url": "/api/app.ui.metadata/directive/rvMetadataExpand"397 },398 {399 "name": "rvMetadataPanel",400 "outputPath": "./partials/partials/api/app.ui.metadata/directive/rvMetadataPanel.html",401 "url": "/api/app.ui.metadata/directive/rvMetadataPanel"402 },403 {404 "name": "rvContentPane",405 "outputPath": "./partials/partials/api/app.ui.panels/directive/rvContentPane.html",406 "url": "/api/app.ui.panels/directive/rvContentPane"407 },408 {409 "name": "rvFiltersPanel",410 "outputPath": "./partials/partials/api/app.ui.panels/directive/rvFiltersPanel.html",411 "url": "/api/app.ui.panels/directive/rvFiltersPanel"412 },413 {414 "name": "rvSettings",415 "outputPath": "./partials/partials/api/app.ui.settings/directive/rvSettings.html",416 "url": "/api/app.ui.settings/directive/rvSettings"417 },418 {419 "name": "rvMenuLink",420 "outputPath": "./partials/partials/api/app.ui.sidenav/directive/rvMenuLink.html",421 "url": "/api/app.ui.sidenav/directive/rvMenuLink"422 },423 {424 "name": "sideNavigationService",425 "outputPath": "./partials/partials/api/app.ui.sidenav/service/sideNavigationService.html",426 "url": "/api/app.ui.sidenav/service/sideNavigationService"427 },428 {429 "name": "rvTocEntryControl",430 "outputPath": "./partials/partials/api/ap/directive/rvTocEntryControl.html",431 "url": "/api/ap/directive/rvTocEntryControl"432 },433 {434 "name": "rvTocEntryFlag",435 "outputPath": "./partials/partials/api/app.ui.toc/directive/rvTocEntryFlag.html",436 "url": "/api/app.ui.toc/directive/rvTocEntryFlag"437 },438 {439 "name": "rvLayerItemSymbology",440 "outputPath": "./partials/partials/api/app.ui.toc/directive/rvLayerItemSymbology.html",441 "url": "/api/app.ui.toc/directive/rvLayerItemSymbology"442 },443 {444 "name": "rvTocEntry",445 "outputPath": "./partials/partials/api/app.ui.toc/directive/rvTocEntry.html",446 "url": "/api/app.ui.toc/directive/rvTocEntry"447 },448 {449 "name": "rvToc",450 "outputPath": "./partials/partials/api/app.ui.toc/directive/rvToc.html",451 "url": "/api/app.ui.toc/directive/rvToc"452 },453 {454 "name": "tocService",455 "outputPath": "./partials/partials/api/app.ui.toc/service/tocService.html",456 "url": "/api/app.ui.toc/service/tocService"457 },458 {459 "name": "rvToolbox",460 "outputPath": "./partials/partials/api/app.ui.toolbox/directive/rvToolbox.html",461 "url": "/api/app.ui.toolbox/directive/rvToolbox"462 }...

Full Screen

Full Screen

template.js

Source:template.js Github

copy

Full Screen

1/*2 * Copyright 2011 Twitter, Inc.3 * Licensed under the Apache License, Version 2.0 (the "License");4 * you may not use this file except in compliance with the License.5 * You may obtain a copy of the License at6 *7 * http://www.apache.org/licenses/LICENSE-2.08 *9 * Unless required by applicable law or agreed to in writing, software10 * distributed under the License is distributed on an "AS IS" BASIS,11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * See the License for the specific language governing permissions and13 * limitations under the License.14 */15var Hogan = {};16(function (Hogan) {17 Hogan.Template = function (codeObj, text, compiler, options) {18 codeObj = codeObj || {};19 this.r = codeObj.code || this.r;20 this.c = compiler;21 this.options = options || {};22 this.text = text || '';23 this.partials = codeObj.partials || {};24 this.subs = codeObj.subs || {};25 this.buf = '';26 }27 Hogan.Template.prototype = {28 // render: replaced by generated code.29 r: function (context, partials, indent) { return ''; },30 // variable escaping31 v: hoganEscape,32 // triple stache33 t: coerceToString,34 render: function render(context, partials, indent) {35 return this.ri([context], partials || {}, indent);36 },37 // render internal -- a hook for overrides that catches partials too38 ri: function (context, partials, indent) {39 return this.r(context, partials, indent);40 },41 // ensurePartial42 ep: function(symbol, partials) {43 var partial = this.partials[symbol];44 // check to see that if we've instantiated this partial before45 var template = partials[partial.name];46 if (partial.instance && partial.base == template) {47 return partial.instance;48 }49 if (typeof template == 'string') {50 if (!this.c) {51 throw new Error("No compiler available.");52 }53 template = this.c.compile(template, this.options);54 }55 if (!template) {56 return null;57 }58 // We use this to check whether the partials dictionary has changed59 this.partials[symbol].base = template;60 if (partial.subs) {61 // Make sure we consider parent template now62 if (!partials.stackText) partials.stackText = {};63 for (key in partial.subs) {64 if (!partials.stackText[key]) {65 partials.stackText[key] = (this.activeSub !== undefined && partials.stackText[this.activeSub]) ? partials.stackText[this.activeSub] : this.text;66 }67 }68 template = createSpecializedPartial(template, partial.subs, partial.partials,69 this.stackSubs, this.stackPartials, partials.stackText);70 }71 this.partials[symbol].instance = template;72 return template;73 },74 // tries to find a partial in the current scope and render it75 rp: function(symbol, context, partials, indent) {76 var partial = this.ep(symbol, partials);77 if (!partial) {78 return '';79 }80 return partial.ri(context, partials, indent);81 },82 // render a section83 rs: function(context, partials, section) {84 var tail = context[context.length - 1];85 if (!isArray(tail)) {86 section(context, partials, this);87 return;88 }89 for (var i = 0; i < tail.length; i++) {90 context.push(tail[i]);91 section(context, partials, this);92 context.pop();93 }94 },95 // maybe start a section96 s: function(val, ctx, partials, inverted, start, end, tags) {97 var pass;98 if (isArray(val) && val.length === 0) {99 return false;100 }101 if (typeof val == 'function') {102 val = this.ms(val, ctx, partials, inverted, start, end, tags);103 }104 pass = !!val;105 if (!inverted && pass && ctx) {106 ctx.push((typeof val == 'object') ? val : ctx[ctx.length - 1]);107 }108 return pass;109 },110 // find values with dotted names111 d: function(key, ctx, partials, returnFound) {112 var found,113 names = key.split('.'),114 val = this.f(names[0], ctx, partials, returnFound),115 doModelGet = this.options.modelGet,116 cx = null;117 if (key === '.' && isArray(ctx[ctx.length - 2])) {118 val = ctx[ctx.length - 1];119 } else {120 for (var i = 1; i < names.length; i++) {121 found = findInScope(names[i], val, doModelGet);122 if (found !== undefined) {123 cx = val;124 val = found;125 } else {126 val = '';127 }128 }129 }130 if (returnFound && !val) {131 return false;132 }133 if (!returnFound && typeof val == 'function') {134 ctx.push(cx);135 val = this.mv(val, ctx, partials);136 ctx.pop();137 }138 return val;139 },140 // find values with normal names141 f: function(key, ctx, partials, returnFound) {142 var val = false,143 v = null,144 found = false,145 doModelGet = this.options.modelGet;146 for (var i = ctx.length - 1; i >= 0; i--) {147 v = ctx[i];148 val = findInScope(key, v, doModelGet);149 if (val !== undefined) {150 found = true;151 break;152 }153 }154 if (!found) {155 return (returnFound) ? false : "";156 }157 if (!returnFound && typeof val == 'function') {158 val = this.mv(val, ctx, partials);159 }160 return val;161 },162 // higher order templates163 ls: function(func, cx, ctx, partials, text, tags) {164 var oldTags = this.options.delimiters;165 this.options.delimiters = tags;166 this.b(this.ct(coerceToString(func.call(cx, text, ctx)), cx, partials));167 this.options.delimiters = oldTags;168 return false;169 },170 // compile text171 ct: function(text, cx, partials) {172 if (this.options.disableLambda) {173 throw new Error('Lambda features disabled.');174 }175 return this.c.compile(text, this.options).render(cx, partials);176 },177 // template result buffering178 b: function(s) { this.buf += s; },179 fl: function() { var r = this.buf; this.buf = ''; return r; },180 // method replace section181 ms: function(func, ctx, partials, inverted, start, end, tags) {182 var textSource,183 cx = ctx[ctx.length - 1],184 result = func.call(cx);185 if (typeof result == 'function') {186 if (inverted) {187 return true;188 } else {189 textSource = (this.activeSub && this.subsText && this.subsText[this.activeSub]) ? this.subsText[this.activeSub] : this.text;190 return this.ls(result, cx, ctx, partials, textSource.substring(start, end), tags);191 }192 }193 return result;194 },195 // method replace variable196 mv: function(func, ctx, partials) {197 var cx = ctx[ctx.length - 1];198 var result = func.call(cx);199 if (typeof result == 'function') {200 return this.ct(coerceToString(result.call(cx)), cx, partials);201 }202 return result;203 },204 sub: function(name, context, partials, indent) {205 var f = this.subs[name];206 if (f) {207 this.activeSub = name;208 f(context, partials, this, indent);209 this.activeSub = false;210 }211 }212 };213 //Find a key in an object214 function findInScope(key, scope, doModelGet) {215 var val;216 if (scope && typeof scope == 'object') {217 if (scope[key] !== undefined) {218 val = scope[key];219 // try lookup with get for backbone or similar model data220 } else if (doModelGet && scope.get && typeof scope.get == 'function') {221 val = scope.get(key);222 }223 }224 return val;225 }226 function createSpecializedPartial(instance, subs, partials, stackSubs, stackPartials, stackText) {227 function PartialTemplate() {};228 PartialTemplate.prototype = instance;229 function Substitutions() {};230 Substitutions.prototype = instance.subs;231 var key;232 var partial = new PartialTemplate();233 partial.subs = new Substitutions();234 partial.subsText = {}; //hehe. substext.235 partial.buf = '';236 stackSubs = stackSubs || {};237 partial.stackSubs = stackSubs;238 partial.subsText = stackText;239 for (key in subs) {240 if (!stackSubs[key]) stackSubs[key] = subs[key];241 }242 for (key in stackSubs) {243 partial.subs[key] = stackSubs[key];244 }245 stackPartials = stackPartials || {};246 partial.stackPartials = stackPartials;247 for (key in partials) {248 if (!stackPartials[key]) stackPartials[key] = partials[key];249 }250 for (key in stackPartials) {251 partial.partials[key] = stackPartials[key];252 }253 return partial;254 }255 var rAmp = /&/g,256 rLt = /</g,257 rGt = />/g,258 rApos = /\'/g,259 rQuot = /\"/g,260 hChars = /[&<>\"\']/;261 function coerceToString(val) {262 return String((val === null || val === undefined) ? '' : val);263 }264 function hoganEscape(str) {265 str = coerceToString(str);266 return hChars.test(str) ?267 str268 .replace(rAmp, '&amp;')269 .replace(rLt, '&lt;')270 .replace(rGt, '&gt;')271 .replace(rApos, '&#39;')272 .replace(rQuot, '&quot;') :273 str;274 }275 var isArray = Array.isArray || function(a) {276 return Object.prototype.toString.call(a) === '[object Array]';277 };...

Full Screen

Full Screen

MustacheTemplate.js

Source:MustacheTemplate.js Github

copy

Full Screen

1const { inspect } = require('util');2const AbstractCompiledResource = require('./AbstractCompiledResource');3const Hogan = require('hogan.js');4class MustacheTemplate extends AbstractCompiledResource {5 static get supportedExtensions() {6 return ['.mst', '.mustache', '.tpt'];7 }8 constructor(...args) {9 super(...args);10 if (!this.io) {11 throw new Error('IOInterface as second argument');12 }13 if (typeof this.io.readFile !== 'function') {14 throw new Error(15 `IOInterface missing readFile method: ${inspect(this.io)}`16 );17 }18 this._loadedPartials = new Map();19 }20 _tryLoadAllExtensions(21 name,22 extensions = MustacheTemplate.supportedExtensions23 ) {24 return this.io.readFile(name + extensions[0], 'utf8').catch(e => {25 if (e.code !== 'ENOENT' || extensions.length === 1) {26 throw e;27 }28 return this._tryLoadAllExtensions(name, extensions.slice(1));29 });30 }31 _findUnloadedPartialNames(template) {32 const partialNames = Object.values(template.partials).map(33 ({ name }) => name34 );35 const uniquePartialNames = [...new Set(partialNames)];36 return uniquePartialNames.filter(37 name => !this._loadedPartials.has(name)38 );39 }40 async _loadPartial(name) {41 let partial = this._loadedPartials.get(name);42 if (!partial) {43 try {44 partial = Hogan.compile(45 (await this._tryLoadAllExtensions(name)).trim()46 );47 this._loadedPartials.set(name, partial);48 } catch (error) {49 return { badPartial: { name, error } };50 }51 }52 return partial;53 }54 async _loadPartials(partialNames) {55 const loadedPartials = await Promise.all(56 partialNames.map(name => this._loadPartial(name))57 );58 const badPartials = loadedPartials.filter(59 ({ badPartial }) => badPartial60 );61 if (badPartials.length > 0) {62 const partialErrors = badPartials.map(63 ({ badPartial: { name, error } }) =>64 `'${name}: ${error.stack}\n`65 );66 throw new Error(`Error in template partials: ${partialErrors}`);67 }68 const foundDescendentPartials = loadedPartials.reduce(69 (found, tpt) => found.concat(this._findUnloadedPartialNames(tpt)),70 []71 );72 if (foundDescendentPartials.length > 0) {73 return await this._loadPartials([74 ...new Set(foundDescendentPartials)75 ]);76 }77 }78 async compile() {79 this._template = Hogan.compile(this.source);80 // recursively load all descendent partials ahead of time81 await this._loadPartials(82 this._findUnloadedPartialNames(this._template)83 );84 this._partials = {};85 for (const [name, tpt] of this._loadedPartials.entries()) {86 this._partials[name] = tpt;87 }88 return this;89 }90 async render(context) {91 return this._template.render(context, this._partials, '').trim();92 }93}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5wpt.runTest(url, options, function(err, data) {6 if (err) return console.error(err);7 console.log('Test %s from %s completed', data.testId, data.from);8});9var wpt = require('webpagetest');10var wpt = new WebPageTest('www.webpagetest.org');11var options = {12};13wpt.runTest(url, options, function(err, data) {14 if (err) return console.error(err);15 console.log('Test %s from %s completed', data.testId, data.from);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19var options = {20};21wpt.runTest(url, options, function(err, data) {22 if (err) return console.error(err);23 console.log('Test %s from %s completed', data.testId, data.from);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1get_header();2get_template_part('content','page');3get_footer();4<?php the_content(); ?>5function wptheme_add_scripts(){6 wp_enqueue_style('wptheme-main-style',get_stylesheet_uri());7}8add_action('wp_enqueue_scripts','wptheme_add_scripts');9<?php get_header(); ?>10<?php if(have_posts()) : ?>11 <?php while(have_posts()) : the_post(); ?>12 <h3><?php the_title(); ?></h3>13 <small>Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, in <?php the_category(); ?></small>14 <p><?php the_content(); ?></p>15 <?php endwhile; ?>16 <?php echo wpautop('Sorry, no posts were found'); ?>17<?php endif; ?>18<?php get_footer(); ?>19<?php get_header(); ?>20<?php if(have_posts()) : ?>21 <?php while(have_posts()) : the_post(); ?>22 <h3><?php the_title(); ?></h3>23 <small>Posted on: <?php the_time('F j

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools')2var fs = require('fs')3var path = require('path')4var page = wptools.page('Albert_Einstein', { partials: partials })5page.get(function(err, resp) {6 fs.writeFileSync(path.join(__dirname, 'partial.json'), JSON.stringify(resp, null, 2))7})8### `wptools.page(title, [options])`9### `page.get(callback)`10### `page.request(callback)`11### `page.getHtml(callback)`12### `page.requestHtml(callback)`13### `page.getInfobox(callback)`14### `page.requestInfobox(callback)`15### `page.getCoordinates(callback)`16### `page.requestCoordinates(callback)`17### `page.getDescription(callback)`

Full Screen

Using AI Code Generation

copy

Full Screen

1var path = require('path');2var wptoolkit = require('wptoolkit');3var partials = wptoolkit.partials;4partials({5 path: path.join(__dirname, 'partials')6});7var path = require('path');8var wptoolkit = require('wptoolkit');9var partials = wptoolkit.partials;10partials({11 path: path.join(__dirname, 'partials')12});13var path = require('path');14var wptoolkit = require('wptoolkit');15var partials = wptoolkit.partials;16partials({17 path: path.join(__dirname, 'partials')18});19var wptoolkit = require('wptoolkit');20### wptoolkit.init([options])21Default: `process.cwd()`22Default: `path.join(cwd, 'partials')`23Default: `['{{', '}}']`24Default: `{}`25Default: `{}`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4wpt.runTest(options, function(err, data) {5 if (err) return console.error(err);6 console.log('Test status:', data.statusText);7 if (data.statusCode === 200) {8 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');9 console.log('View your test at', data.data.userUrl);10 }11});12var wpt = require('webpagetest');13var options = {14};15wpt.runTest(options, function(err, data) {16 if (err) return console.error(err);17 console.log('Test status:', data.statusText);18 if (data.statusCode === 200) {19 console.log('Test completed in', data.data.average.firstView.loadTime, 'ms');20 console.log('View your test at', data.data.userUrl);21 }22});23var wpt = require('webpagetest');24var options = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var fs = require('fs');3var client = wpt('www.webpagetest.org');4var options = {5};6client.runTest(url, options, function(err, data) {7 if (err) return console.error(err);8 console.log('Test ID: %s', data.data.testId);9 var testId = data.data.testId;10 client.getTestResults(testId, function(err, data) {11 if (err) return console.error(err);12 var head = data.data.runs[1].firstView.head;13 var body = data.data.runs[1].firstView.body;14 var html = head + body;15 fs.writeFile('test.html', html, function(err) {16 if (err) throw err;17 console.log('It\'s saved!');18 });19 });20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var toolkit = new wptoolkit();3toolkit.partialsPath = '/path/to/partials/folder/';4toolkit.partials = ['header','footer'];5toolkit.template = 'home';6toolkit.data = {title:'Welcome to wptoolkit'};7toolkit.render(function(err,html){8 if(err)9 console.log(err);10 console.log(html);11});12var express = require('express');13var wptoolkit = require('wptoolkit');14var app = express();15var toolkit = new wptoolkit();16toolkit.partialsPath = '/path/to/partials/folder/';17toolkit.partials = ['header','footer'];18toolkit.template = 'home';19toolkit.data = {title:'Welcome to wptoolkit'};20app.use(toolkit.middleware());21app.get('/',function(req,res){22 req.wptoolkit.render(function(err,html){23 if(err)24 console.log(err);25 res.send(html);26 });27});28app.listen(3000);29console.log('Server is running on port 3000');30var express = require('express');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Hans_Solo');3page.partials(function(resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Hans_Solo');8page.partials(function(resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Hans_Solo');13page.partials(function(resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Hans_Solo');18page.partials(function(resp) {19 console.log(resp);20});21var wptools = require('wptools');22var page = wptools.page('Hans_Solo');23page.partials(function(resp) {24 console.log(resp);25});26var wptools = require('wptools');27var page = wptools.page('Hans_Solo');28page.partials(function(resp) {29 console.log(resp);30});31var wptools = require('wptools');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful