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

This commit is contained in:
2025-07-18 11:53:46 +02:00
parent beca2c6b2b
commit 7162f13166
61 changed files with 1511 additions and 791 deletions

View File

@ -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)!
}
"""
"""
}
}
}