// // KMCompLightParser.swift // PDF Master // // Created by wanjun on 2022/12/21. // import Cocoa class KMCompLightParser: KMBaseParser { func startParse() -> KMCompLight { self.fileName = "comp-light" self.fileType = "json" return compLightParser(self.jsonParser) } func compLightParser(_ jsonData: [String: Any]) -> KMCompLight { let data = jsonData let allKey = data.keys let compLightModel = KMCompLight.init() if allKey.contains("btn") { compLightModel.btn = ["btn" : btnNodeParser((data["btn"] as! [String : Any]))] } if allKey.contains("dropdown") { compLightModel.dropdown = ["dropdown" : dropdownNodeParser((data["dropdown"] as! [String : Any]))] } if allKey.contains("navmenu") { compLightModel.navmenu = ["navmenu" : navmenuNodeParser((data["navmenu"] as! [String : Any]))] } if allKey.contains("multi-tab") { compLightModel.multi_tab = ["multi-tab" : multitabNodeParser((data["multi-tab"] as! [String : Any]))] } if allKey.contains("checkbox-radio") { compLightModel.checkbox_radio = ["checkbox-radio" : checkboxradioNodeParser((data["checkbox-radio"] as! [String : Any]))] } if allKey.contains("input") { compLightModel.input = ["input" : inputNodeParser((data["input"] as! [String : Any]))] } if allKey.contains("pagination") { compLightModel.pagination = ["pagination" : paginationNodeParser((data["pagination"] as! [String : Any]))] } if allKey.contains("select") { compLightModel.select = ["select" : selectNodeParser((data["select"] as! [String : Any]))] } if allKey.contains("slider") { compLightModel.slider = ["slider" : sliderNodeParser((data["slider"] as! [String : Any]))] } if allKey.contains("stepper") { compLightModel.stepper = ["stepper" : stepperNodeParser((data["stepper"] as! [String : Any]))] } if allKey.contains("badge") { compLightModel.badge = ["badge" : badgeNodeParser((data["badge"] as! [String : Any]))] } if allKey.contains("collapse") { compLightModel.collapse = ["collapse" : collapseNodeParser((data["collapse"] as! [String : Any]))] } if allKey.contains("list") { compLightModel.list = ["list" : listNodeParser((data["list"] as! [String : Any]))] } if allKey.contains("progress") { compLightModel.progress = ["progress" : progressNodeParser((data["progress"] as! [String : Any]))] } if allKey.contains("segmented") { compLightModel.segmented = ["segmented" : segmentedNodeParser((data["segmented"] as! [String : Any]))] } if allKey.contains("tree") { compLightModel.tree = ["tree" : treeNodeParser((data["tree"] as! [String : Any]))] } if allKey.contains("alert") { compLightModel.alert = ["alert" : alertNodeParser((data["alert"] as! [String : Any]))] } if allKey.contains("drawer") { compLightModel.drawer = ["drawer" : drawerNodeParser((data["drawer"] as! [String : Any]))] } if allKey.contains("notification") { compLightModel.notification = ["notification" : notificationNodeParser((data["notification"] as! [String : Any]))] } if allKey.contains("table") { compLightModel.table = ["table" : tableNodeParser((data["table"] as! [String : Any]))] } if allKey.contains("divider") { compLightModel.divider = ["divider" : dividerNodeParser((data["divider"] as! [String : Any]))] } return compLightModel } // MARK: Node Parser func btnNodeParser(_ jsonData: [String: Any]) -> KMCompLight_btn { let allKey = jsonData.keys let model = KMCompLight_btn.init() if allKey.contains("cta") { model.cta = ["cta" : sizeNodeParser(jsonData["cta"] as! [String : Any])] } if allKey.contains("brand") { model.brand = ["brand" : sizeNodeParser(jsonData["brand"] as! [String : Any])] } if allKey.contains("sec") { model.sec = ["sec" : sizeNodeParser(jsonData["sec"] as! [String : Any])] } if allKey.contains("ghost") { model.ghost = ["ghost" : sizeNodeParser(jsonData["ghost"] as! [String : Any])] } if allKey.contains("link") { model.link = ["link" : sizeNodeParser(jsonData["link"] as! [String : Any])] } if allKey.contains("upgrade") { model.upgrade = ["upgrade" : sizeNodeParser(jsonData["upgrade"] as! [String : Any])] } if allKey.contains("icon-fill") { model.icon_fill = ["icon-fill" : sizeNodeParser(jsonData["icon-fill"] as! [String : Any])] } if allKey.contains("sec-icon") { model.sec_icon = ["sec-icon" : sizeNodeParser(jsonData["sec-icon"] as! [String : Any])] } return model } func dropdownNodeParser(_ jsonData: [String: Any]) -> KMCompLight_dropdown { let allKey = jsonData.keys let model = KMCompLight_dropdown.init() if allKey.contains("s") { model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])] } return model } func navmenuNodeParser(_ jsonData: [String: Any]) -> KMCompLight_navmenu { let allKey = jsonData.keys let model = KMCompLight_navmenu.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("base") { model.base = ["base" : sizeNodeParser(jsonData["base"] as! [String : Any])] } if allKey.contains("has-icon") { model.has_icon = ["has-icon" : sizeNodeParser(jsonData["has-icon"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func multitabNodeParser(_ jsonData: [String: Any]) -> KMCompLight_multiTab { let allKey = jsonData.keys let model = KMCompLight_multiTab.init() if allKey.contains("bg") { model.bg = ["bg" : uiAttributeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func checkboxradioNodeParser(_ jsonData: [String: Any]) -> KMCompLight_checkboxRadio { let allKey = jsonData.keys let model = KMCompLight_checkboxRadio.init() if allKey.contains("bg") { model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func inputNodeParser(_ jsonData: [String: Any]) -> KMCompLight_input { let allKey = jsonData.keys let model = KMCompLight_input.init() if allKey.contains("m") { model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])] } if allKey.contains("tips") { model.tips = ["tips" : uiAttributeParser(jsonData["tips"] as! [String : Any])] } if allKey.contains("s") { model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])] } return model } func paginationNodeParser(_ jsonData: [String: Any]) -> KMCompLight_pagination { let allKey = jsonData.keys let model = KMCompLight_pagination.init() if allKey.contains("Simple") { model.simple = ["Simple" : uiAttributeParser2(jsonData["Simple"] as! [String : Any])] } if allKey.contains("multiple") { model.multiple = ["multiple" : uiAttributeParser2(jsonData["multiple"] as! [String : Any])] } return model } func selectNodeParser(_ jsonData: [String: Any]) -> KMCompLight_select { let allKey = jsonData.keys let model = KMCompLight_select.init() if allKey.contains("s") { model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])] } if allKey.contains("m") { model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])] } if allKey.contains("Simple") { model.simple = ["Simple" : uiAttributeParser2(jsonData["Simple"] as! [String : Any])] } return model } func sliderNodeParser(_ jsonData: [String: Any]) -> KMCompLight_slider { let allKey = jsonData.keys let model = KMCompLight_slider.init() if allKey.contains("knob") { model.knob = ["knob" : uiStateParser(jsonData["knob"] as! [String : Any])] } if allKey.contains("track") { model.track = ["track" : uiStateParser(jsonData["track"] as! [String : Any])] } if allKey.contains("track-filled") { model.track_filled = ["track-filled" : uiStateParser(jsonData["track-filled"] as! [String : Any])] } return model } func stepperNodeParser(_ jsonData: [String: Any]) -> KMCompLight_stepper { let allKey = jsonData.keys let model = KMCompLight_stepper.init() if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("arrow") { model.arrow = ["arrow" : uiAttributeParser(jsonData["arrow"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func badgeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_badge { let allKey = jsonData.keys let model = KMCompLight_badge.init() if allKey.contains("dot") { model.dot = ["dot" : valueTypeParser(jsonData["dot"] as! [String : Any])] } if allKey.contains("text") { model.text = ["text" : uiAttributeParser2(jsonData["text"] as! [String : Any])] } return model } func cardNodeParser(_ jsonData: [String: Any]) -> KMCompLight_card { let allKey = jsonData.keys let model = KMCompLight_card.init() if allKey.contains("has-desc") { model.has_desc = ["has-desc" : uiAttributeParser(jsonData["has-desc"] as! [String : Any])] } if allKey.contains("Simple") { model.simple = ["Simple" : uiAttributeParser(jsonData["Simple"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func collapseNodeParser(_ jsonData: [String: Any]) -> KMCompLight_collapse { let allKey = jsonData.keys let model = KMCompLight_collapse.init() if allKey.contains("ad-list") { let subData = jsonData["ad-list"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("mac-text") { submodel.mac_text = ["mac-text" : uiStateParser(subData["mac-text"] as! [String : Any])] } if subKeys.contains("bg") { submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])] } if subKeys.contains("win-text") { submodel.win_text = ["win-text" : uiStateParser(subData["win-text"] as! [String : Any])] } if subKeys.contains("item-spacing") { submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])] } model.ad_list = ["ad-list" : submodel] } if allKey.contains("bota-list") { let subData = jsonData["bota-list"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("bg") { submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])] } if subKeys.contains("mac-text-title") { submodel.mac_text_title = ["mac-text-title" : uiStateParser(subData["mac-text-title"] as! [String : Any])] } if subKeys.contains("mac-text-desc") { submodel.mac_text_desc = ["mac-text-desc" : uiStateParser(subData["mac-text-desc"] as! [String : Any])] } if subKeys.contains("win-text-title") { submodel.win_text_title = ["win-text-title" : uiStateParser(subData["win-text-title"] as! [String : Any])] } if subKeys.contains("win-text-desc") { submodel.win_text_desc = ["win-text-desc" : uiStateParser(subData["win-text-desc"] as! [String : Any])] } model.bota_list = ["bota-list" : submodel] } return model } func listNodeParser(_ jsonData: [String: Any]) -> KMCompLight_list { let allKey = jsonData.keys let model = KMCompLight_list.init() if allKey.contains("bookmark") { let subData = jsonData["bookmark"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("mac-text") { submodel.mac_text = ["mac-text" : valueTypeParser(subData["mac-text"] as! [String : Any])] } if subKeys.contains("win-text") { submodel.win_text = ["win-text" : valueTypeParser(subData["win-text"] as! [String : Any])] } if subKeys.contains("bg") { submodel.bg = ["bg" : uiStateParser(subData["bg"] as! [String : Any])] } model.bookmark = ["bookmark" : submodel] } if allKey.contains("markup-header") { model.markup_header = ["markup-header" : uiAttributeParser2(jsonData["markup-header"] as! [String : Any])] } if allKey.contains("markup-note") { model.markup_note = ["markup-note" : uiAttributeParser2(jsonData["markup-note"] as! [String : Any])] } return model } func progressNodeParser(_ jsonData: [String: Any]) -> KMCompLight_progress { let allKey = jsonData.keys let model = KMCompLight_progress.init() if allKey.contains("popup") { let subData = jsonData["popup"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("bg") { submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])] } if subKeys.contains("mac-text") { submodel.mac_text = ["mac-text" : valueTypeParser(subData["mac-text"] as! [String : Any])] } if subKeys.contains("win-text") { submodel.win_text = ["win-text" : valueTypeParser(subData["win-text"] as! [String : Any])] } if subKeys.contains("progress-bar") { submodel.progress_bar = ["progress-bar" : progressBarParser(subData["progress-bar"] as! [String : Any])] } if subKeys.contains("item-spacing") { submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])] } model.popup = ["popup" : submodel] } if allKey.contains("loading") { let subData = jsonData["loading"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_sizeNode.init() if subKeys.contains("m") { submodel.m = ["m" : valueTypeParser(subData["m"] as! [String : Any])] } if subKeys.contains("s") { submodel.s = ["s" : valueTypeParser(subData["s"] as! [String : Any])] } model.loading = ["loading" : submodel] } return model } func segmentedNodeParser(_ jsonData: [String: Any]) -> KMCompLight_segmented { let allKey = jsonData.keys let model = KMCompLight_segmented.init() if allKey.contains("bg") { model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("bg-item") { model.bg_item = ["bg-item" : uiStateParser(jsonData["bg-item"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func treeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_tree { let allKey = jsonData.keys let model = KMCompLight_tree.init() if allKey.contains("base") { model.base = ["base" : baseNodeParser(jsonData["base"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("rename") { let subData = jsonData["rename"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("bg-text") { submodel.bg_text = ["bg-text" : uiStateParser(subData["bg-text"] as! [String : Any])] } if subKeys.contains("bg-field") { submodel.bg_field = ["bg-field" : valueTypeParser(subData["bg-field"] as! [String : Any])] } model.rename = ["rename" : submodel] } if allKey.contains("has-arrow") { model.has_arrow = ["has-arrow" : baseNodeParser(jsonData["has-arrow"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func alertNodeParser(_ jsonData: [String: Any]) -> KMCompLight_alert { let allKey = jsonData.keys let model = KMCompLight_alert.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } return model } func drawerNodeParser(_ jsonData: [String: Any]) -> KMCompLight_drawer { let allKey = jsonData.keys let model = KMCompLight_drawer.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } return model } func notificationNodeParser(_ jsonData: [String: Any]) -> KMCompLight_notification { let allKey = jsonData.keys let model = KMCompLight_notification.init() if allKey.contains("toast") { model.toast = ["toast" : uiAttributeParser2(jsonData["toast"] as! [String : Any])] } if allKey.contains("modal") { let subData = jsonData["modal"] as! [String : Any] let subKeys = subData.keys let submodel = KMCompLight_UIAttribute.init() if subKeys.contains("bg") { submodel.bg = ["bg" : valueTypeParser(subData["bg"] as! [String : Any])] } if subKeys.contains("item-spacing") { submodel.item_spacing = ["item-spacing" : valueTypeParser(subData["item-spacing"] as! [String : Any])] } if subKeys.contains("mac-text") { submodel.mac_text = ["mac-text" : uiStateParser(subData["mac-text"] as! [String : Any])] } if subKeys.contains("win-text") { submodel.win_text = ["win-text" : uiStateParser(subData["win-text"] as! [String : Any])] } model.modal = ["modal" : submodel] } return model } func tableNodeParser(_ jsonData: [String: Any]) -> KMCompLight_table { let allKey = jsonData.keys let model = KMCompLight_table.init() if allKey.contains("header") { model.header = ["header" : uiAttributeParser2(jsonData["header"] as! [String : Any])] } if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("list") { model.list = ["list" : tableListNodeParser(jsonData["list"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } return model } func dividerNodeParser(_ jsonData: [String: Any]) -> KMCompLight_divider { let allKey = jsonData.keys let model = KMCompLight_divider.init() if allKey.contains("horiz") { model.horiz = ["horiz" : valueTypeParser(jsonData["horiz"] as! [String : Any])] } if allKey.contains("vert") { model.vert = ["vert" : valueTypeParser(jsonData["vert"] as! [String : Any])] } return model } // MARK: func sizeNodeParser(_ jsonData: [String: Any]) -> KMCompLight_sizeNode { let allKey = jsonData.keys let model = KMCompLight_sizeNode.init() if allKey.contains("s") { model.s = ["s" : uiAttributeParser(jsonData["s"] as! [String : Any])] } if allKey.contains("m") { model.m = ["m" : uiAttributeParser(jsonData["m"] as! [String : Any])] } if allKey.contains("l") { model.l = ["l" : uiAttributeParser(jsonData["l"] as! [String : Any])] } return model } func tableListNodeParser(_ jsonData: [String: Any]) -> KMCompLight_tableListNode { let allKey = jsonData.keys let model = KMCompLight_tableListNode.init() if allKey.contains("file") { model.file = ["file" : uiAttributeParser3(jsonData["file"] as! [String : Any])] } if allKey.contains("batch") { model.batch = ["batch" : uiAttributeParser(jsonData["batch"] as! [String : Any])] } return model } func uiAttributeParser(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute { //btn - cta - mac-text/ let allKey = jsonData.keys let model = KMCompLight_UIAttribute.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } return model } func uiAttributeParser2(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute { let allKey = jsonData.keys let model = KMCompLight_UIAttribute.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : valueTypeParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : valueTypeParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : valueTypeParser(jsonData["win-text"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : valueTypeParser(jsonData["item-spacing"] as! [String : Any])] } return model } func uiAttributeParser3(_ jsonData: [String: Any]) -> KMCompLight_UIAttribute { //btn - cta - mac-text/ let allKey = jsonData.keys let model = KMCompLight_UIAttribute.init() if allKey.contains("mac-text") { model.mac_text = ["mac-text" : uiStateParser(jsonData["mac-text"] as! [String : Any])] } if allKey.contains("bg") { model.bg = ["bg" : uiStateParser(jsonData["bg"] as! [String : Any])] } if allKey.contains("win-text") { model.win_text = ["win-text" : uiStateParser(jsonData["win-text"] as! [String : Any])] } if allKey.contains("item-spacing") { model.item_spacing = ["item-spacing" : uiStateParser(jsonData["item-spacing"] as! [String : Any])] } return model } func uiStateParser(_ jsonData: [String: Any]) -> KMCompLight_UIState { let allKey = jsonData.keys let model = KMCompLight_UIState.init() if allKey.contains("def") { model.def = ["def" : valueTypeParser(jsonData["def"] as! [String : Any])] } if allKey.contains("dis") { model.dis = ["dis" : valueTypeParser(jsonData["dis"] as! [String : Any])] } if allKey.contains("norm") { model.norm = ["norm" : valueTypeParser(jsonData["norm"] as! [String : Any])] } if allKey.contains("hov") { model.hov = ["hov" : valueTypeParser(jsonData["hov"] as! [String : Any])] } if allKey.contains("act") { model.act = ["act" : valueTypeParser(jsonData["act"] as! [String : Any])] } if allKey.contains("sel") { model.sel = ["sel" : valueTypeParser(jsonData["sel"] as! [String : Any])] } if allKey.contains("placeholder") { model.placeholder = ["placeholder" : valueTypeParser(jsonData["placeholder"] as! [String : Any])] } if allKey.contains("focus") { model.focus = ["focus" : valueTypeParser(jsonData["focus"] as! [String : Any])] } if allKey.contains("error-def") { model.error_def = ["error-def" : valueTypeParser(jsonData["error-def"] as! [String : Any])] } if allKey.contains("error-focus") { model.error_focus = ["error-focus" : valueTypeParser(jsonData["error-focus"] as! [String : Any])] } if allKey.contains("error") { model.error = ["error" : valueTypeParser(jsonData["error"] as! [String : Any])] } if allKey.contains("none") { model.none = ["none" : valueTypeParser(jsonData["none"] as! [String : Any])] } if allKey.contains("custom") { model.custom = ["custom" : valueTypeParser(jsonData["custom"] as! [String : Any])] } if allKey.contains("move") { model.move = ["move" : valueTypeParser(jsonData["move"] as! [String : Any])] } if allKey.contains("change") { model.change = ["change" : valueTypeParser(jsonData["change"] as! [String : Any])] } if allKey.contains("title") { model.title = ["title" : valueTypeParser(jsonData["title"] as! [String : Any])] } if allKey.contains("desc") { model.desc = ["desc" : valueTypeParser(jsonData["desc"] as! [String : Any])] } if allKey.contains("unsel") { model.unsel = ["unsel" : valueTypeParser(jsonData["unsel"] as! [String : Any])] } if allKey.contains("main") { model.main = ["main" : valueTypeParser(jsonData["main"] as! [String : Any])] } if allKey.contains("info") { model.info = ["info" : valueTypeParser(jsonData["info"] as! [String : Any])] } if allKey.contains("warning") { model.warning = ["warning" : valueTypeParser(jsonData["warning"] as! [String : Any])] } if allKey.contains("item") { model.item = ["item" : valueTypeParser(jsonData["item"] as! [String : Any])] } return model } func valueTypeParser(_ jsonData: [String: Any]) -> KMCompLight_valueType { let allKey = jsonData.keys let model = KMCompLight_valueType.init() if allKey.contains("value") { model.value = ["value" : uiValueParser(jsonData["value"] as! [String : Any])] } if allKey.contains("type") { model.type = ["type" : jsonData["type"] as! String] } return model } func uiValueParser(_ jsonData: [String: Any]) -> KMCompLight_UIValue { let allKey = jsonData.keys let model = KMCompLight_UIValue.init() if allKey.contains("fill") { model.fill = ["fill" : jsonData["fill"] as! String] } if allKey.contains("typography") { model.typography = ["typography" : jsonData["typography"] as! String] } if allKey.contains("height") { model.height = ["height" : jsonData["height"] as! String] } if allKey.contains("horizontalPadding") { model.horizontalPadding = ["horizontalPadding" : jsonData["horizontalPadding"] as! String] } if allKey.contains("borderRadius") { model.borderRadius = ["borderRadius" : jsonData["borderRadius"] as! String] } if allKey.contains("itemSpacing") { model.itemSpacing = ["itemSpacing" : jsonData["itemSpacing"] as! String] } if allKey.contains("borderWidth") { model.borderWidth = ["borderWidth" : jsonData["borderWidth"] as! String] } if allKey.contains("border") { model.border = ["border" : jsonData["border"] as! String] } if allKey.contains("borderRadiusTopLeft") { model.borderRadiusTopLeft = ["borderRadiusTopLeft" : jsonData["borderRadiusTopLeft"] as! String] } if allKey.contains("borderRadiusTopRight") { model.borderRadiusTopRight = ["borderRadiusTopRight" : jsonData["borderRadiusTopRight"] as! String] } if allKey.contains("borderWidthBottom") { model.borderWidthBottom = ["borderWidthBottom" : jsonData["borderWidthBottom"] as! String] } if allKey.contains("boxShadow") { model.boxShadow = ["boxShadow" : jsonData["boxShadow"] as! String] } if allKey.contains("paddingLeft") { model.paddingLeft = ["paddingLeft" : jsonData["paddingLeft"] as! String] } if allKey.contains("paddingRight") { model.paddingRight = ["paddingRight" : jsonData["paddingRight"] as! String] } if allKey.contains("paddingTop") { model.paddingTop = ["paddingTop" : jsonData["paddingTop"] as! String] } if allKey.contains("paddingBottom") { model.paddingBottom = ["paddingBottom" : jsonData["paddingBottom"] as! String] } return model } func progressBarParser(_ jsonData: [String: Any]) -> KMCompLight_progressBar { let allKey = jsonData.keys let model = KMCompLight_progressBar.init() if allKey.contains("track") { model.track = ["track" : valueTypeParser(jsonData["track"] as! [String : Any])] } if allKey.contains("track-filled") { model.track_filled = ["track-filled" : valueTypeParser(jsonData["track-filled"] as! [String : Any])] } return model } func baseNodeParser(_ jsonData: [String: Any]) -> KMCompLight_baseNode { let allKey = jsonData.keys let model = KMCompLight_baseNode.init() if allKey.contains("parent") { model.parent = ["parent" : uiAttributeParser(jsonData["parent"] as! [String : Any])] } if allKey.contains("children-lv2") { model.children_lv2 = ["children-lv2" : uiAttributeParser(jsonData["children-lv2"] as! [String : Any])] } if allKey.contains("children-lv3") { model.children_lv3 = ["children-lv3" : uiAttributeParser(jsonData["children-lv3"] as! [String : Any])] } if allKey.contains("children-lv4") { model.children_lv4 = ["children-lv4" : uiAttributeParser(jsonData["children-lv4"] as! [String : Any])] } return model } } // MARK: - Parser Action extension KMCompLightParser { func startJSONParse() -> [String : Any] { self.fileName = "comp-light" self.fileType = "json" return self.jsonParser } func parserValueNode(_ dict: [String : Any], _ tokenKey: String) -> Void { let valueDict = dict var tokenStr = tokenKey let allKey = valueDict.keys if allKey.contains("value") { let value = valueDict["value"] if (value is [String : String]) { var rootNode = value as! [String : Any] let rootNodeKeys = rootNode.keys for rootNodeKey in rootNodeKeys { let rootValue: String = rootNode[rootNodeKey] as! String if (rootValue.first == "{") && (rootValue.last == "}") { rootNode.updateValue(valueParser(key: rootValue), forKey: rootNodeKey) } } finalDict[tokenStr] = rootNode } } else { for node in allKey { if tokenKey == "" { tokenStr = node } else { tokenStr = String(format: "%@.%@", tokenKey, node) } parserValueNode(valueDict[node] as! [String : Any], tokenStr) } } } }