feat(RES-57): Add visibility to control scope of generated code (#18)
All checks were successful
gitea-openium/resgen.swift/pipeline/head This commit looks good

Add visibility parameter: public, package, internal, private
Impacted command: analytics, colors, fonts, images, strings, tags

Reviewed-on: #18
This commit is contained in:
2025-07-21 16:56:05 +02:00
parent beca2c6b2b
commit 5ad219ae89
62 changed files with 1526 additions and 794 deletions

View File

@@ -6,6 +6,7 @@
//
import Foundation
import ToolCore
// swiftlint:disable no_grouping_extension
@@ -22,33 +23,43 @@ 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)!
}
"""
"""
}
}
}