feat: Begins vapor application, begins view controller.
This commit is contained in:
43
Sources/ViewController/Interface.swift
Normal file
43
Sources/ViewController/Interface.swift
Normal file
@@ -0,0 +1,43 @@
|
||||
import Dependencies
|
||||
import DependenciesMacros
|
||||
import Elementary
|
||||
import Logging
|
||||
import ManualDCore
|
||||
|
||||
extension DependencyValues {
|
||||
public var viewController: ViewController {
|
||||
get { self[ViewController.self] }
|
||||
set { self[ViewController.self] = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
public typealias AnySendableHTML = (any HTML & Sendable)
|
||||
|
||||
@DependencyClient
|
||||
public struct ViewController: Sendable {
|
||||
public var view: @Sendable (Request) async throws -> AnySendableHTML
|
||||
}
|
||||
|
||||
extension ViewController {
|
||||
|
||||
public struct Request: Sendable {
|
||||
|
||||
public let route: SiteRoute.View
|
||||
public let isHtmxRequest: Bool
|
||||
public let logger: Logger
|
||||
|
||||
public init(
|
||||
route: SiteRoute.View,
|
||||
isHtmxRequest: Bool,
|
||||
logger: Logger
|
||||
) {
|
||||
self.route = route
|
||||
self.isHtmxRequest = isHtmxRequest
|
||||
self.logger = logger
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ViewController: TestDependencyKey {
|
||||
public static let testValue = Self()
|
||||
}
|
||||
25
Sources/ViewController/Views/MainPage.swift
Normal file
25
Sources/ViewController/Views/MainPage.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
import Elementary
|
||||
|
||||
public struct MainPage<Inner: HTML>: SendableHTMLDocument where Inner: Sendable {
|
||||
public var title: String { "Manual-D" }
|
||||
public var lang: String { "en" }
|
||||
let inner: Inner
|
||||
|
||||
init(_ inner: () -> Inner) {
|
||||
self.inner = inner()
|
||||
}
|
||||
|
||||
public var head: some HTML {
|
||||
meta(.charset(.utf8))
|
||||
script(.src("https://unpkg.com/htmx.org@2.0.8")) {}
|
||||
script(.src("/js/main.js")) {}
|
||||
link(.rel(.stylesheet), .href("/css/main.css"))
|
||||
link(.rel(.icon), .href("/images/favicon.ico"), .custom(name: "type", value: "image/x-icon"))
|
||||
}
|
||||
|
||||
public var body: some HTML {
|
||||
inner
|
||||
}
|
||||
}
|
||||
|
||||
public protocol SendableHTMLDocument: HTMLDocument, Sendable {}
|
||||
Reference in New Issue
Block a user