Skip to content

Add Configuration Builder (and tests) #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ lint-js: npm-dependencies
test-js: npm-dependencies
npm run test -- run

lint-swift:
swift package plugin swiftlint

local-android-library: build
echo "--- :android: Building Library"
./android/gradlew -p ./android :gutenberg:publishToMavenLocal -exclude-task prepareToPublishToS3
Expand Down
22 changes: 11 additions & 11 deletions ios/Demo-iOS/Sources/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ struct ContentView: View {
private extension EditorConfiguration {

static var template: Self {
var configuration = EditorConfiguration.default

#warning("1. Update the property values below")
#warning("1. Update the siteURL and authHeader values below")
#warning("2. Install the Jetpack plugin to the site")
configuration.siteURL = "https://modify-me.com"
configuration.authHeader = "Insert the Authorization header value here"
let siteUrl: String = "https://modify-me.com"
let authHeader: String = "Insert the Authorization header value here"
let siteApiRoot: String = "\(siteUrl)/wp-json/"

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

return configuration
return configuration.build()
}

}
Expand Down
13 changes: 13 additions & 0 deletions ios/Sources/GutenbergKit/Sources/EditorAssetsLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import Foundation
import CryptoKit
import SwiftSoup

#if canImport(UIKit)
import UIKit

public actor EditorAssetsLibrary {
enum ManifestError: Error {
case unavailable
Expand Down Expand Up @@ -166,6 +169,8 @@ private extension String {
}
}

#endif

struct EditorAssetsMainifest: Codable {
var scripts: String
var styles: String
Expand Down Expand Up @@ -220,7 +225,11 @@ struct EditorAssetsMainifest: Codable {
for script in try document.select("script[src]") {
if let src = try? script.attr("src") {
let link = Self.resolveAssetLink(src, defaultScheme: defaultScheme)
#if canImport(UIKit)
let newLink = CachedAssetSchemeHandler.cachedURL(forWebLink: link) ?? link
#else
let newLink = link
#endif
try script.attr("src", newLink)
}
}
Expand All @@ -243,7 +252,11 @@ struct EditorAssetsMainifest: Codable {
for stylesheet in try document.select(#"link[rel="stylesheet"][href]"#) {
if let href = try? stylesheet.attr("href") {
let link = Self.resolveAssetLink(href, defaultScheme: defaultScheme)
#if canImport(UIKit)
let newLink = CachedAssetSchemeHandler.cachedURL(forWebLink: link) ?? link
#else
let newLink = link
#endif
try stylesheet.attr("href", newLink)
}
}
Expand Down
2 changes: 2 additions & 0 deletions ios/Sources/GutenbergKit/Sources/EditorBlockPicker.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI

#if canImport(UIKit)
// TODO: Add search
// TODO: Group these properly
struct EditorBlockPicker: View {
Expand Down Expand Up @@ -217,3 +218,4 @@ struct EditorBlockPickerSection: Identifiable {
let name: String
let blockTypes: [EditorBlockType]
}
#endif
Loading