Add stencil on color
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
PixeeBox/resgen.swift/pipeline/head There was a failure building this commit

This commit is contained in:
2023-12-15 09:49:11 +01:00
parent eed20367b9
commit 3f64e9682c
12 changed files with 163 additions and 27 deletions

View File

@ -41,12 +41,28 @@ struct ColorExtensionGenerator {
staticVar: Bool,
extensionName: String,
isSwiftUI: Bool) -> String {
[
Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI),
Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI),
Self.getFooter()
]
.joined(separator: "\n")
// [
// Self.getHeader(extensionClassname: extensionName, isSwiftUI: isSwiftUI),
// Self.getProperties(for: colors, withStaticVar: staticVar, isSwiftUI: isSwiftUI),
// Self.getFooter()
// ]
// .joined(separator: "\n")
do {
let context: [String: Any] = [
"colors": colors,
"isStatic": staticVar,
"isSwiftUI": isSwiftUI,
"toolName": Colors.toolName,
"resgenVersion": ResgenSwiftVersion,
"extensionClassname": extensionName
]
return try ResgenSwift.environment.renderTemplate(name: "Colors/main_template", context: context)
} catch {
// let error = ColorsToolError.writeExtension(extensionFilePath, error.localizedDescription)
// print(error.description)
Colors.exit(withError: error)
}
}
private static func getHeader(extensionClassname: String, isSwiftUI: Bool) -> String {

View File

@ -8,6 +8,8 @@
import ToolCore
import Foundation
import ArgumentParser
import Stencil
import PathKit
struct ResgenSwift: ParsableCommand {
@ -32,6 +34,20 @@ struct ResgenSwift: ParsableCommand {
// subcommand is not given on the command line.
//defaultSubcommand: Twine.self
)
static let projectDirectory = URL(fileURLWithPath: #file) // ProjectDir/Sources/ResgenSwift/main.swift
.deletingLastPathComponent() // ProjectDir/Sources/ResgenSwift/
.deletingLastPathComponent() // ProjectDir/Sources/
.deletingLastPathComponent() // ProjectDir/
static let environment = Environment(
loader: FileSystemLoader(
paths: [
Path("\(projectDirectory.path)/Templates/")
]
)
)
}
print(ResgenSwift.projectDirectory.path)
ResgenSwift.main()