sliemeobn / elementary

A modern and efficient HTML rendering library - inspired by SwiftUI, built for the web.
https://swiftpackageindex.com/sliemeobn/elementary
Apache License 2.0
145 stars 6 forks source link

Various issues with Hummingbird integration #57

Open maclong9 opened 11 hours ago

maclong9 commented 11 hours ago

I pretty much pulled it straight from the examples:

import Elementary
import HummingbirdElementary

extension MainLayout: Sendable where Body: Sendable {}
struct MainLayout<Body: HTML>: HTMLDocument {
    var title: String
    @HTMLBuilder var pageContent: Body

    var head: some HTML {
        meta(.charset(.utf8))
        meta(.name(.viewport), .content("width=device-width, initial-scale=1.0"))
        HTMLComment("Do not use this in production, use the tailwind CLI to generate a production build from your swift files.")
        script(.src("https://cdn.tailwindcss.com")) {}
    }

    var body: some HTML {
        div(.class("flex flex-col min-h-screen items-center font-mono bg-zinc-300")) {
            div(.class("bg-zinc-50 m-12 p-12 rounded-lg shadow-md gap-4")) {
                h1(.class("text-3xl pb-6 mx-auto")) { title }
                main {
                    pageContent
                }
            }
        }
    }
}

The above file has the following errors:

5: Type 'Body' constrained to non-protocol, non-class type 'HTML'
9: A 'some' type must specify only 'Any', 'AnyObject', protocols, and/or a base class
10, 11, 12, 13: Result of 'HTMLVoidElement<Tag>' initializer is unused
16: A 'some' type must specify only 'Any', 'AnyObject', protocols, and/or a base class

Here is my Package.swift

// swift-tools-version:6.0
import PackageDescription

let package = Package(
    name: "swift-todos",
    platforms: [
        .macOS(.v14)
    ],
    dependencies: [
        .package(url: "https://github.com/sliemeobn/elementary.git", from: "0.4.1"),
        .package(url: "https://github.com/hummingbird-community/hummingbird-elementary.git", from: "0.4.0"),

        .package(url: "https://github.com/vapor/fluent-kit.git", from: "1.48.5"),
        .package(url: "https://github.com/vapor/fluent-sqlite-driver.git", from: "4.7.0"),
        .package(
            url: "https://github.com/hummingbird-project/hummingbird-auth.git",
            from: "2.0.0-rc.5"
        ),
        .package(
            url: "https://github.com/hummingbird-project/hummingbird-compression.git",
            from: "2.0.0-rc"
        ),
        .package(
            url: "https://github.com/hummingbird-project/hummingbird-fluent.git",
            from: "2.0.0-beta.2"
        ),
        .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.3.0"),
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.4.0"),
    ],
    targets: [
        .executableTarget(
            name: "App",
            dependencies: [
                .product(name: "Elementary", package: "elementary"),
                .product(name: "HummingbirdElementary", package: "hummingbird-elementary"),

                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                .product(name: "Bcrypt", package: "hummingbird-auth"),
                .product(name: "FluentKit", package: "fluent-kit"),
                .product(name: "FluentSQLiteDriver", package: "fluent-sqlite-driver"),
                .product(name: "Hummingbird", package: "hummingbird"),
                .product(name: "HummingbirdAuth", package: "hummingbird-auth"),
                .product(name: "HummingbirdBasicAuth", package: "hummingbird-auth"),
                .product(name: "HummingbirdCompression", package: "hummingbird-compression"),
                .product(name: "HummingbirdFluent", package: "hummingbird-fluent"),
            ],
            swiftSettings: [
                .unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))
            ]
        ),
        .testTarget(
            name: "AppTests",
            dependencies: [
                .byName(name: "App"),
                .product(name: "HummingbirdAuthTesting", package: "hummingbird-auth"),
                .product(name: "HummingbirdTesting", package: "hummingbird"),
            ]
        ),
    ]
)
sliemeobn commented 10 hours ago

hmm.... the code looks fine on first look.

my best guess would be that you have defined your own HTML type in the App module somewhere that shadows the Elementary.HTML protocol.

can we rule that out before we dig deeper?