Split Models from Network package

This commit is contained in:
Thomas Ricouard 2022-11-29 09:28:17 +01:00
parent 4742e3112b
commit 202bf06dc6
12 changed files with 75 additions and 14 deletions

View file

@ -17,6 +17,7 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
9F29553D292B67B600E0E81B /* Network */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Network; path = Packages/Network; sourceTree = "<group>"; }; 9F29553D292B67B600E0E81B /* Network */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Network; path = Packages/Network; sourceTree = "<group>"; };
9F29553E292B6AF600E0E81B /* Timeline */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Timeline; path = Packages/Timeline; sourceTree = "<group>"; }; 9F29553E292B6AF600E0E81B /* Timeline */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Timeline; path = Packages/Timeline; sourceTree = "<group>"; };
9F398AA32935F90100A889F2 /* Models */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Models; path = Packages/Models; sourceTree = "<group>"; };
9FBFE639292A715500C250E9 /* IceCubesApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IceCubesApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9FBFE639292A715500C250E9 /* IceCubesApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IceCubesApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
9FBFE63C292A715500C250E9 /* IceCubesAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IceCubesAppApp.swift; sourceTree = "<group>"; }; 9FBFE63C292A715500C250E9 /* IceCubesAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IceCubesAppApp.swift; sourceTree = "<group>"; };
9FBFE640292A715600C250E9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 9FBFE640292A715600C250E9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -43,6 +44,7 @@
9FBFE63B292A715500C250E9 /* IceCubesApp */, 9FBFE63B292A715500C250E9 /* IceCubesApp */,
9FBFE63A292A715500C250E9 /* Products */, 9FBFE63A292A715500C250E9 /* Products */,
9FBFE64C292A72BD00C250E9 /* Frameworks */, 9FBFE64C292A72BD00C250E9 /* Frameworks */,
9F398AA32935F90100A889F2 /* Models */,
9F29553E292B6AF600E0E81B /* Timeline */, 9F29553E292B6AF600E0E81B /* Timeline */,
9F29553D292B67B600E0E81B /* Network */, 9F29553D292B67B600E0E81B /* Network */,
); );

9
Packages/Models/.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

View file

@ -0,0 +1,27 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Models",
platforms: [
.iOS(.v16),
],
products: [
.library(
name: "Models",
targets: ["Models"]),
],
dependencies: [
.package(url: "https://gitlab.com/mflint/HTML2Markdown", exact: "1.0.0")
],
targets: [
.target(
name: "Models",
dependencies: ["HTML2Markdown"]),
.testTarget(
name: "ModelsTests",
dependencies: ["Models"]),
]
)

View file

@ -0,0 +1,3 @@
# Models
A description of this package.

View file

@ -2,6 +2,20 @@ import HTML2Markdown
import Foundation import Foundation
extension Status { extension Status {
private static var createdAtDateFormatter: DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.calendar = .init(identifier: .iso8601)
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
dateFormatter.timeZone = .init(abbreviation: "UTC")
return dateFormatter
}
private static var createdAtRelativeFormatter: RelativeDateTimeFormatter {
let dateFormatter = RelativeDateTimeFormatter()
dateFormatter.unitsStyle = .abbreviated
return dateFormatter
}
public var contentAsMarkdown: String { public var contentAsMarkdown: String {
do { do {
let dom = try HTMLParser().parse(html: content) let dom = try HTMLParser().parse(html: content)
@ -12,16 +26,10 @@ extension Status {
} }
public var createdAtDate: Date { public var createdAtDate: Date {
let dateFormatter = DateFormatter() Self.createdAtDateFormatter.date(from: createdAt)!
dateFormatter.calendar = .init(identifier: .iso8601)
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX"
dateFormatter.timeZone = .init(abbreviation: "UTC")
return dateFormatter.date(from: createdAt)!
} }
public var createdAtFormatted: String { public var createdAtFormatted: String {
let dateFormatter = RelativeDateTimeFormatter() Self.createdAtRelativeFormatter.localizedString(for: createdAtDate, relativeTo: Date())
dateFormatter.unitsStyle = .abbreviated
return dateFormatter.localizedString(for: createdAtDate, relativeTo: Date())
} }
} }

View file

@ -0,0 +1,11 @@
import XCTest
@testable import Models
final class ModelsTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(Models().text, "Hello, World!")
}
}

View file

@ -13,13 +13,11 @@ let package = Package(
name: "Network", name: "Network",
targets: ["Network"]), targets: ["Network"]),
], ],
dependencies: [ dependencies: [],
.package(url: "https://gitlab.com/mflint/HTML2Markdown", exact: "1.0.0")
],
targets: [ targets: [
.target( .target(
name: "Network", name: "Network",
dependencies: ["HTML2Markdown"]), dependencies: []),
.testTarget( .testTarget(
name: "NetworkTests", name: "NetworkTests",
dependencies: ["Network"]), dependencies: ["Network"]),

View file

@ -15,12 +15,14 @@ let package = Package(
], ],
dependencies: [ dependencies: [
.package(name: "Network", path: "../Network"), .package(name: "Network", path: "../Network"),
.package(name: "Models", path: "../Models"),
], ],
targets: [ targets: [
.target( .target(
name: "Timeline", name: "Timeline",
dependencies: [ dependencies: [
.product(name: "Network", package: "Network") .product(name: "Network", package: "Network"),
.product(name: "Models", package: "Models")
]), ]),
.testTarget( .testTarget(
name: "TimelineTests", name: "TimelineTests",

View file

@ -1,5 +1,5 @@
import SwiftUI import SwiftUI
import Network import Models
struct StatusRowView: View { struct StatusRowView: View {
let status: Status let status: Status

View file

@ -1,5 +1,6 @@
import SwiftUI import SwiftUI
import Network import Network
import Models
@MainActor @MainActor
class TimelineViewModel: ObservableObject { class TimelineViewModel: ObservableObject {