Skip to content
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

Add Package.swift #1396

Open
wants to merge 2 commits into
base: develop
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ playground.xcworkspace
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
.build/
.swiftpm

# CocoaPods
#
Expand Down
6 changes: 5 additions & 1 deletion Aztec/Classes/Extensions/NSBundle+AztecBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import Foundation

extension Bundle {
@objc public class var aztecBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
let defaultBundle = Bundle(for: EditorView.self)
// If installed with CocoaPods, resources will be in WordPress-Aztec-iOS.bundle
if let bundleURL = defaultBundle.resourceURL,
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("WordPress-Aztec-iOS.bundle")) {
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("WordPress-Aztec-iOS.bundle")) {
return resourceBundle
}
// Otherwise, the default bundle is used for resources
return defaultBundle
#endif
}
}
56 changes: 0 additions & 56 deletions AztecTests/BaseConverters/CLinkedListToArrayConverterTests.swift

This file was deleted.

24 changes: 18 additions & 6 deletions AztecTests/Extensions/UIImageResizeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ class UIImageResizeTests: XCTestCase {
}

func testResizingImageWorks() {
let bundle = Bundle(for: type(of: self))

#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: type(of: self))
#endif

guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else {
XCTFail()
return
Expand Down Expand Up @@ -52,8 +56,12 @@ class UIImageResizeTests: XCTestCase {
}

func testResizingImageWorks2() {
let bundle = Bundle(for: type(of: self))

#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: type(of: self))
#endif

guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else {
XCTFail()
return
Expand Down Expand Up @@ -90,8 +98,12 @@ class UIImageResizeTests: XCTestCase {
}

func testResizingImageWithoutSizeChangeReturnsSameImage() {
let bundle = Bundle(for: type(of: self))

#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: type(of: self))
#endif

guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else {
XCTFail()
return
Expand Down
34 changes: 20 additions & 14 deletions AztecTests/TestingSupport/TextViewStub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,48 @@ import UIKit
@testable import Aztec

class TextViewStub: Aztec.TextView {

let attachmentDelegate = TextViewStubAttachmentDelegate()

// MARK: - Sample HTML Retrieval

static func loadSampleHTML() -> String {
guard let path = Bundle(for: self).path(forResource: "content", ofType: "html"),
let sample = try? String(contentsOfFile: path)
else {
fatalError()
#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: self)
#endif

guard let path = bundle.path(forResource: "content", ofType: "html"),
let sample = try? String(contentsOfFile: path)
else {
fatalError()
}

return sample
}

init(withHTML html: String? = nil, font: UIFont = .systemFont(ofSize: 14), pasteboard: UIPasteboard = .forTesting) {
super.init(
defaultFont: font,
defaultMissingImage: UIImage())

textAttachmentDelegate = attachmentDelegate
registerAttachmentImageProvider(attachmentDelegate)

if let html = html {
setHTML(html)
}

self.pasteboard = pasteboard
}

convenience init(withSampleHTML: Bool) {
let html = withSampleHTML ? TextViewStub.loadSampleHTML() : nil

self.init(withHTML: html)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
Expand Down
37 changes: 37 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// swift-tools-version:5.10

import PackageDescription

let package = Package(
name: "WordPressAztecEditor",
platforms: [.iOS(.v11)],
products: [
.library(name: "Aztec", targets: ["Aztec"]),
.library(name: "WordPressEditor", targets: ["WordPressEditor"]),
],
targets: [
.target(
name: "Aztec",
path: "Aztec",
resources: [.process("Assets")]
),
.target(
name: "WordPressEditor",
dependencies: ["Aztec"],
path: "WordPressEditor/WordPressEditor"
),
.testTarget(
name: "AztecTests",
dependencies: ["Aztec"],
path: "AztecTests",
resources: [.process("Resources")]
),
.testTarget(
name: "WordPressEditorTests",
dependencies: ["Aztec", "WordPressEditor"],
path: "WordPressEditor/WordPressEditorTests",
resources: [.process("Resources")]
)
],
swiftLanguageVersions: [.v5]
)
104 changes: 0 additions & 104 deletions WordPressEditor/WordPressEditorTests/GutenbergPreProcessorTests.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ class GutenpackAttachmentRendererTests: XCTestCase {
// We no longer support 1x
fatalError()
}()

let bundle = Bundle(for: type(of: self))

#if SWIFT_PACKAGE
let bundle = Bundle.module
#else
let bundle = Bundle(for: type(of: self))
#endif
guard let url = bundle.url(forResource: fileName, withExtension: "png", subdirectory: nil),
let expectedPNGRepresentation = try? Data(contentsOf: url, options: []) else {
XCTFail()
Expand Down