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

Add support for selecting a different bundle #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 10 additions & 6 deletions Sources/AckGen/Acknowledgement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ public struct Acknowledgement: Codable {
self.license = license
}


/// <#Description#>
/// - Parameter plistName: the property list's filename without extension
/// - Returns: Array of objects containing title and
public static func all(fromPlist plistName: String = "Acknowledgements") -> [Acknowledgement] {
guard let path = Bundle.main.path(forResource: plistName, ofType: "plist"),
/// Fetch all the acknowledgements from the acknowledgement property list's file.
/// - Parameters:
/// - plistName: the property list's filename without extension. Default to `Acknowledgements`.
/// - bundle: the bundle where the plist file is located. Default to the main bundle.
/// - Returns: Array of objects containing title and licence.
public static func all(
fromPlist plistName: String = "Acknowledgements",
in bundle: Bundle = .main
) -> [Acknowledgement] {
guard let path = bundle.path(forResource: plistName, ofType: "plist"),
let xml = FileManager.default.contents(atPath: path),
let acks = try? PropertyListDecoder().decode([Acknowledgement].self, from: xml) else { return [] }
return acks.sorted(by: { $0.title.lowercased() < $1.title.lowercased() })
Expand Down
5 changes: 4 additions & 1 deletion Sources/AckGenUI/AcknowledgementsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ public struct AcknowledgementsList: View {

private let title: String
private let plistName: String
private let bundle: Bundle
private let otherAcknowledgements: [Acknowledgement]

public init(
title: String = "Acknowledgements",
plistName: String = "Acknowledgements",
bundle: Bundle = .main,
otherAcknowledgements: [AckGen.Acknowledgement] = []
) {
self.title = title
self.plistName = plistName
self.bundle = bundle
self.otherAcknowledgements = otherAcknowledgements
}

Expand All @@ -35,7 +38,7 @@ public struct AcknowledgementsList: View {
}
.customNavigationTitle(title)
.onAppear {
self.acknowledgements = (Acknowledgement.all(fromPlist: plistName) + otherAcknowledgements).sorted()
self.acknowledgements = (Acknowledgement.all(fromPlist: plistName, in: bundle) + otherAcknowledgements).sorted()
}
}
}
Expand Down