Skip to content

Commit a922952

Browse files
committed
Define package dependency to host HTML resources
1 parent 704fbbd commit a922952

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ build: npm-dependencies prep-translations ## Build the project for all platforms
7676
@echo "--- :open_file_folder: Copying Build Products into place"
7777
rm -rf ./ios/Sources/GutenbergKit/Gutenberg/ ./android/Gutenberg/src/main/assets/
7878
cp -r ./dist/. ./ios/Sources/GutenbergKit/Gutenberg/
79+
cp -r ./dist/. ./ios/Sources/GutenbergKitResources/Resources/
7980
cp -r ./dist/. ./android/Gutenberg/src/main/assets
8081

8182
.PHONY: build-swift-package

Package.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ let package = Package(
1616
targets: [
1717
.target(
1818
name: "GutenbergKit",
19-
dependencies: ["SwiftSoup", "SVGView"],
19+
dependencies: [
20+
"SwiftSoup",
21+
"SVGView",
22+
.target(name: "GutenbergKitResources")
23+
],
2024
path: "ios/Sources/GutenbergKit",
2125
exclude: [],
2226
resources: [.copy("Gutenberg")]
@@ -29,6 +33,12 @@ let package = Package(
2933
resources: [
3034
.process("Resources")
3135
]
36+
),
37+
38+
.target(
39+
name: "GutenbergKitResources",
40+
path: "ios/Sources/GutenbergKitResources",
41+
resources: [.copy("Resources")]
3242
)
3343
]
3444
)

ios/Sources/GutenbergKitResources/Resources/.gitkeep

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
struct GutenbergKitResources {
4+
5+
/// Loads the Gutenberg CSS from the bundled assets.
6+
public static func loadGutenbergCSS() -> String? {
7+
guard let assetsURL = Bundle.module.url(forResource: "Gutenberg", withExtension: nil) else {
8+
assertionFailure("Gutenberg resource not found in bundle")
9+
return nil
10+
}
11+
12+
let assetsDirectory = assetsURL.appendingPathComponent("assets")
13+
guard let files = try? FileManager.default.contentsOfDirectory(at: assetsDirectory, includingPropertiesForKeys: nil),
14+
let cssURL = files.first(where: { $0.lastPathComponent.hasPrefix("index-") && $0.lastPathComponent.hasSuffix(".css") }),
15+
let css = try? String(contentsOf: cssURL, encoding: .utf8) else {
16+
assertionFailure("Failed to load Gutenberg CSS from bundle")
17+
return nil
18+
}
19+
return css
20+
}
21+
}

0 commit comments

Comments
 (0)