-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlitho-model-index.swift
More file actions
executable file
·100 lines (86 loc) · 5.04 KB
/
Copy pathlitho-model-index.swift
File metadata and controls
executable file
·100 lines (86 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/swift
import Foundation
let args = CommandLine.arguments
let targetName = args[1]
let modelName = args[2]
let capitalizeFirstLetter: (String) -> String = { $0.prefix(1).uppercased() + $0.dropFirst() }
let capModel = capitalizeFirstLetter(modelName)
let pluralModel = "\(modelName)s"
let pluralCapModel = "\(capModel)s"
let vcString = """
import LUX
import LithoOperators
import FlexDataSource
import PlaygroundVCHelpers
import Slippers
import Combine
import fuikit
struct \(capModel) {
}
struct \(pluralCapModel)Wrapper { var \(pluralModel): [\(capModel)]? }
extension \(capModel): Codable {}
extension \(pluralCapModel)Wrapper: Codable {}
func \(modelName)sVC() -> \(pluralCapModel)ViewController {
let vc = \(capModel)sViewController.makeFromXIB()
vc.onViewDidLoad = ~>configure(vc:)
return vc
}
class \(pluralCapModel)ViewController: FUITableViewViewController {
var viewModel: LUXTableViewModel?
}
fileprivate func configure(vc: \(pluralCapModel)ViewController) {
let refresher: Refreshable = <#Refreshable#> // e.g. Refresher, PageManager, MetaRefresher
let modelsPublisher: AnyPublisher<[\(capModel)], Never> = <#AnyPublisher<[\(capModel)], Never>#> // e.g. unwrappedModelPublisher(call.publisher.$data.eraseToAnyPublisher(), ^\(pluralCapModel)Wrapper.\(pluralModel)))
let vm = viewModel(for: vc.tableView, refresher, modelsPublisher)
vc.viewModel = vm
vm.refresh()
}
func viewModel(for tableView: UITableView?, _ refresher: Refreshable, _ \(pluralModel)Pub: AnyPublisher<[\(capModel)], Never>) -> LUXRefreshableTableViewModel {
let itemsPub: AnyPublisher<[FlexDataSourceItem], Never> = \(pluralModel)Pub.map(configure(\(modelName):in:) >||> LUXModelItem.init >||> map).eraseToAnyPublisher()
let vm = LUXItemsTableViewModel(refresher, itemsPublisher: itemsPub)
vm.tableView = tableView
return vm
}
func configure(\(modelName): \(capModel), in cell: UITableViewCell) {}
"""
let xib = """
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="\(capModel)sViewController" customModule="\(targetName)" customModuleProvider="target">
<connections>
<outlet property="tableView" destination="z1l-9v-LSq" id="3KD-qL-KPj"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="z1l-9v-LSq">
<rect key="frame" x="0.0" y="44" width="414" height="818"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
</tableView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="z1l-9v-LSq" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="EV1-2T-Akg"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="bottom" secondItem="z1l-9v-LSq" secondAttribute="bottom" id="WPi-dj-gni"/>
<constraint firstItem="z1l-9v-LSq" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" id="l9h-lv-Ntj"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="z1l-9v-LSq" secondAttribute="trailing" id="xaZ-SJ-SHt"/>
</constraints>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
<point key="canvasLocation" x="131.8840579710145" y="153.34821428571428"/>
</view>
</objects>
</document>
"""
try! vcString.write(toFile: "./\(targetName)/\(capModel)sViewController.swift", atomically: true, encoding: .utf8)
try! xib.write(toFile: "./\(targetName)/\(capModel)sViewController.xib", atomically: true, encoding: .utf8)