mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 08:20:59 +00:00
Split Models from Network package
This commit is contained in:
parent
4742e3112b
commit
202bf06dc6
12 changed files with 75 additions and 14 deletions
|
@ -17,6 +17,7 @@
|
|||
/* Begin PBXFileReference section */
|
||||
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>"; };
|
||||
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; };
|
||||
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>"; };
|
||||
|
@ -43,6 +44,7 @@
|
|||
9FBFE63B292A715500C250E9 /* IceCubesApp */,
|
||||
9FBFE63A292A715500C250E9 /* Products */,
|
||||
9FBFE64C292A72BD00C250E9 /* Frameworks */,
|
||||
9F398AA32935F90100A889F2 /* Models */,
|
||||
9F29553E292B6AF600E0E81B /* Timeline */,
|
||||
9F29553D292B67B600E0E81B /* Network */,
|
||||
);
|
||||
|
|
9
Packages/Models/.gitignore
vendored
Normal file
9
Packages/Models/.gitignore
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/config/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
27
Packages/Models/Package.swift
Normal file
27
Packages/Models/Package.swift
Normal 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"]),
|
||||
]
|
||||
)
|
3
Packages/Models/README.md
Normal file
3
Packages/Models/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Models
|
||||
|
||||
A description of this package.
|
|
@ -2,6 +2,20 @@ import HTML2Markdown
|
|||
import Foundation
|
||||
|
||||
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 {
|
||||
do {
|
||||
let dom = try HTMLParser().parse(html: content)
|
||||
|
@ -12,16 +26,10 @@ extension Status {
|
|||
}
|
||||
|
||||
public var createdAtDate: Date {
|
||||
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.date(from: createdAt)!
|
||||
Self.createdAtDateFormatter.date(from: createdAt)!
|
||||
}
|
||||
|
||||
public var createdAtFormatted: String {
|
||||
let dateFormatter = RelativeDateTimeFormatter()
|
||||
dateFormatter.unitsStyle = .abbreviated
|
||||
return dateFormatter.localizedString(for: createdAtDate, relativeTo: Date())
|
||||
Self.createdAtRelativeFormatter.localizedString(for: createdAtDate, relativeTo: Date())
|
||||
}
|
||||
}
|
11
Packages/Models/Tests/ModelsTests/ModelsTests.swift
Normal file
11
Packages/Models/Tests/ModelsTests/ModelsTests.swift
Normal 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!")
|
||||
}
|
||||
}
|
|
@ -13,13 +13,11 @@ let package = Package(
|
|||
name: "Network",
|
||||
targets: ["Network"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://gitlab.com/mflint/HTML2Markdown", exact: "1.0.0")
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(
|
||||
name: "Network",
|
||||
dependencies: ["HTML2Markdown"]),
|
||||
dependencies: []),
|
||||
.testTarget(
|
||||
name: "NetworkTests",
|
||||
dependencies: ["Network"]),
|
||||
|
|
|
@ -15,12 +15,14 @@ let package = Package(
|
|||
],
|
||||
dependencies: [
|
||||
.package(name: "Network", path: "../Network"),
|
||||
.package(name: "Models", path: "../Models"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "Timeline",
|
||||
dependencies: [
|
||||
.product(name: "Network", package: "Network")
|
||||
.product(name: "Network", package: "Network"),
|
||||
.product(name: "Models", package: "Models")
|
||||
]),
|
||||
.testTarget(
|
||||
name: "TimelineTests",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import SwiftUI
|
||||
import Network
|
||||
import Models
|
||||
|
||||
struct StatusRowView: View {
|
||||
let status: Status
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import SwiftUI
|
||||
import Network
|
||||
import Models
|
||||
|
||||
@MainActor
|
||||
class TimelineViewModel: ObservableObject {
|
||||
|
|
Loading…
Reference in a new issue