Add visibility parameters to control scope of generated extension
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ToolCore
|
||||
|
||||
// swiftlint:disable no_grouping_extension
|
||||
|
||||
@ -22,33 +23,40 @@ extension FontName {
|
||||
postscriptName.removeCharacters(from: "[]+-_")
|
||||
}
|
||||
|
||||
func getProperty(isStatic: Bool, isSwiftUI: Bool) -> String {
|
||||
if isSwiftUI {
|
||||
if isStatic {
|
||||
return """
|
||||
static let \(fontNameSanitize): ((_ size: CGFloat) -> Font) = { size in
|
||||
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
func \(fontNameSanitize)(withSize size: CGFloat) -> Font {
|
||||
func getProperty(
|
||||
isStatic: Bool,
|
||||
isSwiftUI: Bool,
|
||||
visibility: ExtensionVisibility
|
||||
) -> String {
|
||||
switch (isSwiftUI, isStatic) {
|
||||
case (true, true):
|
||||
// SwiftUI, Static => let
|
||||
"""
|
||||
\(visibility) static let \(fontNameSanitize): ((_ size: CGFloat) -> Font) = { size in
|
||||
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
}
|
||||
// UIKit
|
||||
if isStatic {
|
||||
return """
|
||||
static let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
|
||||
case (true, false):
|
||||
// SwiftUI, Not Static => func
|
||||
"""
|
||||
\(visibility) func \(fontNameSanitize)(withSize size: CGFloat) -> Font {
|
||||
Font.custom(FontName.\(fontNameSanitize).rawValue, size: size)
|
||||
}
|
||||
"""
|
||||
case (false, true):
|
||||
// UIKit, Static => let
|
||||
"""
|
||||
\(visibility) static let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
|
||||
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
}
|
||||
return """
|
||||
func \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
|
||||
case (false, false):
|
||||
// UIKit, Not Static => func
|
||||
"""
|
||||
\(visibility) func \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
|
||||
UIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
|
||||
}
|
||||
"""
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user