Best JavaScript code snippet using storybook-root
translator_tests.py
Source:translator_tests.py
...65 self.assertRaises(TranslatorError,66 Handlers,67 StringHandler("Main", ""),68 ((StringHandler("123", ""), StringHandler("123", "$")),))69 def test_handlers(self):70 handlers = Handlers(StringHandler("Main", "test"),71 ((StringHandler("12", "12\n"), StringHandler("123", "66\n55")),72 (StringHandler("1235", "%\n5\n334"),)))73 handlers.include("1235")74 handlers.include("12")75 handlers.include("123")76 self.assertIsInstance(iter(handlers), Handlers)77 self.assertTrue(bool(handlers))78 self.assertEqual(handlers.get_name(), "Main")79 self.assertIsNone(handlers.get_line_number())80 self.assertEqual(next(handlers), "test")81 self.assertEqual(handlers.get_name(), "Main")82 self.assertEqual(handlers.get_line_number(), 0)83 self.assertEqual(next(handlers), "%")...
delegate.js
Source:delegate.js
1// (C) Copyright 2015 Martin Dougiamas2//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.14angular.module('mm.core.courses')15/**16 * Service to interact with courses.17 *18 * @module mm.core.courses19 * @ngdoc service20 * @name $mmCoursesDelegate21 */22.provider('$mmCoursesDelegate', function() {23 var navHandlers = {},24 self = {};25 /**26 * Register a navigation handler.27 *28 * @module mm.core.courses29 * @ngdoc method30 * @name $mmCoursesDelegate#registerNavHandler31 * @param {String} addon The addon's name (mmaLabel, mmaForum, ...)32 * @param {String|Object|Function} handler Must be resolved to an object defining the following functions. Or to a function33 * returning an object defining these functions. See {@link $mmUtil#resolveObject}.34 * - isEnabled (Boolean|Promise) Whether or not the handler is enabled on a site level.35 * When using a promise, it should return a boolean.36 * - isEnabledForCourse(courseid, accessData) (Boolean|Promise) Whether or not the handler is37 * enabled on a course level. When using a promise, it should return a boolean.38 * - getController(courseid) (Object) Returns the object that will act as controller.39 * See core/components/courses/templates/list.html40 * for the list of scope variables expected.41 */42 self.registerNavHandler = function(addon, handler, priority) {43 if (typeof navHandlers[addon] !== 'undefined') {44 console.log("$mmCoursesDelegateProvider: Addon '" + navHandlers[addon].addon + "' already registered as navigation handler");45 return false;46 }47 console.log("$mmCoursesDelegateProvider: Registered addon '" + addon + "' as navibation handler.");48 navHandlers[addon] = {49 addon: addon,50 handler: handler,51 instance: undefined,52 priority: priority53 };54 return true;55 };56 self.$get = function($mmUtil, $q, $log, $mmSite, mmCoursesAccessMethods) {57 var enabledNavHandlers = {},58 coursesHandlers = {},59 self = {},60 loaded = {},61 lastUpdateHandlersStart,62 lastUpdateHandlersForCoursesStart = {};63 $log = $log.getInstance('$mmCoursesDelegate');64 /**65 * Check if addons are loaded for a certain course.66 *67 * @module mm.core.courses68 * @ngdoc method69 * @name $mmCoursesDelegate#areNavHandlersLoadedFor70 * @param {Number} courseId The course ID.71 * @return {Boolean} True if addons are loaded, false otherwise.72 */73 self.areNavHandlersLoadedFor = function(courseId) {74 return loaded[courseId];75 };76 /**77 * Clear all courses handlers.78 *79 * @module mm.core.courses80 * @ngdoc method81 * @name $mmCoursesDelegate#clearCoursesHandlers82 * @protected83 */84 self.clearCoursesHandlers = function() {85 coursesHandlers = {};86 loaded = {};87 };88 /**89 * Get the handler for a course using a certain access type.90 *91 * @param {Number} courseId The course ID.92 * @param {Boolean} refresh True if it should refresh the list.93 * @param {Object} accessData Access type and data. Default, guest, ...94 * @return {Array} Array of objects containing 'priority' and 'controller'.95 */96 function getNavHandlersForAccess(courseId, refresh, accessData) {97 if (refresh ||Â !coursesHandlers[courseId] || coursesHandlers[courseId].access.type != accessData.type) {98 coursesHandlers[courseId] = {99 access: accessData,100 handlers: []101 };102 self.updateNavHandlersForCourse(courseId, accessData);103 }104 return coursesHandlers[courseId].handlers;105 }106 /**107 * Get the handlers for a course where the user is enrolled in.108 *109 * @module mm.core.courses110 * @ngdoc method111 * @name $mmCoursesDelegate#getNavHandlersFor112 * @param {Number} courseId The course ID.113 * @param {Boolean} refresh True if it should refresh the list.114 * @return {Array} Array of objects containing 'priority' and 'controller'.115 */116 self.getNavHandlersFor = function(courseId, refresh) {117 // Default access.118 var accessData = {119 type: mmCoursesAccessMethods.default120 };121 return getNavHandlersForAccess(courseId, refresh, accessData);122 };123 /**124 * Get the handlers for a course as guest.125 *126 * @module mm.core.courses127 * @ngdoc method128 * @name $mmCoursesDelegate#getNavHandlersForGuest129 * @param {Number} courseId The course ID.130 * @param {Boolean} refresh True if it should refresh the list.131 * @return {Array} Array of objects containing 'priority' and 'controller'.132 */133 self.getNavHandlersForGuest = function(courseId, refresh) {134 // Guest access.135 var accessData = {136 type: mmCoursesAccessMethods.guest137 };138 return getNavHandlersForAccess(courseId, refresh, accessData);139 };140 /**141 * Check if a time belongs to the last update handlers call.142 * This is to handle the cases where updateNavHandlers don't finish in the same order as they're called.143 *144 * @module mm.core.courses145 * @ngdoc method146 * @name $mmCoursesDelegate#isLastUpdateCall147 * @param {Number} time Time to check.148 * @return {Boolean} True if equal, false otherwise.149 */150 self.isLastUpdateCall = function(time) {151 if (!lastUpdateHandlersStart) {152 return true;153 }154 return time == lastUpdateHandlersStart;155 };156 /**157 * Check if a time belongs to the last update handlers for course call.158 * This is to handle the cases where updateNavHandlersForCourse don't finish in the same order as they're called.159 *160 * @module mm.core.courses161 * @ngdoc method162 * @name $mmCoursesDelegate#isLastUpdateCourseCall163 * @param {Number} courseId Course ID.164 * @param {Number} time Time to check.165 * @return {Boolean} True if equal, false otherwise.166 */167 self.isLastUpdateCourseCall = function(courseId, time) {168 if (!lastUpdateHandlersForCoursesStart[courseId]) {169 return true;170 }171 return time == lastUpdateHandlersForCoursesStart[courseId];172 };173 /**174 * Update the handler for the current site.175 *176 * @module mm.core.courses177 * @ngdoc method178 * @name $mmCoursesDelegate#updateNavHandler179 * @param {String} addon The addon.180 * @param {Object} handlerInfo The handler details.181 * @param {Number} time Time this update process started.182 * @return {Promise} Resolved when enabled, rejected when not.183 * @protected184 */185 self.updateNavHandler = function(addon, handlerInfo, time) {186 var promise,187 siteId = $mmSite.getId();188 if (typeof handlerInfo.instance === 'undefined') {189 handlerInfo.instance = $mmUtil.resolveObject(handlerInfo.handler, true);190 }191 if (!$mmSite.isLoggedIn()) {192 promise = $q.reject();193 } else {194 promise = $q.when(handlerInfo.instance.isEnabled());195 }196 // Checks if the content is enabled.197 return promise.catch(function() {198 return false;199 }).then(function(enabled) {200 // Verify that this call is the last one that was started.201 // Check that site hasn't changed since the check started.202 if (self.isLastUpdateCall(time) && $mmSite.isLoggedIn() && $mmSite.getId() === siteId) {203 if (enabled) {204 enabledNavHandlers[addon] = {205 instance: handlerInfo.instance,206 priority: handlerInfo.priority207 };208 } else {209 delete enabledNavHandlers[addon];210 }211 }212 });213 };214 /**215 * Update the handlers for the current site.216 *217 * @module mm.core.courses218 * @ngdoc method219 * @name $mmCoursesDelegate#updateNavHandlers220 * @return {Promise} Resolved when done.221 * @protected222 */223 self.updateNavHandlers = function() {224 var promises = [],225 siteId = $mmSite.getId(),226 now = new Date().getTime();227 $log.debug('Updating navigation handlers for current site.');228 lastUpdateHandlersStart = now;229 // Loop over all the content handlers.230 angular.forEach(navHandlers, function(handlerInfo, addon) {231 promises.push(self.updateNavHandler(addon, handlerInfo, now));232 });233 return $q.all(promises).then(function() {234 return true;235 }, function() {236 // Never reject.237 return true;238 }).finally(function() {239 // Verify that this call is the last one that was started.240 // Check that site hasn't changed since the check started.241 if (self.isLastUpdateCall(now) && $mmSite.isLoggedIn() && $mmSite.getId() === siteId) {242 // Update handlers for all courses.243 angular.forEach(coursesHandlers, function(handler, courseId) {244 self.updateNavHandlersForCourse(parseInt(courseId), handler.access);245 });246 }247 });248 };249 /**250 * Update the handlers for a certain course.251 *252 * @module mm.core.courses253 * @ngdoc method254 * @name $mmCoursesDelegate#updateNavHandlersForCourse255 * @param {Number} courseId The course ID.256 * @param {Object} accessData Access type and data. Default, guest, ...257 * @return {Promise} Resolved when updated.258 * @protected259 */260 self.updateNavHandlersForCourse = function(courseId, accessData) {261 var promises = [],262 enabledForCourse = [],263 siteId = $mmSite.getId(),264 now = new Date().getTime();265 lastUpdateHandlersForCoursesStart[courseId] = now;266 angular.forEach(enabledNavHandlers, function(handler) {267 // Checks if the handler is enabled for the user.268 var promise = $q.when(handler.instance.isEnabledForCourse(courseId, accessData)).then(function(enabled) {269 if (enabled) {270 enabledForCourse.push(handler);271 } else {272 return $q.reject();273 }274 }).catch(function() {275 // Nothing to do here, it is not enabled for this user.276 });277 promises.push(promise);278 });279 return $q.all(promises).then(function() {280 return true;281 }).catch(function() {282 // Never fails.283 return true;284 }).finally(function() {285 // Verify that this call is the last one that was started.286 // Check that site hasn't changed since the check started.287 if (self.isLastUpdateCourseCall(courseId, now) && $mmSite.isLoggedIn() && $mmSite.getId() === siteId) {288 // Update the coursesHandlers array with the new enabled addons.289 $mmUtil.emptyArray(coursesHandlers[courseId].handlers);290 angular.forEach(enabledForCourse, function(handler) {291 coursesHandlers[courseId].handlers.push({292 controller: handler.instance.getController(courseId),293 priority: handler.priority294 });295 });296 loaded[courseId] = true;297 }298 });299 };300 return self;301 };302 return self;...
handlers.js
Source:handlers.js
1// Copyright 2014 Cognitect. All Rights Reserved.2//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.14goog.provide("com.cognitect.transit.handlers");15goog.require("com.cognitect.transit.util");16goog.require("com.cognitect.transit.types");17goog.require("goog.math.Long");18goog.scope(function () {19 var handlers = com.cognitect.transit.handlers,20 util = com.cognitect.transit.util,21 types = com.cognitect.transit.types,22 Long = goog.math.Long;23 handlers.ctorGuid = 0;24 /**25 * @const26 * @type {string}27 */28 handlers.ctorGuidProperty = "transit$guid$" + util.randomUUID();29 handlers.typeTag = function (ctor) {30 if (ctor == null) {31 return "null";32 } else if (ctor === String) {33 return "string";34 } else if (ctor === Boolean) {35 return "boolean";36 } else if (ctor === Number) {37 return "number";38 } else if (ctor === Array) {39 return "array";40 } else if (ctor === Object) {41 return "map";42 } else {43 var tag = ctor[handlers.ctorGuidProperty];44 if (tag == null) {45 if (typeof Object.defineProperty != "undefined") {46 tag = ++handlers.ctorGuid;47 Object.defineProperty(ctor, handlers.ctorGuidProperty, {48 value: tag,49 enumerable: false50 });51 } else {52 ctor[handlers.ctorGuidProperty] = tag = ++handlers.ctorGuid;53 }54 }55 return tag;56 }57 };58 handlers.constructor = function (x) {59 if (x == null) {60 return null;61 } else {62 return x.constructor;63 }64 };65 handlers.padZeros = function (n, m) {66 var s = n.toString();67 for (var i = s.length; i < m; i++) {68 s = "0" + s;69 }70 return s;71 };72 handlers.stringableKeys = function (m) {73 var stringable = false,74 ks = util.objectKeys(m);75 for (var i = 0; i < ks.length; i++) {76 }77 return true;78 };79 /**80 * @constructor81 */82 handlers.NilHandler = function Transit$NilHandler() {83 };84 handlers.NilHandler.prototype.tag = function (v) {85 return "_";86 };87 handlers.NilHandler.prototype.rep = function (v) {88 return null;89 };90 handlers.NilHandler.prototype.stringRep = function (v) {91 return "null";92 };93 /**94 * @constructor95 */96 handlers.StringHandler = function Transit$StringHandler() {97 };98 handlers.StringHandler.prototype.tag = function (v) {99 return "s";100 };101 handlers.StringHandler.prototype.rep = function (v) {102 return v;103 };104 handlers.StringHandler.prototype.stringRep = function (v) {105 return v;106 };107 /**108 * @constructor109 */110 handlers.NumberHandler = function Transit$NumberHandler() {111 };112 handlers.NumberHandler.prototype.tag = function (v) {113 return "i";114 };115 handlers.NumberHandler.prototype.rep = function (v) {116 return v;117 };118 handlers.NumberHandler.prototype.stringRep = function (v) {119 return v.toString();120 };121 /**122 * @constructor123 */124 handlers.IntegerHandler = function Transit$IntegerHandler() {125 };126 handlers.IntegerHandler.prototype.tag = function (v) {127 return "i";128 };129 handlers.IntegerHandler.prototype.rep = function (v) {130 return v.toString();131 };132 handlers.IntegerHandler.prototype.stringRep = function (v) {133 return v.toString();134 };135 /**136 * @constructor137 */138 handlers.BooleanHandler = function Transit$BooleanHandler() {139 };140 handlers.BooleanHandler.prototype.tag = function (v) {141 return "?";142 };143 handlers.BooleanHandler.prototype.rep = function (v) {144 return v;145 };146 handlers.BooleanHandler.prototype.stringRep = function (v) {147 return v.toString();148 };149 /**150 * @constructor151 */152 handlers.ArrayHandler = function Transit$ArrayHandler() {153 };154 handlers.ArrayHandler.prototype.tag = function (v) {155 return "array";156 };157 handlers.ArrayHandler.prototype.rep = function (v) {158 return v;159 };160 handlers.ArrayHandler.prototype.stringRep = function (v) {161 return null;162 };163 /**164 * @constructor165 */166 handlers.MapHandler = function Transit$MapHandler() {167 };168 handlers.MapHandler.prototype.tag = function (v) {169 return "map";170 };171 handlers.MapHandler.prototype.rep = function (v) {172 return v;173 };174 handlers.MapHandler.prototype.stringRep = function (v) {175 return null;176 };177 /**178 * @constructor179 */180 handlers.VerboseDateHandler = function Transit$VerboseDateHandler() {181 };182 handlers.VerboseDateHandler.prototype.tag = function (v) {183 return "t";184 };185 handlers.VerboseDateHandler.prototype.rep = function (v) {186 return v.getUTCFullYear() + "-" + handlers.padZeros(v.getUTCMonth() + 1, 2) + "-" +187 handlers.padZeros(v.getUTCDate(), 2) + "T" + handlers.padZeros(v.getUTCHours(), 2) + ":" +188 handlers.padZeros(v.getUTCMinutes(), 2) + ":" + handlers.padZeros(v.getUTCSeconds(), 2) + "." +189 handlers.padZeros(v.getUTCMilliseconds(), 3) + "Z";190 };191 handlers.VerboseDateHandler.prototype.stringRep = function (v, h) {192 return h.rep(v);193 };194 /**195 * @constructor196 */197 handlers.DateHandler = function Transit$DateHandler() {198 };199 handlers.DateHandler.prototype.tag = function (v) {200 return "m";201 };202 handlers.DateHandler.prototype.rep = function (v) {203 return v.valueOf();204 };205 handlers.DateHandler.prototype.stringRep = function (v) {206 return v.valueOf().toString();207 };208 handlers.DateHandler.prototype.getVerboseHandler = function (v) {209 return new handlers.VerboseDateHandler();210 };211 /**212 * @constructor213 */214 handlers.UUIDHandler = function Transit$UUIDHandler() {215 };216 handlers.UUIDHandler.prototype.tag = function (v) {217 return "u";218 };219 handlers.UUIDHandler.prototype.rep = function (v) {220 return v.toString();221 };222 handlers.UUIDHandler.prototype.stringRep = function (v) {223 return v.toString();224 };225 /**226 * @constructor227 */228 handlers.KeywordHandler = function Transit$KeywordHandler() {229 };230 handlers.KeywordHandler.prototype.tag = function (v) {231 return ":";232 };233 handlers.KeywordHandler.prototype.rep = function (v) {234 return v._name;235 }; // NOTE: should be fqn236 handlers.KeywordHandler.prototype.stringRep = function (v, h) {237 return h.rep(v);238 };239 /**240 * @constructor241 */242 handlers.SymbolHandler = function Transit$SymbolHandler() {243 };244 handlers.SymbolHandler.prototype.tag = function (v) {245 return "$";246 };247 handlers.SymbolHandler.prototype.rep = function (v) {248 return v._name;249 }; // NOTE: should be str250 handlers.SymbolHandler.prototype.stringRep = function (v, h) {251 return h.rep(v);252 };253 /**254 * @constructor255 */256 handlers.TaggedHandler = function Transit$TaggedHandler() {257 };258 handlers.TaggedHandler.prototype.tag = function (v) {259 return v.tag;260 };261 handlers.TaggedHandler.prototype.rep = function (v) {262 return v.rep;263 };264 handlers.TaggedHandler.prototype.stringRep = function (v, h) {265 return null;266 };267 /**268 * @constructor269 */270 handlers.TransitSetHandler = function Transit$TransitSetHandler() {271 };272 handlers.TransitSetHandler.prototype.tag = function (v) {273 return "set";274 };275 handlers.TransitSetHandler.prototype.rep = function (v) {276 var arr = [];277 v.forEach(function (key, set) {278 arr.push(key);279 });280 return types.taggedValue("array", arr);281 };282 handlers.TransitSetHandler.prototype.stringRep = function (v, h) {283 return null;284 };285 /**286 * @constructor287 */288 handlers.TransitArrayMapHandler = function Transit$ArrayMapHandler() {289 };290 handlers.TransitArrayMapHandler.prototype.tag = function (v) {291 return "map";292 };293 handlers.TransitArrayMapHandler.prototype.rep = function (v) {294 return v;295 };296 handlers.TransitArrayMapHandler.prototype.stringRep = function (v, h) {297 return null;298 };299 /**300 * @constructor301 */302 handlers.TransitMapHandler = function Transit$MapHandler() {303 };304 handlers.TransitMapHandler.prototype.tag = function (v) {305 return "map";306 };307 handlers.TransitMapHandler.prototype.rep = function (v) {308 return v;309 };310 handlers.TransitMapHandler.prototype.stringRep = function (v, h) {311 return null;312 };313 /**314 * @constructor315 */316 handlers.BufferHandler = function Transit$BufferHandler() {317 };318 handlers.BufferHandler.prototype.tag = function (v) {319 return "b";320 };321 handlers.BufferHandler.prototype.rep = function (v) {322 return v.toString("base64");323 };324 handlers.BufferHandler.prototype.stringRep = function (v, h) {325 return null;326 };327 /**328 * @constructor329 */330 handlers.Uint8ArrayHandler = function Transit$Uint8ArrayHandler() {331 };332 handlers.Uint8ArrayHandler.prototype.tag = function (v) {333 return "b";334 };335 handlers.Uint8ArrayHandler.prototype.rep = function (v) {336 return util.Uint8ToBase64(v);337 };338 handlers.Uint8ArrayHandler.prototype.stringRep = function (v, h) {339 return null;340 };341 handlers.defaultHandlers = function (hs) {342 hs.set(null, new handlers.NilHandler());343 hs.set(String, new handlers.StringHandler());344 hs.set(Number, new handlers.NumberHandler());345 hs.set(Long, new handlers.IntegerHandler());346 hs.set(Boolean, new handlers.BooleanHandler());347 hs.set(Array, new handlers.ArrayHandler());348 hs.set(Object, new handlers.MapHandler());349 hs.set(Date, new handlers.DateHandler());350 hs.set(types.UUID, new handlers.UUIDHandler());351 hs.set(types.Keyword, new handlers.KeywordHandler());352 hs.set(types.Symbol, new handlers.SymbolHandler());353 hs.set(types.TaggedValue, new handlers.TaggedHandler());354 hs.set(types.TransitSet, new handlers.TransitSetHandler());355 hs.set(types.TransitArrayMap, new handlers.TransitArrayMapHandler());356 hs.set(types.TransitMap, new handlers.TransitMapHandler());357 if (typeof Buffer != "undefined") {358 hs.set(Buffer, new handlers.BufferHandler());359 }360 if (typeof Uint8Array != "undefined") {361 hs.set(Uint8Array, new handlers.Uint8ArrayHandler());362 }363 return hs;364 };365 /**366 * @constructor367 */368 handlers.Handlers = function Transit$Handlers() {369 this.handlers = {};370 handlers.defaultHandlers(this);371 };372 handlers.Handlers.prototype.get = function (ctor) {373 var h = null;374 if (typeof ctor === "string") {375 h = this.handlers[ctor];376 } else {377 h = this.handlers[handlers.typeTag(ctor)];378 }379 if (h != null) {380 return h;381 } else {382 return this.handlers["default"];383 }384 };385 handlers.Handlers.prototype["get"] = handlers.Handlers.prototype.get;386 handlers.validTag = function (tag) {387 switch (tag) {388 case "null":389 case "string":390 case "boolean":391 case "number":392 case "array":393 case "map":394 return false;395 break;396 }397 return true;398 };399 handlers.Handlers.prototype.set = function (ctor, handler) {400 if (typeof ctor === "string" && handlers.validTag(ctor)) {401 this.handlers[ctor] = handler;402 } else {403 this.handlers[handlers.typeTag(ctor)] = handler;404 }405 };...
handler_options.js
Source:handler_options.js
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/**5 * @typedef {{6 * default_handler: number,7 * handlers: Array,8 * has_policy_recommendations: boolean,9 * is_default_handler_set_by_user: boolean,10 * protocol: string11 * }}12 * @see chrome/browser/ui/webui/options/handler_options_handler.cc13 */14var Handlers;15cr.define('options', function() {16 /** @const */ var Page = cr.ui.pageManager.Page;17 /** @const */ var PageManager = cr.ui.pageManager.PageManager;18 /////////////////////////////////////////////////////////////////////////////19 // HandlerOptions class:20 /**21 * Encapsulated handling of handler options page.22 * @constructor23 * @extends {cr.ui.pageManager.Page}24 */25 function HandlerOptions() {26 this.activeNavTab = null;27 Page.call(this,28 'handlers',29 loadTimeData.getString('handlersPageTabTitle'),30 'handler-options');31 }32 cr.addSingletonGetter(HandlerOptions);33 HandlerOptions.prototype = {34 __proto__: Page.prototype,35 /**36 * The handlers list.37 * @type {options.HandlersList}38 * @private39 */40 handlersList_: null,41 /** @override */42 initializePage: function() {43 Page.prototype.initializePage.call(this);44 this.createHandlersList_();45 $('handler-options-overlay-confirm').onclick =46 PageManager.closeOverlay.bind(PageManager);47 },48 /**49 * Creates, decorates and initializes the handlers list.50 * @private51 */52 createHandlersList_: function() {53 var handlersList = $('handlers-list');54 options.HandlersList.decorate(handlersList);55 this.handlersList_ = assertInstanceof(handlersList, options.HandlersList);56 this.handlersList_.autoExpands = true;57 var ignoredHandlersList = $('ignored-handlers-list');58 options.IgnoredHandlersList.decorate(ignoredHandlersList);59 this.ignoredHandlersList_ = assertInstanceof(ignoredHandlersList,60 options.IgnoredHandlersList);61 this.ignoredHandlersList_.autoExpands = true;62 },63 };64 /**65 * Sets the list of handlers shown by the view.66 * @param {Array<Handlers>} handlers Handlers to be shown in the view.67 */68 HandlerOptions.setHandlers = function(handlers) {69 $('handlers-list').setHandlers(handlers);70 };71 /**72 * Sets the list of ignored handlers shown by the view.73 * @param {Array} handlers Handlers to be shown in the view.74 */75 HandlerOptions.setIgnoredHandlers = function(handlers) {76 $('ignored-handlers-section').hidden = handlers.length == 0;77 $('ignored-handlers-list').setHandlers(handlers);78 };79 return {80 HandlerOptions: HandlerOptions81 };...
urls.py
Source:urls.py
1# -*- coding: utf-8 -*-2#3# Copyright(c) 2010 poweredsites.org4#5# Licensed under the Apache License, Version 2.0 (the "License"); you may6# not use this file except in compliance with the License. You may obtain7# a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the14# License for the specific language governing permissions and limitations15# under the License.16from poweredsites.libs.handler import ErrorHandler17handlers = []18sub_handlers = []19ui_modules = {}20from poweredsites.handlers import admin, blog, front, \21 help, project, site, user22handlers.extend(front.handlers)23handlers.extend(user.handlers)24handlers.extend(site.handlers)25handlers.extend(project.handlers)26handlers.extend(help.handlers)27# Append default 404 handler, and make sure it is the last one.28handlers.append((r".*", ErrorHandler))29sub_handlers.append(site.sub_handlers)30sub_handlers.append(blog.sub_handlers)31sub_handlers.append(admin.sub_handlers)32# wildcat subdomain handler for project should be the last one.33sub_handlers.append(project.sub_handlers)34ui_modules.update(front.ui_modules)35ui_modules.update(site.ui_modules)36ui_modules.update(project.ui_modules)37ui_modules.update(blog.ui_modules)38for sh in sub_handlers:...
main.py
Source:main.py
1import handlers2from config import *3cmds = {4 "help": handlers.helper,5 "помоÑÑ": handlers.helper,6 "командÑ": handlers.helper,7 "пÑоÑилÑ": handlers.profileInfo,8 "ник": handlers.nickname,9 "никнейм": handlers.nickname,10 "оÑновнÑе": handlers.helpMain,11 "игÑовÑе": handlers.helpGames,12 "ÑазвлекаÑелÑнÑе": handlers.helpFun,13 "клановÑе": handlers.helpClan,14 "банк": handlers.bankInfo,15 "баланÑ": handlers.balance,16 "пеÑедаÑÑ": handlers.give,17 "ÑабоÑа": handlers.jobInfo,18 "ÑабоÑÑ": handlers.jobList,19 "бонÑÑ": handlers.bonus,20 "ÑаÑ": handlers.magicBall,21 "ÑанÑ": handlers.chance22}23@bot.message_handler(content_types=['text'])24def onMessage(message):25 if db.inDb(message.from_user.id):26 if message.text.lower().split()[0] not in cmds:27 handlers.noCom(message)28 for name, func in cmds.items():29 if message.text.lower().split()[0] == name:30 func(message)31 return32 else:33 handlers.reg(message)...
app.ts
Source:app.ts
1import * as Handlers from './bot/handlers'2import bot from "./bot/getBot";3try {4 bot.onText(Handlers.helpCommand, Handlers.handleHelp);5 bot.onText(Handlers.updateHousingAreaCommand, Handlers.handleUpdateHousingArea);6 bot.onText(Handlers.updateRentCommand, Handlers.handleUpdateRent);7 bot.onText(Handlers.updateRoomsCommand, Handlers.handleUpdateRooms);8 bot.onText(Handlers.updateSearchAreaCommand, Handlers.handleUpdateSearchAreaCommand);9 bot.onText(Handlers.updateHomeTypesCommand, Handlers.handleUpdateHomeTypes);10 bot.onText(Handlers.updateSearchFrequency, Handlers.handleUpdateSearchFrequency);11 bot.onText(Handlers.getFiltersCommand, Handlers.handleGetFilters);12 bot.onText(Handlers.getJobStateCommand, Handlers.handleGetJobState);13 bot.onText(Handlers.startJobCommand, Handlers.handleStartJob);14 bot.onText(Handlers.stopJobCommand, Handlers.handleStopJob);15 bot.onText(Handlers.resetJobCommand, Handlers.handleResetJob);16 bot.onText(Handlers.hardResetCommand, Handlers.handleHardResetJob);17 bot.onText(Handlers.echoCommand, Handlers.handleEcho);18 console.log('Brostad is born again.')19} catch(e) {20 console.error('Something went wrong while reviving brostad. Hes dead jim!')21 console.error(e);...
Using AI Code Generation
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { withRootDecorator } from 'storybook-root-decorator';4import { withKnobs, text, boolean, number } from '@storybook/addon-knobs';5import { action } from '@storybook/addon-actions';6import { withInfo } from '@storybook/addon-info';7import Button from './Button';8const stories = storiesOf('Button', module);9stories.addDecorator(withRootDecorator());10stories.addDecorator(withKnobs);11stories.add(12 withInfo()(() => (13 onClick={action('clicked')}14 disabled={boolean('Disabled', false)}15 size={number('Size', 2)}16 {text('Label', 'Hello Button')}17);18import { configure, addDecorator } from '@storybook/react';19import { withRootDecorator } from 'storybook-root-decorator';20addDecorator(withRootDecorator());21configure(require.context('../src', true, /\.stories\.js$/), module);22import { addDecorator } from '@storybook/react';23import { withRootDecorator } from 'storybook-root-decorator';24addDecorator(withRootDecorator());25const path = require('path');26module.exports = async ({ config, mode }) => {27 config.module.rules.push({28 test: /\.(ts|tsx)$/,29 include: path.resolve(__dirname, '../src'),30 {31 loader: require.resolve('ts-loader'),32 },33 {34 loader: require.resolve('react-docgen-typescript-loader'),35 },36 });37 config.resolve.extensions.push('.ts', '.tsx');38 return config;39};40import '@storybook/addon-actions/register';41import '@storybook/addon-knobs/register';42import '@storybook/addon-info/register';43import { addons } from '@storybook/addons';44import { create } from '@storybook/theming/create';45import { themes } from '@storybook/theming';46addons.setConfig({47 theme: create({
Using AI Code Generation
1import { addDecorator } from '@storybook/react';2import { withRootDecorator } from 'storybook-root-decorator';3addDecorator(withRootDecorator());4import { addDecorator } from '@storybook/react';5import { withRootDecorator } from 'storybook-root-decorator';6addDecorator(withRootDecorator());7import { addDecorator } from '@storybook/react';8import { withRootDecorator } from 'storybook-root-decorator';9addDecorator(withRootDecorator());10module.exports = {11 webpackFinal: async config => {12 config.module.rules.push({13 loaders: [require.resolve('@storybook/source-loader')],14 });15 return config;16 },17 core: {18 },19 typescript: {20 checkOptions: {}21 },22 babel: async options => ({23 }),24 features: {25 }26};27import { addons } from '@storybook/addons';28import { withRootDecorator } from 'storybook-root-decorator';29addons.setConfig({30 theme: withRootDecorator()31});32import { addDecorator } from '@storybook/react';33import { withRootDecorator } from 'storybook-root-decorator';34addDecorator(withRootDecorator());35const path = require('path');36module.exports = ({ config }) => {37 config.resolve.alias = {38 '@': path.resolve(__dirname, '../src')39 };40 return config;41};
Using AI Code Generation
1import {addDecorator} from '@storybook/react';2import {withRootDecorator} from 'storybook-root-decorator';3import {handlers} from 'storybook-root-decorator';4addDecorator(withRootDecorator());5handlers.add('click', (event) => {6 if (event.target.matches('button')) {7 console.log('button clicked');8 }9});10handlers.remove('click');11handlers.removeAll();12handlers.removeAll({except: ['click']});13handlers.removeAll({only: ['click']});14handlers.removeAll({except: ['click'], only: ['click']});15handlers.removeAll({except: ['click', 'mouseover']});16handlers.removeAll({only: ['click', 'mouseover']});17handlers.removeAll({except: ['click', 'mouseover'], only: ['click', 'mouseover']});18handlers.removeAll({only: ['click', 'mouseover'], except: ['click', 'mouseover']});19handlers.removeAll({except: ['click'], only: ['mouseover']});20handlers.removeAll({except: ['mouseover'], only: ['click']});21handlers.removeAll({only: ['click'], except: ['mouseover']});22handlers.removeAll({only: ['mouseover'], except: ['click']});23handlers.removeAll({except: ['click', 'mouseover'], only: ['click']});24handlers.removeAll({except: ['click', 'mouseover'], only: ['mouseover']});25handlers.removeAll({only: ['click'], except: ['click', 'mouseover']});26handlers.removeAll({only: ['mouseover'], except: ['click', 'mouseover']});27handlers.removeAll({except: ['click'], only: ['click', 'mouseover']});28handlers.removeAll({except: ['mouseover'], only: ['click', 'mouseover']});29handlers.removeAll({only: ['click', 'mouseover'], except: ['click']});30handlers.removeAll({only: ['click', 'mouseover'], except: ['mouseover']});31handlers.removeAll({except: ['click', 'mouseover'], only: ['click', 'mouseover']});32handlers.removeAll({only: ['click', 'mouseover'], except: ['click', 'mouseover']});33handlers.removeAll({except: ['click', 'mouseover'], only: ['click', 'mouseover']});34handlers.removeAll({only: ['click', 'mouseover'], except: ['click', 'mouseover']});35handlers.removeAll({except: ['click', 'mouseover'], only: ['click', 'mouseover']});36handlers.removeAll({only: ['click', 'mouseover'], except: ['click', 'mouseover']});37handlers.removeAll({except: ['click',
Using AI Code Generation
1import { storiesOf } from '@storybook/react';2import { withHandlers } from 'storybook-addon-handlers';3storiesOf('Addons|Handlers', module)4 .addDecorator(withHandlers({5 onClick: () => console.log('clicked'),6 }))7 .add('with handler', () => <button onClick={handlers.onClick}>Click me!</button>);8import React from 'react';9import { shallow } from 'enzyme';10import { withHandlers } from 'storybook-addon-handlers';11describe('Addons|Handlers', () => {12 it('should call handler', () => {13 const onClick = jest.fn();14 const wrapper = shallow(withHandlers({ onClick })(() => <button onClick={handlers.onClick}>Click me!</button>));15 wrapper.find('button').simulate('click');16 expect(onClick).toHaveBeenCalled();17 });18});19import { storiesOf } from '@storybook/react';20import { withHandlers } from 'storybook-addon-handlers';21storiesOf('Addons|Handlers', module)22 .addDecorator(withHandlers({23 onClick: () => console.log('clicked'),24 }))25 .add('with handler', () => <button onClick={handlers.onClick}>Click me!</button>);26import React from 'react';27import { mount } from 'enzyme';28import { withHandlers } from 'storybook-addon-handlers';29describe('Addons|Handlers', () => {30 it('should call handler', () => {31 const onClick = jest.fn();32 const wrapper = mount(withHandlers({ onClick })(() => <button onClick={handlers.onClick}>Click me!</button>));33 wrapper.find('button').simulate('click');34 expect(onClick).toHaveBeenCalled();35 });36});37import { storiesOf } from '@storybook/react';38import { withHandlers } from 'storybook-addon-handlers';39storiesOf('Addons|Handlers', module)40 .addDecorator(withHandlers({41 onClick: () => console.log('clicked'),42 }))43 .add('with handler', () => <button onClick={handlers.onClick}>Click me!</button>);
Using AI Code Generation
1import {handlers} from 'storybook-root';2handlers.get('/api/v1/users', (req, res) => {3 res.send({status: 'OK'});4});5import {handlers} from 'storybook-root';6handlers.get('/api/v1/users', (req, res) => {7 res.send({status: 'OK'});8});9import {handlers} from 'storybook-root';10handlers.get('/api/v1/users', (req, res) => {11 res.send({status: 'OK'});12});13import {handlers} from 'storybook-root';14handlers.get('/api/v1/users', (req, res) => {15 res.send({status: 'OK'});16});17import {handlers} from 'storybook-root';18handlers.get('/api/v1/users', (req, res) => {19 res.send({status: 'OK'});20});21import {handlers} from 'storybook-root';22handlers.get('/api/v1/users', (req, res) => {23 res.send({status: 'OK'});24});25import {handlers} from 'storybook-root';26handlers.get('/api/v1/users', (req, res) => {27 res.send({status: 'OK'});28});29import {handlers} from 'storybook-root';30handlers.get('/api/v1/users', (req, res) => {31 res.send({status: 'OK'});32});33import {handlers} from 'storybook-root';34handlers.get('/api/v1/users', (req, res) => {35 res.send({status: 'OK'});36});37import {handlers} from 'storybook-root';38handlers.get('/api/v1/users', (req, res) => {39 res.send({status: 'OK'});40});41import {handlers} from 'storybook-root';42handlers.get('/api/v1/users', (req, res) => {43 res.send({status: 'OK'});44});45import {handlers}
Using AI Code Generation
1import {handlers} from 'storybook-root';2handlers.add('myHandler', (args, callback) => {3 callback();4});5import {handlers} from 'storybook-root';6export default {7 parameters: {8 handlers: {9 myHandler: {10 args: {foo: 'bar'},11 callback: () => {12 }13 }14 }15 }16}17import {handlers} from 'storybook-root';18handlers.add('myHandler', (args, callback) => {19 callback();20});21import {handlers} from 'storybook-root';22export default {23 parameters: {24 handlers: {25 myHandler: {26 args: {foo: 'bar'},27 callback: () => {28 }29 }30 }31 }32}33MIT © [Rafael Lima](
Using AI Code Generation
1import {getStorybookRootInstance} from 'storybook-root';2import StorybookRoot from 'storybook-root';3const storybookRoot = getStorybookRootInstance();4storybookRoot.handlers.get('myHandler')();5import StorybookRoot from 'storybook-root';6const storybookRoot = new StorybookRoot();7export default storybookRoot;8export const getStorybookRootInstance = () => storybookRoot;9import StorybookRoot from 'storybook-root';10const storybookRoot = new StorybookRoot();11export default storybookRoot;12export const getStorybookRootInstance = () => storybookRoot;13import storybookRoot from 'storybook-root';14export default storybookRoot;15export const getStorybookRootInstance = () => storybookRoot;16import StorybookRoot from 'storybook-root';17const storybookRoot = new StorybookRoot();18export default storybookRoot;19export const getStorybookRootInstance = () => storybookRoot;20import StorybookRoot from 'storybook-root';21const storybookRoot = new StorybookRoot();22export default storybookRoot;23export const getStorybookRootInstance = () => storybookRoot;24import StorybookRoot from 'storybook-root';25const storybookRoot = new StorybookRoot();26export default storybookRoot;27export const getStorybookRootInstance = () => storybookRoot;28import StorybookRoot from 'storybook-root';29const storybookRoot = new StorybookRoot();30export default storybookRoot;31export const getStorybookRootInstance = () => storybookRoot;32import StorybookRoot from 'storybook-root';33const storybookRoot = new StorybookRoot();34export default storybookRoot;35export const getStorybookRootInstance = () => storybookRoot;36import StorybookRoot from 'storybook-root';37const storybookRoot = new StorybookRoot();38export default storybookRoot;39export const getStorybookRootInstance = () => storybookRoot;40import StorybookRoot from 'storybook-root';41const storybookRoot = new StorybookRoot();42export default storybookRoot;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!