123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836 |
- //
- // 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)
- }
- }
- }
- }
|