Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict with SwiftUI: Renaming Classes to RImageRessource and RColorRessource #854

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/RswiftGenerators/AssetCatalog+Generator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public protocol AssetCatalogContent {
func generateVarGetter() -> VarGetter
}

extension ColorResource {
extension RColorResource {
public static func generateStruct(catalogs: [AssetCatalog], prefix: SwiftIdentifier) -> Struct {
let merged: AssetCatalog.Namespace = catalogs.map(\.root).reduce(.init(), { $0.merging($1) })

Expand All @@ -29,8 +29,8 @@ extension DataResource {
}
}

extension ImageResource {
public static func generateStruct(catalogs: [AssetCatalog], toplevel resources: [ImageResource], prefix: SwiftIdentifier) -> Struct {
extension RImageResource {
public static func generateStruct(catalogs: [AssetCatalog], toplevel resources: [RImageResource], prefix: SwiftIdentifier) -> Struct {
// Multiple resources can share same name,
// for example: Colors.jpg and Colors@2x.jpg are both named "Colors.jpg"
// Deduplicate these
Expand Down Expand Up @@ -97,14 +97,14 @@ extension AssetCatalog.Namespace {
}
}

extension ColorResource: AssetCatalogContent {
extension RColorResource: AssetCatalogContent {
public func generateVarGetter() -> VarGetter {
let fullname = (path + [name]).joined(separator: "/")
let code = ".init(name: \"\(fullname.escapedStringLiteral)\", path: \(path), bundle: bundle)"
return VarGetter(
comments: ["Color `\(fullname)`."],
name: SwiftIdentifier(name: name),
typeReference: TypeReference(module: .rswiftResources, rawName: "ColorResource"),
typeReference: TypeReference(module: .rswiftResources, rawName: "RColorResource"),
valueCodeString: code
)
}
Expand All @@ -124,7 +124,7 @@ extension DataResource: AssetCatalogContent {
}
}

extension ImageResource: AssetCatalogContent {
extension RImageResource: AssetCatalogContent {
public func generateVarGetter() -> VarGetter {
let locs = locale.map { $0.codeString() } ?? "nil"
let odrt = onDemandResourceTags?.debugDescription ?? "nil"
Expand All @@ -133,7 +133,7 @@ extension ImageResource: AssetCatalogContent {
return VarGetter(
comments: ["Image `\(fullname)`."],
name: SwiftIdentifier(name: name),
typeReference: TypeReference(module: .rswiftResources, rawName: "ImageResource"),
typeReference: TypeReference(module: .rswiftResources, rawName: "RImageResource"),
valueCodeString: code
)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/RswiftGenerators/FontResource+Generator.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FontResource+Generator.swift
// RFontResource+Generator.swift
// rswift
//
// Created by Tom Lokhorst on 2021-04-18.
Expand All @@ -8,8 +8,8 @@
import Foundation
import RswiftResources

extension FontResource {
public static func generateStruct(resources: [FontResource], prefix: SwiftIdentifier) -> Struct {
extension RFontResource {
public static func generateStruct(resources: [RFontResource], prefix: SwiftIdentifier) -> Struct {
let structName = SwiftIdentifier(name: "font")
let qualifiedName = prefix + structName
let warning: (String) -> Void = { print("warning: [R.swift]", $0) }
Expand All @@ -36,7 +36,7 @@ extension FontResource {
comments: [],
name: .init(name: "makeIterator"),
params: [],
returnType: .indexingIterator(.fontResource),
returnType: .indexingIterator(.RFontResource),
valueCodeString: "[\(names.map(\.value).joined(separator: ", "))].makeIterator()"
)
}
Expand All @@ -57,12 +57,12 @@ extension FontResource {
}
}

extension FontResource {
extension RFontResource {
func generateVarGetter() -> VarGetter {
VarGetter(
comments: ["Font `\(name)`."],
name: SwiftIdentifier(name: name),
typeReference: TypeReference(module: .rswiftResources, rawName: "FontResource"),
typeReference: TypeReference(module: .rswiftResources, rawName: "RFontResource"),
valueCodeString: ".init(name: \"\(name)\", bundle: bundle, filename: \"\(filename)\")"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ extension TypeReference {
static var nsViewController: TypeReference = .init(module: .appKit, rawName: "NSViewController")


static var fontResource: TypeReference = .init(module: .rswiftResources, rawName: "FontResource")
static var RFontResource: TypeReference = .init(module: .rswiftResources, rawName: "RFontResource")
}
20 changes: 10 additions & 10 deletions Sources/RswiftParsers/ProjectResources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public enum ResourceType: String, CaseIterable {
public struct ProjectResources {
public let assetCatalogs: [AssetCatalog]
public let files: [FileResource]
public let fonts: [FontResource]
public let images: [ImageResource]
public let fonts: [RFontResource]
public let images: [RImageResource]
public let strings: [StringsTable]
public let nibs: [NibResource]
public let storyboards: [StoryboardResource]
Expand Down Expand Up @@ -104,8 +104,8 @@ public struct ProjectResources {

let assetCatalogs: [AssetCatalog]
let files: [FileResource]
let fonts: [FontResource]
let images: [ImageResource]
let fonts: [RFontResource]
let images: [RImageResource]
let strings: [StringsTable]
let nibs: [NibResource]
let storyboards: [StoryboardResource]
Expand All @@ -123,25 +123,25 @@ public struct ProjectResources {
let dontParseFileForImages = !parseImagesAsFiles
files = try urls
.filter { !FileResource.unsupportedExtensions.contains($0.pathExtension) }
.filter { !(dontParseFileForFonts && FontResource.supportedExtensions.contains($0.pathExtension)) }
.filter { !(dontParseFileForImages && ImageResource.supportedExtensions.contains($0.pathExtension)) }
.filter { !(dontParseFileForFonts && RFontResource.supportedExtensions.contains($0.pathExtension)) }
.filter { !(dontParseFileForImages && RImageResource.supportedExtensions.contains($0.pathExtension)) }
.compactMap { url in try parse(with: warning) { try FileResource.parse(url: url) } }
} else {
files = []
}

if resourceTypes.contains(.font) {
fonts = try urls
.filter { FontResource.supportedExtensions.contains($0.pathExtension) }
.compactMap { url in try parse(with: warning) { try FontResource.parse(url: url) } }
.filter { RFontResource.supportedExtensions.contains($0.pathExtension) }
.compactMap { url in try parse(with: warning) { try RFontResource.parse(url: url) } }
} else {
fonts = []
}

if resourceTypes.contains(.image) {
images = try urls
.filter { ImageResource.supportedExtensions.contains($0.pathExtension) }
.compactMap { url in try parse(with: warning) { try ImageResource.parse(url: url, assetTags: nil) } }
.filter { RImageResource.supportedExtensions.contains($0.pathExtension) }
.compactMap { url in try parse(with: warning) { try RImageResource.parse(url: url, assetTags: nil) } }
} else {
images = []
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/RswiftParsers/Resources/AssetCatalog+Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ extension AssetCatalog: SupportedExtensions {
subnamespaces[name] = namespace
}

var colors: [ColorResource] = []
var colors: [RColorResource] = []
for fileURL in directory.colors {
let name = fileURL.filenameWithoutExtension!
colors.append(.init(name: name, path: path, bundle: .temp))
}

var images: [ImageResource] = []
var images: [RImageResource] = []
for fileURL in directory.images {
let name = fileURL.filenameWithoutExtension!
let tags = parseOnDemandResourceTags(directory: fileURL)
Expand Down
8 changes: 4 additions & 4 deletions Sources/RswiftParsers/Resources/FontResource+Parser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FontResource.swift
// RFontResource.swift
// R.swift
//
// Created by Mathijs Kadijk on 09-12-15.
Expand All @@ -9,10 +9,10 @@ import Foundation
import RswiftResources
import CoreGraphics

extension FontResource: SupportedExtensions {
extension RFontResource: SupportedExtensions {
static public let supportedExtensions: Set<String> = ["otf", "ttf"]

static public func parse(url: URL) throws -> FontResource {
static public func parse(url: URL) throws -> RFontResource {
guard let dataProvider = CGDataProvider(url: url as CFURL) else {
throw ResourceParsingError("Unable to create data provider for font at \(url)")
}
Expand All @@ -22,7 +22,7 @@ extension FontResource: SupportedExtensions {
throw ResourceParsingError("No postscriptName associated to font at \(url)")
}

return FontResource(
return RFontResource(
name: postScriptName as String,
bundle: .temp,
filename: url.lastPathComponent
Expand Down
10 changes: 5 additions & 5 deletions Sources/RswiftParsers/Resources/ImageResource+Parser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ImageResource.swift
// RImageResource.swift
// R.swift
//
// Created by Mathijs Kadijk on 09-12-15.
Expand All @@ -10,11 +10,11 @@ import RswiftResources
import CoreGraphics


extension ImageResource: SupportedExtensions {
extension RImageResource: SupportedExtensions {
// See "Supported Image Formats" on https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImage_Class/
static public let supportedExtensions: Set<String> = ["tiff", "tif", "jpg", "jpeg", "gif", "png", "bmp", "bmpf", "ico", "cur", "xbm"]

static public func parse(url: URL, assetTags: [String]?) throws -> ImageResource {
static public func parse(url: URL, assetTags: [String]?) throws -> RImageResource {
let filename = url.lastPathComponent
let pathExtension = url.pathExtension
guard filename.count > 0 && pathExtension.count > 0 else {
Expand All @@ -23,12 +23,12 @@ extension ImageResource: SupportedExtensions {

let locale = LocaleReference(url: url)

let extensions = ImageResource.supportedExtensions.joined(separator: "|")
let extensions = RImageResource.supportedExtensions.joined(separator: "|")
let regex = try! NSRegularExpression(pattern: "(~(ipad|iphone))?(@[2,3]x)?\\.(\(extensions))$", options: .caseInsensitive)
let fullFileNameRange = NSRange(location: 0, length: filename.count)
let pathExtensionToUse = (pathExtension == "png") ? "" : ".\(pathExtension)"
let name = regex.stringByReplacingMatches(in: filename, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: fullFileNameRange, withTemplate: pathExtensionToUse)

return ImageResource(name: name, path: [], bundle: .temp, locale: locale, onDemandResourceTags: assetTags)
return RImageResource(name: name, path: [], bundle: .temp, locale: locale, onDemandResourceTags: assetTags)
}
}
8 changes: 4 additions & 4 deletions Sources/RswiftResources/AssetCatalog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public struct AssetCatalog {
extension AssetCatalog {
public struct Namespace {
public var subnamespaces: [String: Namespace] = [:]
public var colors: [ColorResource] = []
public var images: [ImageResource] = []
public var colors: [RColorResource] = []
public var images: [RImageResource] = []
public var dataAssets: [DataResource] = []

public init() {
}

public init(
subnamespaces: [String: Namespace],
colors: [ColorResource],
images: [ImageResource],
colors: [RColorResource],
images: [RImageResource],
dataAssets: [DataResource]
) {
self.subnamespaces = subnamespaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Color {

- parameter resource: The resource you want the color of (`R.color.*`)
*/
public init(_ resource: ColorResource) {
public init(_ resource: RColorResource) {
self.init(resource.name, bundle: resource.bundle)
}
}
Expand All @@ -25,7 +25,7 @@ extension Color {
#if os(iOS) || os(tvOS) || os(visionOS)
import UIKit

extension ColorResource {
extension RColorResource {

/**
Returns the color from this resource (`R.color.*`) that is compatible with the trait collection.
Expand All @@ -51,7 +51,7 @@ extension UIColor {

- returns: A color that exactly or best matches the desired traits with the given resource (`R.color.*`), or nil if no suitable color was found.
*/
public convenience init?(resource: ColorResource, compatibleWith traitCollection: UITraitCollection? = nil) {
public convenience init?(resource: RColorResource, compatibleWith traitCollection: UITraitCollection? = nil) {
self.init(named: resource.name, in: resource.bundle, compatibleWith: traitCollection)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@ extension Font {
/**
Create a custom font from this resource (`R.font.*`) and and size that scales with the body text style.
*/
public static func custom(_ resource: FontResource, size: CGFloat) -> Font {
public static func custom(_ resource: RFontResource, size: CGFloat) -> Font {
.custom(resource.name, size: size)
}

/**
Create a custom font from this resource (`R.font.*`) and a fixed size that does not scale with Dynamic Type.
*/
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, visionOS 1, *)
public static func custom(_ resource: FontResource, fixedSize: CGFloat) -> Font {
public static func custom(_ resource: RFontResource, fixedSize: CGFloat) -> Font {
.custom(resource.name, fixedSize: fixedSize)
}

/**
Create a custom font from this resource (`R.font.*`) and and size that is relative to the given `textStyle`.
*/
@available(macOS 11, iOS 14, tvOS 14, watchOS 7, visionOS 1, *)
public static func custom(_ resource: FontResource, size: CGFloat, relativeTo textStyle: Font.TextStyle) -> Font {
public static func custom(_ resource: RFontResource, size: CGFloat, relativeTo textStyle: Font.TextStyle) -> Font {
.custom(resource.name, size: size, relativeTo: textStyle)
}
}

#if canImport(UIKit)
import UIKit

extension FontResource {
extension RFontResource {

/**
Returns the font from this resource (`R.font.*`) at the specified zie.
Expand All @@ -64,7 +64,7 @@ public extension UIFont {

- returns: A font object of the specified font resource and size.
*/
convenience init?(resource: FontResource, size: CGFloat) {
convenience init?(resource: RFontResource, size: CGFloat) {
self.init(name: resource.name, size: size)
}
}
Expand All @@ -74,7 +74,7 @@ public extension UIFont {
#if canImport(UIKit)
import UIKit

extension FontResource {
extension RFontResource {
/**
Returns true if the font can be loaded.
Custom fonts may not be loaded if not properly configured in Info.plist
Expand All @@ -86,7 +86,7 @@ extension FontResource {
#elseif canImport(AppKit)
import AppKit

extension FontResource {
extension RFontResource {
/**
Returns true if the font can be loaded.
Custom fonts may not be loaded if not properly configured in Info.plist
Expand Down
Loading