resgen.swift/Sources/FontToolCore/FontToolContentGenerator.swift

60 lines
1.7 KiB
Swift

//
// FontToolContentGenerator.swift
//
//
// Created by Thibaut Schmitt on 13/12/2021.
//
import Foundation
class FontToolContentGenerator {
static func getExtensionHeader(fontsNames: [String]) -> String {
"""
// \(fontsNames.joined(separator: " "))
// Generated from FontToolCore
import UIKit
"""
}
static func getFontNameEnum(fontsNames: [String]) -> String {
var enumDefinition = "\tenum FontName: String {\n"
fontsNames.forEach {
//debugPrint("Name: \($0.removeCharacters(from: "[]+-_"))")
enumDefinition += "\t\tcase \($0.removeCharacters(from: "[]+-_")) = \"\($0)\"\n"
}
enumDefinition += "\t}\n"
return enumDefinition
}
static func getFontMethods(fontsNames: [String], isUIFontExtension: Bool) -> String {
var methods = "\t// MARK: - Getter\n"
fontsNames
.unique()
.forEach {
let fontNameSanitize = $0.removeCharacters(from: "[]+-_")
if isUIFontExtension {
methods += """
\n\tstatic let \(fontNameSanitize): ((_ size: CGFloat) -> UIFont) = { size in
\tUIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
\t}\n
"""
} else {
methods += """
\n\tfunc \(fontNameSanitize)(withSize size: CGFloat) -> UIFont {
\tUIFont(name: FontName.\(fontNameSanitize).rawValue, size: size)!
\t}\n
"""
}
}
return methods
}
}