Skip to content

Commit 601a9a8

Browse files
jkmasseldcalhoun
andauthored
Add Configuration Builder (and tests) (#146)
* Add EditorConfigurationBuilder * Add EditorConfigurationBuilderTests * Make Test Suite run on macOS * docs: Document all editor configuration options * test: Expand builder tests * test: Fix EditorManifestTests for macOS runs Apply iOS conditionals used in other, existing code. * ci: Revert Swift test script device configuration removal This was changed while making the tests pass when running on macOS, but it is unclear why the original CI script was changed. Presumably we should run the tests with a fixed device on the CI. debc1c7#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L62 * test: Remove builder cookie assertions This functionality was removed in the trunk branch. --------- Co-authored-by: David Calhoun <[email protected]>
1 parent 45713f4 commit 601a9a8

12 files changed

+684
-63
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ lint-js: npm-dependencies
4747
test-js: npm-dependencies
4848
npm run test -- run
4949

50+
lint-swift:
51+
swift package plugin swiftlint
52+
5053
local-android-library: build
5154
echo "--- :android: Building Library"
5255
./android/gradlew -p ./android :gutenberg:publishToMavenLocal -exclude-task prepareToPublishToS3

ios/Demo-iOS/Sources/ContentView.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,20 @@ struct ContentView: View {
6666
private extension EditorConfiguration {
6767

6868
static var template: Self {
69-
var configuration = EditorConfiguration.default
70-
71-
#warning("1. Update the property values below")
69+
#warning("1. Update the siteURL and authHeader values below")
7270
#warning("2. Install the Jetpack plugin to the site")
73-
configuration.siteURL = "https://modify-me.com"
74-
configuration.authHeader = "Insert the Authorization header value here"
71+
let siteUrl: String = "https://modify-me.com"
72+
let authHeader: String = "Insert the Authorization header value here"
73+
let siteApiRoot: String = "\(siteUrl)/wp-json/"
7574

76-
// DO NOT CHANGE the properties below
77-
configuration.siteApiRoot = "\(configuration.siteURL)/wp-json/"
78-
configuration.editorAssetsEndpoint = URL(string: configuration.siteApiRoot)!.appendingPathComponent("wpcom/v2/editor-assets")
79-
// The `plugins: true` is necessary for the editor to use 'remote.html'
80-
configuration.plugins = true
75+
let configuration = EditorConfigurationBuilder()
76+
.setSiteUrl(siteUrl)
77+
.setAuthHeader(authHeader)
78+
.setSiteApiRoot(siteApiRoot)
79+
.setEditorAssetsEndpoint(URL(string: siteApiRoot)!.appendingPathComponent("wpcom/v2/editor-assets"))
80+
.setShouldUsePlugins(true)
8181

82-
return configuration
82+
return configuration.build()
8383
}
8484

8585
}

ios/Sources/GutenbergKit/Sources/Cache/EditorAssetsLibrary.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ struct EditorAssetsMainifest: Codable {
245245
for script in try document.select("script[src]") {
246246
if let src = try? script.attr("src") {
247247
let link = Self.resolveAssetLink(src, defaultScheme: defaultScheme)
248+
#if canImport(UIKit)
248249
let newLink = CachedAssetSchemeHandler.cachedURL(forWebLink: link) ?? link
250+
#else
251+
let newLink = link
252+
#endif
249253
try script.attr("src", newLink)
250254
}
251255
}
@@ -268,7 +272,11 @@ struct EditorAssetsMainifest: Codable {
268272
for stylesheet in try document.select(#"link[rel="stylesheet"][href]"#) {
269273
if let href = try? stylesheet.attr("href") {
270274
let link = Self.resolveAssetLink(href, defaultScheme: defaultScheme)
275+
#if canImport(UIKit)
271276
let newLink = CachedAssetSchemeHandler.cachedURL(forWebLink: link) ?? link
277+
#else
278+
let newLink = link
279+
#endif
272280
try stylesheet.attr("href", newLink)
273281
}
274282
}

ios/Sources/GutenbergKit/Sources/EditorBlockPicker.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import SwiftUI
22

3+
#if canImport(UIKit)
34
// TODO: Add search
45
// TODO: Group these properly
56
struct EditorBlockPicker: View {
@@ -217,3 +218,4 @@ struct EditorBlockPickerSection: Identifiable {
217218
let name: String
218219
let blockTypes: [EditorBlockType]
219220
}
221+
#endif

0 commit comments

Comments
 (0)