From aaeb244cebca98ac860767b62f2b94f89999458e Mon Sep 17 00:00:00 2001 From: Allen Humphreys Date: Sun, 3 Dec 2023 19:14:42 -0500 Subject: [PATCH] Support SPM installation --- .../contents.xcworkspacedata | 7 + .../xcshareddata/xcschemes/Aztec.xcscheme | 66 +++++++++ ...WordPress-AztecEditor-iOS-Package.xcscheme | 130 ++++++++++++++++++ .../xcschemes/WordPressEditor.xcscheme | 66 +++++++++ Aztec.xcodeproj/project.pbxproj | 3 +- .../Extensions/NSBundle+AztecBundle.swift | 4 + .../CLinkedListToArrayConverterTests.swift | 56 -------- .../BoldElementAttributeConverterTests.swift | 0 ...ItalicElementAttributeConverterTests.swift | 0 ...erlineElementAttributeConverterTests.swift | 0 .../GenericElementConverterTests.swift | 0 .../BoldStringAttributeConverterTests.swift | 0 .../ItalicStringAttributeConverterTests.swift | 0 ...derlineStringAttributeConverterTests.swift | 0 .../Extensions/UIImageResizeTests.swift | 9 +- .../NSBundle+AztecTestsBundle.swift | 11 ++ AztecTests/TestingSupport/TextViewStub.swift | 2 +- CHANGELOG.md | 2 +- Package.swift | 63 +++++++++ README.md | 32 +++++ .../GutenbergPreProcessorTests.swift | 104 -------------- .../GutenpackAttachmentRendererTests.swift | 4 + 22 files changed, 390 insertions(+), 169 deletions(-) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/Aztec.xcscheme create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/WordPress-AztecEditor-iOS-Package.xcscheme create mode 100644 .swiftpm/xcode/xcshareddata/xcschemes/WordPressEditor.xcscheme delete mode 100644 AztecTests/BaseConverters/CLinkedListToArrayConverterTests.swift rename AztecTests/{New Group => Converters}/AttributesToStringAttributes/BoldElementAttributeConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/AttributesToStringAttributes/ItalicElementAttributeConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/AttributesToStringAttributes/UnderlineElementAttributeConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/ElementToAttributedString/GenericElementConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/StringAttributesToAttributes/BoldStringAttributeConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/StringAttributesToAttributes/ItalicStringAttributeConverterTests.swift (100%) rename AztecTests/{New Group => Converters}/StringAttributesToAttributes/UnderlineStringAttributeConverterTests.swift (100%) create mode 100644 AztecTests/TestingSupport/NSBundle+AztecTestsBundle.swift create mode 100644 Package.swift delete mode 100644 WordPressEditor/WordPressEditorTests/GutenbergPreProcessorTests.swift diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/Aztec.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/Aztec.xcscheme new file mode 100644 index 000000000..588fe4008 --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/Aztec.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/WordPress-AztecEditor-iOS-Package.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/WordPress-AztecEditor-iOS-Package.xcscheme new file mode 100644 index 000000000..66468feec --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/WordPress-AztecEditor-iOS-Package.xcscheme @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.swiftpm/xcode/xcshareddata/xcschemes/WordPressEditor.xcscheme b/.swiftpm/xcode/xcshareddata/xcschemes/WordPressEditor.xcscheme new file mode 100644 index 000000000..fd4882afc --- /dev/null +++ b/.swiftpm/xcode/xcshareddata/xcschemes/WordPressEditor.xcscheme @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Aztec.xcodeproj/project.pbxproj b/Aztec.xcodeproj/project.pbxproj index 5042b71ff..fcb3e0522 100644 --- a/Aztec.xcodeproj/project.pbxproj +++ b/Aztec.xcodeproj/project.pbxproj @@ -967,8 +967,7 @@ F1DC21B22199D58B007C189E /* ElementToAttributedString */, F1E75630215B0C9E004BC254 /* StringAttributesToAttributes */, ); - name = Converters; - path = "New Group"; + path = Converters; sourceTree = ""; }; F126ADC521553E25008F7DD1 /* AttributesToStringAttributes */ = { diff --git a/Aztec/Classes/Extensions/NSBundle+AztecBundle.swift b/Aztec/Classes/Extensions/NSBundle+AztecBundle.swift index ae7105590..b686abd5e 100644 --- a/Aztec/Classes/Extensions/NSBundle+AztecBundle.swift +++ b/Aztec/Classes/Extensions/NSBundle+AztecBundle.swift @@ -2,6 +2,9 @@ import Foundation extension Bundle { @objc public class var aztecBundle: Bundle { +#if SPM + return .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, @@ -10,5 +13,6 @@ extension Bundle { } // Otherwise, the default bundle is used for resources return defaultBundle +#endif } } diff --git a/AztecTests/BaseConverters/CLinkedListToArrayConverterTests.swift b/AztecTests/BaseConverters/CLinkedListToArrayConverterTests.swift deleted file mode 100644 index e0603b8aa..000000000 --- a/AztecTests/BaseConverters/CLinkedListToArrayConverterTests.swift +++ /dev/null @@ -1,56 +0,0 @@ -import XCTest -@testable import Aztec - -class CLinkedListToArrayConverterTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - struct TestStruct { - var name: String - var next: UnsafeMutablePointer - } - - class TestClass { - let name: String - - init(name: String) { - self.name = name - } - } - - class TestStructToClassConverter: SafeConverter { - func convert(input: TestStruct) -> TestClass { - let testClass = TestClass(name: input.name) - return testClass - } - } - - func testConversion() { - var struct4 = TestStruct(name: "Struct 4", next: nil) - var struct3 = TestStruct(name: "Struct 3", next: &struct4) - var struct2 = TestStruct(name: "Struct 2", next: &struct3) - var struct1 = TestStruct(name: "Struct 1", next: &struct2) - - // Useful for the final comparison. - let structArray = [struct1, struct2, struct3, struct4] - - let elementConverter = TestStructToClassConverter() - let listToArrayConverter = SafeCLinkedListToArrayConverter(elementConverter: elementConverter, next: { return $0.next }) - - let array = listToArrayConverter.convert(&struct1) - - XCTAssertEqual(array.count, structArray.count) - - for (index, element) in array.enumerate() { - XCTAssertEqual(element.name, structArray[index].name) - } - } -} \ No newline at end of file diff --git a/AztecTests/New Group/AttributesToStringAttributes/BoldElementAttributeConverterTests.swift b/AztecTests/Converters/AttributesToStringAttributes/BoldElementAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/AttributesToStringAttributes/BoldElementAttributeConverterTests.swift rename to AztecTests/Converters/AttributesToStringAttributes/BoldElementAttributeConverterTests.swift diff --git a/AztecTests/New Group/AttributesToStringAttributes/ItalicElementAttributeConverterTests.swift b/AztecTests/Converters/AttributesToStringAttributes/ItalicElementAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/AttributesToStringAttributes/ItalicElementAttributeConverterTests.swift rename to AztecTests/Converters/AttributesToStringAttributes/ItalicElementAttributeConverterTests.swift diff --git a/AztecTests/New Group/AttributesToStringAttributes/UnderlineElementAttributeConverterTests.swift b/AztecTests/Converters/AttributesToStringAttributes/UnderlineElementAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/AttributesToStringAttributes/UnderlineElementAttributeConverterTests.swift rename to AztecTests/Converters/AttributesToStringAttributes/UnderlineElementAttributeConverterTests.swift diff --git a/AztecTests/New Group/ElementToAttributedString/GenericElementConverterTests.swift b/AztecTests/Converters/ElementToAttributedString/GenericElementConverterTests.swift similarity index 100% rename from AztecTests/New Group/ElementToAttributedString/GenericElementConverterTests.swift rename to AztecTests/Converters/ElementToAttributedString/GenericElementConverterTests.swift diff --git a/AztecTests/New Group/StringAttributesToAttributes/BoldStringAttributeConverterTests.swift b/AztecTests/Converters/StringAttributesToAttributes/BoldStringAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/StringAttributesToAttributes/BoldStringAttributeConverterTests.swift rename to AztecTests/Converters/StringAttributesToAttributes/BoldStringAttributeConverterTests.swift diff --git a/AztecTests/New Group/StringAttributesToAttributes/ItalicStringAttributeConverterTests.swift b/AztecTests/Converters/StringAttributesToAttributes/ItalicStringAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/StringAttributesToAttributes/ItalicStringAttributeConverterTests.swift rename to AztecTests/Converters/StringAttributesToAttributes/ItalicStringAttributeConverterTests.swift diff --git a/AztecTests/New Group/StringAttributesToAttributes/UnderlineStringAttributeConverterTests.swift b/AztecTests/Converters/StringAttributesToAttributes/UnderlineStringAttributeConverterTests.swift similarity index 100% rename from AztecTests/New Group/StringAttributesToAttributes/UnderlineStringAttributeConverterTests.swift rename to AztecTests/Converters/StringAttributesToAttributes/UnderlineStringAttributeConverterTests.swift diff --git a/AztecTests/Extensions/UIImageResizeTests.swift b/AztecTests/Extensions/UIImageResizeTests.swift index 1f7ee53f4..3f1c77bbb 100644 --- a/AztecTests/Extensions/UIImageResizeTests.swift +++ b/AztecTests/Extensions/UIImageResizeTests.swift @@ -14,7 +14,7 @@ class UIImageResizeTests: XCTestCase { } func testResizingImageWorks() { - let bundle = Bundle(for: type(of: self)) + let bundle = Bundle.aztecTestsBundle guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else { XCTFail() @@ -52,7 +52,7 @@ class UIImageResizeTests: XCTestCase { } func testResizingImageWorks2() { - let bundle = Bundle(for: type(of: self)) + let bundle = Bundle.aztecTestsBundle guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else { XCTFail() @@ -90,9 +90,8 @@ class UIImageResizeTests: XCTestCase { } func testResizingImageWithoutSizeChangeReturnsSameImage() { - let bundle = Bundle(for: type(of: self)) - - guard let image = UIImage(named: "aztec", in: bundle, compatibleWith: nil) else { + + guard let image = UIImage(named: "aztec", in: .aztecTestsBundle, compatibleWith: nil) else { XCTFail() return } diff --git a/AztecTests/TestingSupport/NSBundle+AztecTestsBundle.swift b/AztecTests/TestingSupport/NSBundle+AztecTestsBundle.swift new file mode 100644 index 000000000..1c4fd4b17 --- /dev/null +++ b/AztecTests/TestingSupport/NSBundle+AztecTestsBundle.swift @@ -0,0 +1,11 @@ +import Foundation + +extension Bundle { + @objc public class var aztecTestsBundle: Bundle { +#if SPM + return .module +#else + return Bundle(for: TextViewStub.self) +#endif + } +} diff --git a/AztecTests/TestingSupport/TextViewStub.swift b/AztecTests/TestingSupport/TextViewStub.swift index 1141805a9..42dfd1236 100644 --- a/AztecTests/TestingSupport/TextViewStub.swift +++ b/AztecTests/TestingSupport/TextViewStub.swift @@ -8,7 +8,7 @@ class TextViewStub: Aztec.TextView { // MARK: - Sample HTML Retrieval static func loadSampleHTML() -> String { - guard let path = Bundle(for: self).path(forResource: "content", ofType: "html"), + guard let path = Bundle.aztecTestsBundle.path(forResource: "content", ofType: "html"), let sample = try? String(contentsOfFile: path) else { fatalError() diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b4d1c21..e5a951a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ _None._ ### Internal Changes -_None._ +* Added SPM support. ## [1.19.9](https://github.com/wordpress-mobile/AztecEditor-iOS/releases/tag/1.19.9) diff --git a/Package.swift b/Package.swift new file mode 100644 index 000000000..028eca67d --- /dev/null +++ b/Package.swift @@ -0,0 +1,63 @@ +// swift-tools-version: 5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let swiftSettings: [SwiftSetting] = [ + .define("SPM"), +] + +let package = Package( + name: "WordPress-AztecEditor-iOS", + platforms: [.iOS(.v11)], + products: [ + .library(name: "Aztec", targets: ["Aztec"]), + .library(name: "WordPressEditor", targets: ["WordPressEditor"]), + ], + dependencies: [ + ], + targets: [ + .target( + name: "Aztec", + dependencies: [ + ], + path: "Aztec", + resources: [ + .process("Assets"), + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "AztecTests", + dependencies: ["Aztec"], + path: "AztecTests", + resources: [ + .process("Resources"), + ], + swiftSettings: swiftSettings + ), + .target( + name: "WordPressEditor", + dependencies: [ + "Aztec", + ], + path: "WordPressEditor/WordPressEditor", + resources: [ + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "WordPressEditorTests", + dependencies: [ + "Aztec", + "WordPressEditor", + ], + path: "WordPressEditor/WordPressEditorTests", + resources: [ + .process("Resources"), + ], + swiftSettings: swiftSettings + ) + ], + swiftLanguageVersions: [.v5] +) diff --git a/README.md b/README.md index 72906901c..57487f1f0 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,38 @@ pod "WordPress-Aztec-iOS", "1.0" # or the version number you want pod "WordPress-Editor-iOS", "1.0" ``` +## Integrating the Library with SPM + +Both libraries are available through [SPM](https://www.swift.org/package-manager/). To install them, add the package to your package +dependencies and the appropriate library to your target dependencies. + +```Swift +let package = Package( + name: "YourPackage", + products: [ + .library(name: "YourLibrary", targets: ["YourTarget"]), + ], + dependencies: [ + .package(url: "https://github.com/wordpress-mobile/AztecEditor-iOS", .upToNextMajor(from: "1.20.0")), + ], + targets: [ + .target( + name: "YourTarget", + dependencies: [ + .product(name: "Aztec", package: "AztecEditor-iOS"), // You can choose... + .product(name: "WordPressEditor", package: "AztecEditor-iOS"), // which library you need. + ] + ), + ] +) +``` + +#### Via Xcode + +You can also just use the project repo URL (https://github.com/wordpress-mobile/AztecEditor-iOS) via Xcode! + +_**note**_: SPM support was added in version 1.20.0, tags prior to that will fail to resolve in SPM. + ## Usage After installing Aztec, import the module and use the `Aztec.TextView` view as shown below: diff --git a/WordPressEditor/WordPressEditorTests/GutenbergPreProcessorTests.swift b/WordPressEditor/WordPressEditorTests/GutenbergPreProcessorTests.swift deleted file mode 100644 index 025240df5..000000000 --- a/WordPressEditor/WordPressEditorTests/GutenbergPreProcessorTests.swift +++ /dev/null @@ -1,104 +0,0 @@ -import XCTest -@testable import WordPressEditor - -class GutenbergPreProcessorTests: XCTestCase { - - let processor = GutenbergPreProcessor() - - // MARK: Regular Gutenberg Tags - - private func encode(blockString: String) -> String { - let data = blockString.data(using: .utf16)! - let base64String = data.base64EncodedString() - - return base64String - } - - /// Verifies that a Gutenberg paragraph block is properly encoded. - /// - func testParagraphBlock() { - let openingGutentag = "" - let input = "\(openingGutentag)\n

Hello there!

\n" - - let encodedOpeningComment = encode(blockString: openingGutentag) - let expected = "\n

Hello there!

\n
" - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } - - /// Verifies that a Gutenberg paragraph block with attributes is properly encoded. - /// - func testParagraphBlockWithAttributes() { - let openingGutentag = "" - let input = "\(openingGutentag)\n

Hello there!

\n" - - let encodedOpeningComment = encode(blockString: openingGutentag) - let expected = "\n

Hello there!

\n
" - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } - - /// Verifies that multiple Gutenberg paragraph blocks with attributes are properly encoded. - /// - func testMultipleParagraphBlocksWithAttributes() { - let openingGutentag = "" - let singleInputParagraph = "\(openingGutentag)\n

Hello there!

\n" - let input = String(format: "%@\n%@\n%@", singleInputParagraph, singleInputParagraph, singleInputParagraph) - - let encodedOpeningComment = encode(blockString: openingGutentag) - let singleExpectedParagraph = "\n

Hello there!

\n
" - let expected = String(format: "%@\n%@\n%@", singleExpectedParagraph, singleExpectedParagraph, singleExpectedParagraph) - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } - - // MARK: - Self-Closing Gutenberg Tags - - /// Verifies that a self closing block is properly processed - /// - func testSelfClosedBlock() { - let input = "" - - let encodedGutentag = encode(blockString: input) - let expected = "" - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } - - /// Verifies that a self closing block with attributes is properly processed - /// - func testSelfClosedBlockWithAttributes() { - let input = "" - - let encodedGutentag = encode(blockString: input) - let expected = "" - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } - - - /// Verifies that multiple self closing blocks with attributes are properly processed - /// - func testMultipleSelfClosedBlockWithAttributes() { - let singleGutentag = "" - let input = String(format: "%@\n%@\n%@", singleGutentag, singleGutentag, singleGutentag) - - let encodedGutentag = encode(blockString: singleGutentag) - let singleExpectedElement = "" - let expected = String(format: "%@\n%@\n%@", singleExpectedElement, singleExpectedElement, singleExpectedElement) - - let output = processor.process(input) - - XCTAssertEqual(output, expected) - } -} diff --git a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Gutenberg/GutenpackAttachmentRendererTests.swift b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Gutenberg/GutenpackAttachmentRendererTests.swift index 65b1668a6..a969fc652 100644 --- a/WordPressEditor/WordPressEditorTests/WordPressPlugin/Gutenberg/GutenpackAttachmentRendererTests.swift +++ b/WordPressEditor/WordPressEditorTests/WordPressPlugin/Gutenberg/GutenpackAttachmentRendererTests.swift @@ -67,7 +67,11 @@ class GutenpackAttachmentRendererTests: XCTestCase { fatalError() }() +#if SPM + let bundle = Bundle.module +#else let bundle = Bundle(for: type(of: self)) +#endif guard let url = bundle.url(forResource: fileName, withExtension: "dat", subdirectory: nil), let expectedPNGRepresentation = try? Data(contentsOf: url, options: []) else { XCTFail()