11import Foundation
22
3- struct Plist2HTML {
4-
5- enum HTMLStyle : String {
6- case light
7- case dark
8- }
9-
10- private let style : HTMLStyle
11-
12- init ( with style: HTMLStyle ) {
13- self . style = style
14- }
15-
16- private static let whiteHTMLColor = " white "
17- private static let blackHTMLColor = " black "
3+ enum Plist2HTML {
184
195 private static let blankLine = " <br> "
206 private static let ackKey = " PreferenceSpecifiers "
217 private static let titleKey = " Title "
228 private static let licenseKey = " License "
239 private static let footerKey = " FooterText "
2410
25- private var textColor : String {
26- return ( self . style == . light) ? Plist2HTML . blackHTMLColor : Plist2HTML . whiteHTMLColor
27- }
28-
29- private var backgroundColor : String {
30- return ( self . style == . light) ? Plist2HTML . whiteHTMLColor : Plist2HTML . blackHTMLColor
31- }
32-
3311 /// Transforms the plist file containing the acknowledgments into an HTML
3412 /// - Parameter url: URL pointing to acknowledgments file
35- func transformPlistFile( from url: URL ) -> String {
13+ static func transformPlistFile( from url: URL ) -> String {
3614 guard
3715 let plistDict = NSDictionary ( contentsOfFile: url. path) ,
3816 let acknowledgmentsMultiList = plistDict [ Plist2HTML . ackKey] as? NSArray else {
@@ -48,51 +26,59 @@ struct Plist2HTML {
4826 }
4927
5028 if let _title = ackDict [ Plist2HTML . titleKey] as? String {
51- htmlString += self . header ( with: _title)
29+ htmlString += Plist2HTML . header ( with: _title)
5230 }
5331
5432 if let _license = ackDict [ Plist2HTML . licenseKey] as? String {
55- htmlString += self . subheader ( with: _license)
33+ htmlString += Plist2HTML . subheader ( with: _license)
5634 }
5735
5836 if let _footerText = ackDict [ Plist2HTML . footerKey] as? String {
59- htmlString += self . paragraph ( with: _footerText. replacingOccurrences ( of: " \n " , with: Plist2HTML . blankLine) )
37+ htmlString += Plist2HTML . paragraph ( with: _footerText. replacingOccurrences ( of: " \n " , with: Plist2HTML . blankLine) )
6038 }
6139
6240 htmlString += Plist2HTML . blankLine
6341 }
6442
65- return self . body ( with: htmlString)
43+ return Plist2HTML . body ( with: htmlString)
6644 }
6745
6846 // MARK: - Helpers
6947
70- private func body( with content: String ) -> String {
71- let fullBody = ( " <body style= \" background-color: \( self . backgroundColor ) ; \" > " + content + " </body> " )
48+ private static func body( with content: String ) -> String {
49+ let fullBody = ( " <body> " + content + " </body> " )
7250
7351 let style = """
74- <style> html, body { font-family: Calibri, " PT Sans " , sans-serif; padding: 15px; }
75- ol {
76- padding-left: 15px;
77- }
78- li {
79- font-size: 16px;
80- }
81- </style>
52+ <style> html, body { font-family: Calibri, " PT Sans " , sans-serif; padding: 15px; }
53+ ol {
54+ padding-left: 15px;
55+ }
56+ li {
57+ font-size: 16px;
58+ }
59+ @media (prefers-color-scheme: dark) {
60+ body {
61+ background: #333;
62+ color: #fff;
63+ }
64+ a {
65+ color:#999;
66+ }
67+ }
68+ </style>
8269 """
83-
8470 return ( fullBody + style)
8571 }
8672
87- private func header( with title: String ) -> String {
88- return ( " <h1 style= \" color: \( self . textColor ) ; \" > " + title + " </h1> " )
73+ private static func header( with title: String ) -> String {
74+ return ( " <h1> " + title + " </h1> " )
8975 }
9076
91- private func subheader( with subtitle: String ) -> String {
92- return ( " <h3 style= \" color: \( self . textColor ) ; \" > " + subtitle + " </h3> " )
77+ private static func subheader( with subtitle: String ) -> String {
78+ return ( " <h3> " + subtitle + " </h3> " )
9379 }
9480
95- private func paragraph( with text: String ) -> String {
96- return ( " <p style= \" color: \( self . textColor ) ; \" > " + text + " </p> " )
81+ private static func paragraph( with text: String ) -> String {
82+ return ( " <p> " + text + " </p> " )
9783 }
9884}
0 commit comments