-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor Platform type to Framework which is more aligned with the concept of what we are representing, default Framework is now SwiftUI, Update README file * Move all file generation logic to new FileGenerator class, Add unit test for header method, header method update to validate struct file name is Capitalized. * Update help info for some parameters
- Loading branch information
Showing
10 changed files
with
362 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Framework.swift | ||
// Chroma | ||
// | ||
// Created by Jota Uribe on 16/10/23. | ||
// | ||
|
||
import Foundation | ||
import ArgumentParser | ||
|
||
enum Framework: String, CaseIterable, ExpressibleByArgument { | ||
case AppKit | ||
case SwiftUI | ||
case UIKit | ||
} | ||
|
||
extension Framework { | ||
static var help: ArgumentHelp { | ||
""" | ||
The framework compatibility of generated .swift file. | ||
Supported values: \(formattedValues). | ||
""" | ||
} | ||
} | ||
|
||
extension Framework { | ||
var defaultValue: String { | ||
switch self { | ||
case .UIKit, .AppKit: | ||
return "?? .clear " | ||
case .SwiftUI: | ||
return "" | ||
} | ||
} | ||
|
||
var parameterName: String { | ||
switch self { | ||
case .UIKit, .AppKit: | ||
return "named: " | ||
case .SwiftUI: | ||
return "" | ||
} | ||
} | ||
|
||
var variableType: String { | ||
switch self { | ||
case .UIKit: return "UIColor" | ||
case .AppKit: return "NSColor" | ||
case .SwiftUI: return "Color" | ||
} | ||
} | ||
|
||
var systemReservedVariableNames: [String] { | ||
switch self { | ||
case .UIKit, .AppKit: | ||
return [] | ||
case .SwiftUI: | ||
return ["accentColor"] | ||
} | ||
} | ||
|
||
func colorVariable(name: String) -> String? { | ||
let formattedName = name.camelCased().removing(.punctuationCharacters.union(.symbols)) | ||
guard !systemReservedVariableNames.contains(formattedName) else { return nil } | ||
return " static var \(formattedName): \(variableType) { return \(variableType)(\(parameterName)\"\(name)\") \(defaultValue)}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CaseIterable+Formatters.swift | ||
// Chroma | ||
// | ||
// Created by Jota Uribe on 17/10/23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension CaseIterable where Self: RawRepresentable { | ||
static var formattedValues: String { | ||
return Self.allCases.map { "\($0.rawValue)" }.joined(separator: ", ") | ||
} | ||
} |
Oops, something went wrong.