UNPKG

@appshuttle.io/turing

Version:
59 lines (45 loc) 2.4 kB
const fs = require('fs') const TRStringManagement = require('../../../../../Mixins/StringManagement/StringManagement') const IBActionTemplates = require('../../TemplateContent/IBAction-Templates') const SHButton = require('../../../../../Classes/UIElements/SHButton') const SHAction = require('../../../../../Classes/UIElements/Attributes/Actions/Action') class IBActionMotor { constructor(path, project, screen) { if (!path) throw new Error('No app delegate path is specified') if (!project) throw new Error('No project is specified') if (!screen) throw new Error('No screen specified') this.path = path this.project = project this.screen = screen this.IBActionContent = '' this.templates = new IBActionTemplates() this.StringManagement = new TRStringManagement() this.generateIBAction = function () { for (const subviewKey in screen.elements) { const element = screen.elements[subviewKey] if (element.type === 'BUTTON') { const button = new SHButton(element) for (const action of button.getActions().getOnTouchUpInside()) { this.generateIBActionStructure(new SHAction(action)) } for (const action of button.getActions().getOnTouchUpOutside()) { this.generateIBActionStructure(new SHAction(action)) } for (const action of button.getActions().getOnTouchDown()) { this.generateIBActionStructure(new SHAction(action)) } } } return this.IBActionContent } this.generateIBActionStructure = function (action) { if (action.isSegue()) { var currentIBActionContent = this.templates.getIBActionSegueStructure() currentIBActionContent = currentIBActionContent.replace(new RegExp(this.templates.FUNCTION_NAME_HOLDER, 'g'), action.getActionId()) currentIBActionContent = currentIBActionContent.replace(new RegExp(this.templates.SEGUE_ID_HOLDER, 'g'), action.getSegue().getSegueId()) this.IBActionContent = this.IBActionContent + currentIBActionContent } } } } module.exports = IBActionMotor