First working version.

This commit is contained in:
Shibo Lyu 2025-08-17 17:06:15 +08:00
parent 2f70b79493
commit 8fbeb20900
6 changed files with 227 additions and 2 deletions

View file

@ -0,0 +1,57 @@
import Foundation
public struct Example {
public var htmlInSwiftCode =
"""
<html>
<head>
<title>Example</title>
</head>
<body>
<h1 class="text-2xl">Hello, World!</h1>
<p>This is an example of HTML in Swift code.</p>
</body>
</html>
"""
public func getTestHTML() throws -> String? {
guard let fileURL = Bundle.module.path(forResource: "Test", ofType: "html") else {
return nil
}
return try String(contentsOfFile: fileURL, encoding: .utf8)
}
public func getGeneratedCSS() throws -> String? {
guard
let tailwindCSSBundleURL = Bundle.module.url(
forResource: "TailwindCSS", withExtension: "bundle")
else {
return nil
}
let cssFileURL = tailwindCSSBundleURL.appendingPathComponent("tw.css")
return try String(contentsOf: cssFileURL, encoding: .utf8)
}
public func printAll() {
print("HTML in Swift Code:")
print(htmlInSwiftCode)
print()
print("Test.html:")
if let testHTML = try! getTestHTML() {
print(testHTML)
} else {
print("Test.html not found.")
}
print()
print("Output Tailwind CSS (minified):")
if let generatedCSS = try! getGeneratedCSS() {
print(generatedCSS)
} else {
print("Tailwind CSS not found.")
}
}
}

View file

@ -0,0 +1,7 @@
<html>
<!-- Generated CSS will be avilable in tw.css file in a TailwindCSS.bundle that can be accessed under `Bundle.module`. -->
<link rel="stylesheet" href="/TailwindCSS.bundle/tw.css" />
<body>
<p class="text-[#f05138] font-bold">Hello, Swift!</p>
</body>
</html>

View file

@ -0,0 +1,7 @@
/** SwiftTailwind assumes a Tailwind.css file is present in the root of target directory. **/
/** To align with Swift Package Manager's build plugin capability, SwiftTailwind requires explicitly register all inputs. */
/** You must specify `source(none)` after `tailwindcss` import and add `@source` for each source file / folder you want to include. */
@import "tailwindcss" source(none);
@source "./Example.swift";
@source "./Folder";