How to use FindClasses method in redwood

Best JavaScript code snippet using redwood

Class.js

Source:Class.js Github

copy

Full Screen

1/* ************************************************************************2 qooxdoo - the new era of web development3 http://qooxdoo.org4 Copyright:5 2004-2008 1&1 Internet AG, Germany, http://www.1und1.de6 2018 Zenesis Limited, http://www.zenesis.com7 License:8 MIT: https://opensource.org/licenses/MIT9 See the LICENSE file in the project's top-level directory for details.10 Authors:11 * John Spackman (johnspackman)12 * Fabian Jakobs (fjakobs)13************************************************************************ */14/**15 * This Class wraps the access to the documentation data of classes.16 */17qx.Class.define("qxl.apiviewer.dao.Class", {18 extend: qxl.apiviewer.dao.Node,19 /**20 * @param className21 */22 construct(className) {23 this.base(arguments);24 this._className = className;25 this._package = qxl.apiviewer.dao.Package.getParentPackage(className);26 this._package.addClass(this);27 },28 members: {29 _package: null,30 _construct: null,31 _destruct: null,32 _defer: null,33 _staticMethods: null,34 _constants: null,35 _members: null,36 _mixinMembers: null,37 _properties: null,38 _mixinProperties: null,39 _events: null,40 _mixinEvents: null,41 _superClass: null,42 _superInterfaces: null,43 _superMixins: null,44 _mixins: null,45 _loadingPromise: null,46 _loaded: false,47 __url: null,48 /**49 * retrieves the meta file name + path50 */51 getMetaFile() {52 return this.__url;53 },54 /**55 * Loads the class56 *57 * @return {Promise}58 */59 load() {60 if (this._loadingPromise) {61 return this._loadingPromise;62 }63 var url = (this.__url =64 qxl.apiviewer.ClassLoader.getBaseUri() +65 this._className.replace(/\./g, "/") +66 ".json");67 return (this._loadingPromise = qxl.apiviewer.RequestUtil.get(url)68 .then((content) => {69 /* eslint-disable-next-line no-eval */70 var meta = eval("(" + content + ")");71 return this._initMeta(meta).then(() => {72 this._loaded = true;73 return this;74 });75 })76 .catch((e) => {77 this.error("Couldn't load file: " + url + " " + e.message);78 }));79 },80 isLoaded() {81 return this._loaded;82 },83 /**84 * Loads meta data, including super classes/interfaces/mixins85 * @param meta86 * @return {qx.Promise}87 */88 _initMeta(meta) {89 this.base(arguments, meta);90 this._jsdoc = meta.clazz.jsdoc || {};91 this._construct = meta.construct92 ? [new qxl.apiviewer.dao.Method(meta.construct, this, "construct")]93 : [];94 this._destruct = meta.destruct95 ? [new qxl.apiviewer.dao.Method(meta.destruct, this, "destruct")]96 : [];97 this._defer = meta.defer98 ? [new qxl.apiviewer.dao.Method(meta.defer, this, "defer")]99 : [];100 this._staticMethods = [];101 this._constants = [];102 if (meta.statics) {103 for (let name in meta.statics) {104 let data = meta.statics[name];105 if (data.type == "variable") {106 this._constants.push(107 new qxl.apiviewer.dao.Constant(data, this, name)108 );109 } else {110 this._staticMethods.push(111 new qxl.apiviewer.dao.Method(data, this, name)112 );113 }114 }115 }116 this._members = [];117 this._mixinMembers = [];118 if (meta.members) {119 for (let name in meta.members) {120 let data = meta.members[name];121 if (data.type == "function") {122 let obj = new qxl.apiviewer.dao.Method(data, this, name);123 if (data.mixin) {124 this._mixinMembers.push(obj);125 } else {126 this._members.push(obj);127 }128 }129 }130 }131 this._events = [];132 this._mixinEvents = [];133 if (meta.events) {134 for (let name in meta.events) {135 let data = meta.events[name];136 let obj = new qxl.apiviewer.dao.Event(data, this);137 if (data.mixin) {138 this._mixinEvents.push(obj);139 } else {140 this._events.push(obj);141 }142 }143 }144 this._properties = [];145 this._mixinProperties = [];146 if (meta.properties) {147 for (let name in meta.properties) {148 let data = meta.properties[name];149 let obj = new qxl.apiviewer.dao.Property(data, this, name);150 if (data.mixin) {151 this._mixinProperties.push(obj);152 } else {153 this._properties.push(obj);154 }155 let evt = obj.getEvent();156 if (evt) {157 let objE = new qxl.apiviewer.dao.Event(158 {159 location: obj.location,160 name: evt,161 type: "qx.event.type.Data",162 jsdoc: {163 "@description": [164 {165 name: "@description",166 body: `Fired on change of the property {@link ${167 data.overriddenFrom || ""168 }#${name} ${name}}`,169 },170 ],171 },172 },173 this174 );175 if (data.mixin) {176 this._mixinEvents.push(objE);177 } else {178 this._events.push(objE);179 }180 }181 }182 }183 this._childControls = [];184 let arr = this._jsdoc["@childControl"];185 if (arr) {186 arr.forEach((elem) => {187 this._childControls.push(188 new qxl.apiviewer.dao.ChildControl(elem, this)189 );190 });191 }192 var all = [];193 /**194 * @param tmp195 */196 function findClasses(tmp) {197 let p = qxl.apiviewer.dao.Class.findClasses(tmp);198 return p.then((classes) => {199 classes.forEach((item) => {200 all.push(item);201 });202 return classes;203 });204 }205 this._superClass = null;206 this._superInterfaces = [];207 this._superMixins = [];208 if (this._meta.type == "interface") {209 all.push(210 findClasses(meta.superClass).then(211 (arr) => (this._superInterfaces = arr)212 )213 );214 } else if (this._meta.type == "mixin") {215 all.push(216 findClasses(meta.superClass).then((arr) => (this._superMixins = arr))217 );218 } else {219 all.push(220 findClasses(meta.superClass).then(221 (arr) => (this._superClass = arr[0] || null)222 )223 );224 }225 this._interfaces = [];226 findClasses(meta.interfaces).then((arr) => (this._interfaces = arr));227 this._mixins = [];228 findClasses(meta.mixins).then((arr) => (this._mixins = arr));229 return qx.Promise.all(all);230 },231 getPackage() {232 return this._package;233 },234 /**235 * Get the name of the class.236 *237 * @return {String} name of the class238 */239 getName() {240 return this._className;241 },242 /**243 * Get the full name of the class, including the package name.244 *245 * @return {String} full name of the class246 */247 getFullName() {248 return this._className;249 },250 /**251 * Get the package name of the class.252 *253 * @return {String} package name of the class254 */255 getPackageName() {256 return this._package.getFullName();257 },258 /**259 * Get type of the class. Valid types are "class", "interface" and "mixin".260 *261 * @return {String} The type of the class. Valid types are "class",262 * "interface" and "mixin".263 */264 getType() {265 return this._meta.type;266 },267 /**268 * Get whether the class is abstract.269 *270 * @return {Boolean} Whether the class is abstract.271 */272 isAbstract() {273 return this._meta.isAbstract || false;274 },275 /**276 * Get whether the class is a static class.277 *278 * @return {Boolean} Whether the class is static.279 */280 isStatic() {281 return this._meta.isStatic || false;282 },283 /**284 * Get whether the class is a singleton.285 *286 * @return {Boolean} Whether the class is a singleton.287 */288 isSingleton() {289 return this._meta.isSingleton || false;290 },291 /**292 * Get the super class of the class.293 *294 * @return {qxl.apiviewer.dao.Class} The super class of the class.295 */296 getSuperClass() {297 return this._superClass;298 },299 /**300 * Get the direct child classes of the class.301 *302 * @return {qx.Promise<qxl.apiviewer.dao.Class[]>} A list of direct child classes of the303 * class.304 */305 getChildClasses() {306 if (!this._childClassesPromise) {307 if (this._meta.type == "class") {308 this._childClassesPromise = qxl.apiviewer.dao.Class.findClasses(309 this._meta.descendants310 );311 } else {312 this._childClassesPromise = qx.Promise.resolve([]);313 }314 }315 return this._childClassesPromise;316 },317 /**318 * Get all interfaces declared at the class declaration.319 *320 * @return {qxl.apiviewer.dao.Class[]} All interfaces declared at the class321 * declaration.322 */323 getInterfaces() {324 return this._interfaces;325 },326 /**327 * Get all super interfaces. (Only for interfaces)328 *329 * @return {qxl.apiviewer.dao.Class[]} All super interfaces.330 */331 getSuperInterfaces() {332 return this._superInterfaces;333 },334 /**335 * Get all mixins declared at the class declaration.336 *337 * @return {qxl.apiviewer.dao.Class[]} All mixins declared at the class338 * declaration.339 */340 getMixins() {341 return this._mixins;342 },343 /**344 * Get all super mixins. (Only for mixins)345 *346 * @return {qxl.apiviewer.dao.Class[]} All super mixins.347 */348 getSuperMixins() {349 return this._superMixins;350 },351 /**352 * Get all classes including this mixin. (Only for mixins)353 *354 * @return {qx.Promise<qxl.apiviewer.dao.Class[]>} All classes including this mixin.355 */356 getIncluder() {357 if (!this._includersPromise) {358 if (this._meta.type == "mixin") {359 this._includersPromise = qxl.apiviewer.dao.Class.findClasses(360 this._meta.descendants361 );362 } else {363 this._includersPromise = qx.Promise.resolve([]);364 }365 }366 return this._includersPromise;367 },368 /**369 * Get all implementations of this interface. (Only for interfaces)370 *371 * @return {qx.Promise<qxl.apiviewer.dao.Class[]>} All implementations of this interface.372 */373 getImplementations() {374 if (!this._implementationsPromise) {375 if (this._meta.type == "interface") {376 this._implementationsPromise = qxl.apiviewer.dao.Class.findClasses(377 this._meta.descendants378 );379 } else {380 this._implementationsPromise = qx.Promise.resolve([]);381 }382 }383 return this._implementationsPromise;384 },385 /**386 * Get the constructor of the class.387 *388 * @return {qxl.apiviewer.dao.Method} The constructor of the class.389 */390 getConstructor() {391 return this._construct;392 },393 /**394 * Get all child controls395 *396 * @return {qxl.apiviewer.dao.ChildControl[]} All child controls.397 */398 getChildControls() {399 return this._childControls;400 },401 /**402 * Get the members of the class.403 *404 * @return {qxl.apiviewer.dao.Method[]} The members of the class.405 * @deprecated Is this used any more????406 */407 getMembers() {408 return this._members;409 },410 /**411 * Get the members of the class.412 *413 * @return {qxl.apiviewer.dao.Method[]} The members of the class.414 */415 getMethods() {416 return this._members;417 },418 /**419 * Get the members of the class, contributed from mixins420 *421 * @return {qxl.apiviewer.dao.Method[]} The members of the class.422 * @deprecated Is this used any more????423 */424 getMixinMembers() {425 return this._mixinMembers;426 },427 /**428 * Get the members of the class, contributed from mixins429 *430 * @return {qxl.apiviewer.dao.Method[]} The members of the class.431 */432 getMixinMethods() {433 return this._mixinMembers;434 },435 /**436 * Get the statics of the class.437 *438 * @return {qxl.apiviewer.dao.Method[]} The statics of the class.439 */440 getStatics() {441 return this._staticMethods;442 },443 /**444 * Get the events of the class.445 *446 * @return {qxl.apiviewer.dao.Event[]} The events of the class.447 */448 getEvents() {449 return this._events;450 },451 /**452 * Get the events of the class, contributed from mixins453 *454 * @return {qxl.apiviewer.dao.Event[]} The events of the class.455 */456 getMixinEvents() {457 return this._mixinEvents;458 },459 /**460 * Get the properties of the class.461 *462 * @return {qxl.apiviewer.dao.Property[]} The properties of the class.463 */464 getProperties() {465 return this._properties;466 },467 /**468 * Returns a property with a given name469 * @param name470 * @return {qxl.apiviewer.dao.Property} The named property471 */472 getProperty(name) {473 for (var i = 0; i < this._properties.length; i++) {474 var prop = this._properties[i];475 if (prop.getName() == name) {476 return prop;477 }478 }479 return null;480 },481 /**482 * Get the properties of the class, contributed from mixins483 *484 * @return {qxl.apiviewer.dao.Property[]} The properties of the class.485 */486 getMixinProperties() {487 return this._mixinProperties;488 },489 /**490 * Get the constants of the class.491 *492 * @return {qxl.apiviewer.dao.Constant[]} The constants of the class.493 */494 getConstants() {495 return this._constants;496 },497 /**498 * Get all references declared using the "see" attribute.499 *500 * @return {String[]} A list of all references declared using the "see" attribute.501 */502 getSee() {503 return (this._jsdoc["@see"] || []).map((item) => item.body);504 },505 getErrors() {506 return [];507 },508 /* COMPLEX FUNCTIONS */509 /**510 * Get the documentation nodes of all classes in the inheritance chain of a511 * class. The first entry in the list is the class itself.512 *513 * @param includeNativeObjects514 * {Boolean} true if you want to get native JS objects too515 * @return {qxl.apiviewer.dao.Class[]} array of super classes of the given516 * class.517 */518 getClassHierarchy(includeNativeObjects) {519 var result = [];520 for (521 var currentClass = this;522 currentClass;523 currentClass = currentClass.getSuperClass()524 ) {525 var isNative = qxl.apiviewer.dao.Class.isNativeObject(currentClass);526 if (!isNative || includeNativeObjects) {527 result.push(currentClass);528 }529 if (isNative) {530 break;531 }532 }533 return result;534 },535 /**536 * Get the documentation nodes of all interfaces in the inheritance chain of537 * an interface. The first entry in the list is the interface itself.538 *539 * @return {qxl.apiviewer.dao.Class[]} array of super interfaces of the given540 * interface.541 */542 getInterfaceHierarchy() {543 var result = [];544 /**545 * @param currentClass546 */547 function add(currentClass) {548 result.push(currentClass);549 currentClass.getSuperInterfaces().forEach((itf) => add(itf));550 }551 add(this);552 return result;553 },554 /**555 * Returns a list of all interfaces the class implements directly.556 *557 * @param includeSuperClasses558 * {Boolean?false} Whether the interfaces of all super classes559 * should be returned as well.560 */561 getAllInterfaces(includeSuperClasses) {562 var interfaceNodes = [];563 let ifaceRecurser = (ifaceNode) => {564 interfaceNodes.push(ifaceNode);565 (ifaceNode.getSuperInterfaces() || []).forEach(ifaceRecurser);566 };567 var classNodes = includeSuperClasses ? this.getClassHierarchy() : [this];568 classNodes.forEach((classNode) => {569 (classNode.getInterfaces() || []).forEach(ifaceRecurser);570 });571 return interfaceNodes;572 },573 /**574 * Return a class item matching the given name.575 *576 * @param itemName577 * {String} name of the class item578 * @return {qxl.apiviewer.dao.ClassItem} the class item.579 */580 getItemByNameFromMixins(itemName) {581 return (582 this._mixinMembers[itemName] ||583 this._mixinProperties[itemName] ||584 this._mixinEvents[itemName] ||585 null586 );587 },588 /**589 * Return a class item matching the given name.590 *591 * @param itemName {String} name of the class item592 * @return {qxl.apiviewer.dao.ClassItem} the class item.593 */594 getItem(itemName) {595 var itemListNames = [596 "getMembers",597 "getStatics",598 "getEvents",599 "getProperties",600 "getConstants",601 // "getAppearances",602 "getChildControls",603 ];604 for (var i = 0; i < itemListNames.length; i++) {605 var list = this[itemListNames[i]]();606 if (list) {607 for (var j = 0; j < list.length; j++) {608 if (itemName == list[j].getName()) {609 return list[j];610 }611 }612 }613 }614 return null;615 },616 /**617 * Get an array of class items matching the given list name. Known list names are:618 * <ul>619 * <li>events</li>620 * <li>constructor</li>621 * <li>properties</li>622 * <li>methods</li>623 * <li>methods-static</li>624 * <li>constants</li>625 * <li>appearances</li>626 * <li>superInterfaces</li>627 * <li>superMixins</li>628 * </li>629 *630 * @param listName {String} name of the item list631 * @return {apiviewer.dao.ClassItem[]} item list632 */633 getItemList(listName) {634 var methodMap = {635 events: "getEvents",636 constructor: "getConstructor",637 properties: "getProperties",638 methods: "getMembers",639 "methods-static": "getStatics",640 constants: "getConstants",641 // "appearances" : "getAppearances",642 superInterfaces: "getSuperInterfaces",643 superMixins: "getSuperMixins",644 childControls: "getChildControls",645 };646 if (listName == "constructor") {647 return this.getConstructor() ? [this.getConstructor()] : [];648 }649 return this[methodMap[listName]]();650 },651 /**652 * Get a class item by the item list name and the item name.653 * Valid item list names are documented at {@link #getItemList}.654 * .655 * @param listName {String} name of the item list.656 * @param itemName {String} name of the class item.657 * @return {apiviewer.dao.ClassItem} the matching class item.658 */659 getItemByListAndName(listName, itemName) {660 var list = this.getItemList(listName);661 for (var j = 0; j < list.length; j++) {662 if (itemName == list[j].getName()) {663 return list[j];664 }665 }666 return null;667 },668 loadDependedClasses() {669 return qxl.apiviewer.ClassLoader.loadClassList(this.getDependedClasses());670 },671 /**672 * Return a list of all classes, mixins and interfaces this class depends673 * on. This includes all super classes and their mixins/interfaces and the674 * class itself.675 *676 * @return {qx.Promise<Class[]>} array of dependent classes.677 */678 getDependedClasses() {679 let foundClasses = [];680 /**681 * @param clazz682 */683 function findClasses(clazz) {684 if (qxl.apiviewer.dao.Class.isNativeObject(clazz)) {685 return;686 }687 clazz.load().then(() => {});688 foundClasses.push(clazz);689 clazz.getSuperClass() && findClasses(clazz.getSuperClass());690 (clazz.getMixins() || []).forEach(() => findClasses);691 (clazz.getSuperMixins() || []).forEach(() => findClasses);692 (clazz.getInterfaces() || []).forEach(() => findClasses);693 (clazz.getSuperInterfaces() || []).forEach(() => findClasses);694 }695 findClasses(this);696 return foundClasses;697 },698 },699 statics: {700 _native_classes: {701 Array: Array,702 Boolean: Boolean,703 Date: Date,704 Error: Error,705 Function: Function,706 Math: Math,707 Number: Number,708 Object: Object,709 RegExp: RegExp,710 String: String,711 },712 /**713 * Get a class documentation by the class name.714 * @param className715 * {String} name of the class716 * @param create717 * @return {qxl.apiviewer.dao.Class} The class documentation718 */719 getClassByName(className, create) {720 var nativeClass = qxl.apiviewer.dao.Class._native_classes[className];721 if (nativeClass !== undefined) {722 return nativeClass;723 }724 var pkg = qxl.apiviewer.dao.Package.getParentPackage(className);725 if (!pkg) {726 throw new Error("Cannot find a package for " + className);727 }728 var cls = pkg.getClassByName(className);729 if (!cls && create) {730 cls = new qxl.apiviewer.dao.Class(className);731 }732 return cls;733 },734 /**735 * Get a class documentation by the class name.736 * @param classNames737 * @param create738 * @return {qxl.apiviewer.dao.Class} The class documentation739 */740 getClassesByName(classNames, create) {741 classNames = qx.lang.Array.toNativeArray(classNames);742 var result = classNames.map((name) =>743 qxl.apiviewer.dao.Class.getClassByName(name, create)744 );745 return result;746 },747 findClasses(name) {748 if (!name) {749 return qx.Promise.resolve([]);750 }751 var all = qx.lang.Array.toNativeArray(name)752 .filter((name) => !qxl.apiviewer.dao.Class._native_classes[name])753 .map((name) => {754 let c = qxl.apiviewer.dao.Class.getClassByName(name);755 if (c) {756 c.load();757 }758 return c;759 });760 return qx.Promise.all(all);761 },762 /**763 * Checks if the Class is a qooxdoo qxl.apiviewer.dao.Class Object or a native764 * one765 *766 * @param clazz767 * {qxl.apiviewer.dao.Class} the object to be checked768 * @return {Boolean} true if it is a JS native object769 */770 isNativeObject(clazz) {771 return clazz.classname !== "qxl.apiviewer.dao.Class";772 },773 },...

Full Screen

Full Screen

FindClasses.es6

Source:FindClasses.es6 Github

copy

Full Screen

1/**2 * Created by AlexanderC on 9/3/15.3 */4'use strict';5import path from 'path';6import fs from 'fs';7import os from 'os';8export class FindClasses {9 /**10 * @param {String} modulePath11 */12 constructor(modulePath) {13 this._modulePath = path.normalize(modulePath);14 this._libPath = path.join(this._modulePath, FindClasses.LIB_DIR);15 this._realLibPath = path.join(this._modulePath, FindClasses.REAL_LIB_DIR);16 this._testsPath = path.join(this._modulePath, FindClasses.TESTS_DIR);17 }18 /**19 * @returns {String[]}20 */21 generateMissingTests() {22 let generatedTests = [];23 let classFiles = FindClasses._lookupClassFiles(this._libPath);24 for (let filepath of classFiles) {25 let relativePath = filepath.substr(this._libPath.length + 1);26 let testFilePath = path.join(this._testsPath, relativePath.replace('.js', '.spec.js'));27 if (!fs.existsSync(testFilePath)) {28 let testContent = FindClasses._genTestSuite(relativePath);29 FindClasses._assureFileDir(testFilePath);30 fs.writeFileSync(testFilePath, testContent);31 generatedTests.push(testFilePath);32 }33 }34 return generatedTests;35 }36 /**37 * @param {String} filePath38 * @private39 */40 static _assureFileDir(filePath) {41 let dirname = path.dirname(filePath);42 let dirnameVector = dirname.split('/');43 let prevDir = '/';44 for (let i in dirnameVector) {45 if (!dirnameVector.hasOwnProperty(i)) {46 continue;47 }48 let dir = dirnameVector[i];49 let curDir = path.join(prevDir, dir);50 prevDir = curDir;51 if (!fs.existsSync(curDir)) {52 fs.mkdirSync(curDir);53 }54 }55 }56 /**57 * @param {String} relativePath58 * @returns {String}59 * @private60 */61 static _genTestSuite(relativePath) {62 return FindClasses.TEST_TPL63 .replace(/\{import\}/g, FindClasses._genClassInclude(relativePath))64 .replace(/\{fullClass\}/g, FindClasses._getFullClassName(relativePath))65 .replace(/\{class\}/g, FindClasses._getClassName(relativePath));66 }67 /**68 * @param {String} relativePath69 * @returns {String}70 * @private71 */72 static _genClassInclude(relativePath) {73 let dotsLength = relativePath.split('/').length;74 let relPathPrefix = "../".repeat(dotsLength) + FindClasses.REAL_LIB_DIR;75 return `import {${FindClasses._getClassName(relativePath)}} from '${relPathPrefix}/${FindClasses._getFullClassName(relativePath)}';`;76 }77 /**78 * @param {String} relativePath79 * @returns {String}80 * @private81 */82 static _getFullClassName(relativePath) {83 return relativePath.substr(0, relativePath.length - path.extname(relativePath).length);84 }85 /**86 * @param {String} relativePath87 * @returns {String}88 * @private89 */90 static _getClassName(relativePath) {91 return path.basename(relativePath, path.extname(relativePath));92 }93 /**94 * @param {String} dir95 * @param {Array} files_96 * @returns {Array}97 * @private98 */99 static _lookupClassFiles(dir, files_ = null) {100 files_ = files_ || [];101 let files = fs.readdirSync(dir);102 for (let i in files){103 if (!files.hasOwnProperty(i)) {104 continue;105 }106 let filename = files[i];107 let filepath = path.join(dir, filename);108 if (fs.statSync(filepath).isDirectory()){109 FindClasses._lookupClassFiles(filepath, files_);110 } else {111 if (!FindClasses._isClassFile(filename)) {112 continue;113 }114 files_.push(filepath);115 }116 }117 return files_;118 }119 /**120 * @param {String} filename121 * @returns {Boolean}122 * @private123 */124 static _isClassFile(filename) {125 return /^[A-Z]/.test(filename) && !/exception\.js$/i.test(filename) && path.extname(filename) === '.js';126 }127 /**128 * @returns {String}129 */130 get testsPath() {131 return this._testsPath;132 }133 /**134 * @returns {String}135 */136 get realLibPath() {137 return this._realLibPath;138 }139 /**140 * @returns {String}141 */142 get libPath() {143 return this._libPath;144 }145 /**146 * @returns {String}147 */148 get modulePath() {149 return this._modulePath;150 }151 /**152 * @returns {String}153 * @constructor154 */155 static get TEST_TPL() {156 let content = [];157 content.push(`// THIS TEST WAS GENERATED AUTOMATICALLY ON ${new Date().toString()}`);158 content.push('');159 content.push('\'use strict\';');160 content.push('');161 content.push('import chai from \'chai\';');162 content.push('{import}');163 content.push('');164 content.push('// @todo: Add more advanced tests');165 content.push('suite(\'{fullClass}\', function() {');166 content.push(' test(\'Class {class} exists in {fullClass}\', () => {');167 content.push(' chai.expect({class}).to.be.an(\'function\');');168 content.push(' });');169 content.push('});');170 content.push('');171 return content.join(os.EOL);172 }173 /**174 * @returns {String}175 */176 static get LIB_DIR() {177 return 'lib';178 }179 /**180 * @returns {String}181 */182 static get REAL_LIB_DIR() {183 return 'lib';184 }185 /**186 * @returns {String}187 */188 static get TESTS_DIR() {189 return 'test';190 }...

Full Screen

Full Screen

classesController.js

Source:classesController.js Github

copy

Full Screen

1// MODUELS2const Classes = require("../../../../models/Class");3const ClassRegister = require("../../../../models/ClassRegister");4class ClassesController {5 async index(req, res, next) {6 try {7 const classes = await Classes.find({});8 const options = {9 title: "مدیریت کلاس ها",10 };11 return res.render("./admin/Classes/index", { options, classes });12 } catch (error) {13 console.log(error);14 return res.redirect("/admin");15 }16 }17 async create(req, res, next) {18 try {19 const options = {20 title: "ایجاد کلاس جدید",21 };22 return res.render("./admin/Classes/create", {23 options,24 ClientError: req.flash("ClientError"),25 });26 } catch (error) {27 console.log(error);28 }29 }30 async store(req, res, next) {31 const { title } = req.body;32 const findWithTitle = await Classes.findOne({ title });33 if (findWithTitle) {34 req.flash("ClientError", ["این عنوان در سامانه موجود هست"]);35 return res.redirect("/admin/Classes/create");36 }37 const addClasses = new Classes({38 title,39 });40 addClasses.save((err, data) => {41 if (err) {42 console.log(err);43 } else {44 return res.redirect("/admin/Classes");45 }46 });47 }48 async update(req, res, next) {49 try {50 const options = {51 title: "ویرایش زبان",52 };53 const { title } = req.params;54 const findClasses = await Classes.findOne({ title });55 if (!findClasses) {56 return res.redirect("/admin/Classess");57 }58 return res.render("./admin/Classes/edit", {59 options,60 Class: findClasses,61 ClientError: req.flash("ClientError"),62 });63 } catch (error) {64 console.log(error);65 }66 }67 async edit(req, res, next) {68 try {69 const { title } = req.body;70 const { titleAddress } = req.params;71 const updateClasses = await Classes.findOneAndUpdate(72 { title: titleAddress },73 { $set: { title } }74 );75 if (updateClasses) {76 return res.redirect("/admin/Classes");77 } else {78 req.flash("ClientError", ["کلاس مورد نظر ویرایش شد"]);79 return res.redirect(`/admin/Classes/${titleAddress}/edit`);80 }81 } catch (error) {82 console.log(error);83 req.flash("ClientError", ["عملیات با موفقیت انجام نشد"]);84 }85 }86 async classStudents(req, res, next) {87 try {88 const { id } = req.params89 const findClasses = await Classes.findById(id);90 if (!findClasses) {91 return res.redirect("/admin/classes");92 }93 const classeStudents = await ClassRegister.find({94 class: findClasses.id,95 });96 const options = {97 title: "مدیریت دانش آموزان کلاس ها",98 };99 return res.render("./admin/Classes/students", { options, classeStudents });100 } catch (error) {101 console.log(error);102 return res.redirect("/admin");103 }104 }105}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var classes = redwood.FindClasses();3for (var i = 0; i < classes.length; i++) {4 console.log(classes[i].name);5}6var redwood = require('redwood');7var classes = redwood.FindClasses();8for (var i = 0; i < classes.length; i++) {9 console.log(classes[i].name);10}11var redwood = require('redwood');12var classes = redwood.FindClasses();13for (var i = 0; i < classes.length; i++) {14 console.log(classes[i].name);15}16var redwood = require('redwood');17var classes = redwood.FindClasses();18for (var i = 0; i < classes.length; i++) {19 console.log(classes[i].name);20}

Full Screen

Using AI Code Generation

copy

Full Screen

1import { FindClasses } from "redwoodjs/graphql-server"2const allClasses = FindClasses()3const allClassesExtendingBase = FindClasses("Base")4const allClassesExtendingBaseAndNamedUser = FindClasses("Base", "User")5const allClassesNamedUser = FindClasses(null, "User")6const allClassesNamedUserInServices = FindClasses(null, "User", "services")7const allClassesInServices = FindClasses(null, null, "services")8- The base class the class extends (optional)9- The name of the class (optional)10- The subdirectory to look in (optional)11import { FindClasses } from "redwoodjs/graphql-server"12const allClasses = FindClasses()13const allClassesExtendingBase = FindClasses("Base")

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var classes = redwood.FindClasses('test');3console.log(classes);4### redwood.FindClasses(searchString)5### redwood.FindClass(searchString)6### redwood.FindClassesWithAttribute(searchString, attributeName)7### redwood.FindClassWithAttribute(searchString, attributeName)8### redwood.FindClassesWithMethod(searchString, methodName)9### redwood.FindClassWithMethod(searchString, methodName)

Full Screen

Using AI Code Generation

copy

Full Screen

1var redwood = require('redwood');2var classes = redwood.FindClasses('Test');3console.log(classes);4var redwood = require('redwood');5var methods = redwood.FindMethods('Test');6console.log(methods);7var redwood = require('redwood');8var properties = redwood.FindProperties('Test');9console.log(properties);10var redwood = require('redwood');11var files = redwood.FindFiles('test');12console.log(files);13var redwood = require('redwood');14var directories = redwood.FindDirectories('test');15console.log(directories);16var redwood = require('redwood');17var files = redwood.FindFilesInDirectory('test', 'test');18console.log(files);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { FindClasses } = require('@redwoodjs/api/dist/FindClasses')2const classes = FindClasses('../api/src/functions/graphql')3console.log(classes)4const { GraphQLFunction } = require('@redwoodjs/api/dist/GraphQLFunction')5const { ApolloServer } = require('apollo-server-lambda')6const { ApolloServerPluginDrainHttpServer } = require('apollo-server-core')7const { createServer } = require('http')8const { schema } = require('./schema')9const httpServer = createServer()10const server = new ApolloServer({11 plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],12})13exports.graphqlHandler = server.createHandler({14 cors: {15 },16})

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 redwood 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