Initial commit.

This commit is contained in:
2026-08-19 23:19:08 +02:00
commit 22e737d9c2
153 changed files with 11680 additions and 0 deletions
@@ -0,0 +1,12 @@
import Infrastructure
/// An ``Asset`` with a fixed file name and set of extensions, optionally held in a folder of its own.
struct StubAsset: Asset {
// MARK: Properties
var folder: String? = nil
let fileExtensions: [AssetExtension]
let fileName: String
}
@@ -0,0 +1,26 @@
import Hummingbird
import Infrastructure
/// A ``LocalizedRequestContext`` carrying the core storage and the negotiated language only.
struct StubRequestContext: LocalizedRequestContext {
// MARK: Properties
/// The core request context storage Hummingbird requires.
var coreContext: CoreRequestContextStorage
/// The language identifier negotiated for the request.
var language: String
// MARK: Initializers
/// Creates a request context for the given source.
/// - Parameter source: the source the context is initialized from.
init(
source: Source
) {
self.coreContext = .init(source: source)
self.language = ""
}
}
@@ -0,0 +1,30 @@
import Hummingbird
import Infrastructure
/// A controller serving its path back as plain text, used to observe route registration.
struct StubController {
// MARK: Properties
/// The path the controller serves, also returned as the response body.
let path: String
}
// MARK: - RouterController
extension StubController: RouterController {
// MARK: Properties
var routes: RouteCollection<BasicRequestContext> {
let routes = RouteCollection(context: BasicRequestContext.self)
routes.get(.init(path)) { _, _ in
self.path
}
return routes
}
}
@@ -0,0 +1,14 @@
import Testing
extension Tag {
/// Tests exercising the asset scaffolding of the Infrastructure package.
@Tag static var asset: Tag
/// Tests exercising an extension of the Infrastructure package.
@Tag static var `extension`: Tag
/// Tests exercising a middleware of the Infrastructure package.
@Tag static var middleware: Tag
/// Tests exercising a protocol scaffolding of the Infrastructure package.
@Tag static var `protocol`: Tag
/// Tests exercising a type of the Infrastructure package.
@Tag static var type: Tag
}
@@ -0,0 +1,101 @@
import Elementary
import Foundation
import Infrastructure
/// A ``Page`` with fixed content, metadata, and stub assets.
struct StubPage: Page {
// MARK: Properties
/// The analytics tracker rendered as a deferred script in the document head, or `nil` to omit it.
let analytics: Analytics?
/// The version token appended to the page's asset URLs, or `nil` to leave them unversioned.
let assetVersion: String?
/// The canonical URL rendered in the document head, or `nil` to omit it.
let canonicalURL: String?
/// The locale the page content is localized to.
let locale: Locale
/// The card rendered as link-preview tags in the document head, or `nil` to omit them.
let socialCard: SocialCard?
/// The structured data rendered as a JSON-LD script in the document head, or `nil` to omit it.
let structuredData: StructuredData?
/// The summary rendered in the document head, or `nil` to omit it.
let summary: String?
// MARK: Initializers
/// Creates a stub page.
/// - Parameters:
/// - locale: the locale the page content is localized to. Defaults to `en`.
/// - assetVersion: the version token appended to the page's asset URLs, or `nil` (the
/// default) to leave them unversioned.
/// - canonicalURL: the canonical URL rendered in the document head, or `nil` (the default)
/// to omit it.
/// - analytics: the analytics tracker rendered as a deferred script in the document head,
/// or `nil` (the default) to omit it.
/// - socialCard: the card rendered as link-preview tags in the document head, or `nil`
/// (the default) to omit them.
/// - structuredData: the structured data rendered as a JSON-LD script in the document
/// head, or `nil` (the default) to omit it.
/// - summary: the summary rendered in the document head, or `nil` (the default)
/// to omit it.
init(
locale: Locale = .init(identifier: "en"),
assetVersion: String? = nil,
canonicalURL: String? = nil,
analytics: Analytics? = nil,
socialCard: SocialCard? = nil,
structuredData: StructuredData? = nil,
summary: String? = nil
) {
self.analytics = analytics
self.assetVersion = assetVersion
self.canonicalURL = canonicalURL
self.locale = locale
self.socialCard = socialCard
self.structuredData = structuredData
self.summary = summary
}
// MARK: Computed
var content: some HTML {
p { "Stub content" }
}
var lang: String {
locale.language.languageCode?.identifier ?? "en"
}
var metadata: some HTML {
meta(
.name("stub"),
.content("marker")
)
}
var scripts: [any Asset] {
[StubAsset(
fileExtensions: [.css, .js],
fileName: "stub"
)]
}
var stylesheets: [any Asset] {
[StubAsset(
fileExtensions: [.css, .js],
fileName: "stub"
)]
}
var title: String {
"Stub Page"
}
}