From ae34495fb60d70a6f954125eb48e5873075cb970 Mon Sep 17 00:00:00 2001 From: HongHao Zhang <3926785+honghaoz@users.noreply.github.com> Date: Sun, 9 Jun 2019 00:51:08 -0700 Subject: [PATCH] Fix travis, update README --- .travis.yml | 44 +++++---------- Example/Example/ViewController.swift | 1 - README.md | 81 +++++++++++++--------------- 3 files changed, 52 insertions(+), 74 deletions(-) diff --git a/.travis.yml b/.travis.yml index f057e76..e81aa83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,54 +7,38 @@ env: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 - - WORKSPACE=Ji.xcworkspace + - PROJECT="Ji.xcodeproj" - IOS_FRAMEWORK_SCHEME="Ji iOS" - MACOS_FRAMEWORK_SCHEME="Ji OSX" - TVOS_FRAMEWORK_SCHEME="Ji tvOS" - WATCHOS_FRAMEWORK_SCHEME="Ji watchOS" - - EXAMPLE_SCHEME="Example" matrix: # iOS - - DESTINATION="OS=11.0,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" - - DESTINATION="OS=10.3.1,name=iPhone 7 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" - - DESTINATION="OS=9.0,name=iPhone 6" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="YES" + - DESTINATION="OS=12.2,name=iPhone Xs" SCHEME="$IOS_FRAMEWORK_SCHEME" + - DESTINATION="OS=11.4,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" # macOS - - DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" + - DESTINATION="arch=x86_64" SCHEME="$MACOS_FRAMEWORK_SCHEME" # tvOS - - DESTINATION="OS=10.2,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" - - DESTINATION="OS=9.0,name=Apple TV 1080p" SCHEME="$TVOS_FRAMEWORK_SCHEME" RUN_TESTS="YES" BUILD_EXAMPLE="NO" + - DESTINATION="OS=12.2,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" + - DESTINATION="OS=11.4,name=Apple TV 4K" SCHEME="$TVOS_FRAMEWORK_SCHEME" # watchOS - - DESTINATION="OS=4.0,name=Apple Watch - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" - - DESTINATION="OS=3.2,name=Apple Watch - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" - - DESTINATION="OS=2.0,name=Apple Watch - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="NO" + - DESTINATION="OS=5.2,name=Apple Watch Series 4 - 44mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" + - DESTINATION="OS=4.2,name=Apple Watch Series 3 - 42mm" SCHEME="$WATCHOS_FRAMEWORK_SCHEME" before_install: - - gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet + # - gem install cocoapods --pre --no-rdoc --no-ri --no-document --quiet script: - set -o pipefail - xcodebuild -version - xcodebuild -showsdks - # Build Framework in Debug and Run Tests if specified - - if [ $RUN_TESTS == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty; - else - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi - - # Build Framework in Release and Run Tests if specified - - if [ $RUN_TESTS == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty; - else - xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi - - # Build Example in Debug if specified - - if [ $BUILD_EXAMPLE == "YES" ]; then - xcodebuild -workspace "$WORKSPACE" -scheme "$EXAMPLE_SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; - fi + ## Build for Debug with tests + - xcodebuild -project "$PROJECT" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug | xcpretty; + + ## Build for Release + - xcodebuild -project "$PROJECT" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release | xcpretty; diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 975f4e6..8227f93 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -14,7 +14,6 @@ class ViewController: UIViewController { super.viewDidLoad() // Init with data - let googleIndexData = try? Data(contentsOf: URL(string: "http://www.google.com")!) if let googleIndexData = googleIndexData { let jiDoc = Ji(htmlData: googleIndexData)! diff --git a/README.md b/README.md index 4a7a469..97f2db5 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ Ji (戟) is a Swift wrapper on libxml2 for parsing XML/HTML. ## Features -- [x] Build XML/HTML Tree and Navigate -- [x] XPath Query Supported -- [x] Comprehensive Unit Test Coverage +- [x] Build XML/HTML Tree and Navigate. +- [x] XPath Query Supported. +- [x] Comprehensive Unit Test Coverage. - [x] Support Swift Package Manager (SPM). Linux compatible. ## Requirements @@ -29,10 +29,9 @@ Ji (戟) is a Swift wrapper on libxml2 for parsing XML/HTML. To integrate **Ji** into your Xcode project using CocoaPods, specify it in your `Podfile`: ```ruby -source 'https://github.com/CocoaPods/Specs.git' use_frameworks! -pod 'Ji', '~> 2.1.0' +pod 'Ji', '~> 4.2.0' ``` Then, run the following command: @@ -46,7 +45,7 @@ $ pod install To integrate `Ji` into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "honghaoz/Ji" ~> 2.1.0 +github "honghaoz/Ji" ~> 4.2.0 ``` ### [Swift Package Manager (SPM)](https://swift.org/package-manager) @@ -61,18 +60,26 @@ brew link --force libxml2 - Linux ```bash -$ apt-get install libxml2-dev +$ sudo apt-get install libxml2-dev ``` #### Update `Package.swift` To integrate `Ji` in your project, add the proper description to your `Package.swift` file: ```swift +// swift-tools-version:4.2 import PackageDescription let package = Package( name: "YOUR_PROJECT_NAME", dependencies: [ - .Package(url: "https://github.com/honghaoz/Ji.git", majorVersion: 2, minor: 1) + .package(url: "https://github.com/honghaoz/Ji.git", from: "4.2.0") + ], + targets: [ + .target( + name: "YOUR_TARGET_NAME", + dependencies: ["Ji"] + ), + ... ] ) ``` @@ -81,25 +88,13 @@ let package = Package( If you prefer not to use a dependency manager, you can integrate Ji into your project manually. -- Configure Xcode project: - - Open project, select the target, under **General**, in **Linked Frameworks and Libraries**, add `libxml2.2.dylib` and `libxml2.dylib` - - Under **Build Settings**, in **Header Search Paths**, add `$(SDKROOT)/usr/include/libxml2` - - Under **Build Settings**, in **Other Linker Flags**, add `-lxml2` -- Import `libxml` headers: - - Copy the those import statements: - ```objective-c - #import - #import - #import - #import - #import - #import - #import - ``` - and paste them into your `[Modulename]-Bridging-Header.h` -- Drag `Ji.swift`, `JiHelper.swift` and `JiNode.swift` in [**Source**](https://github.com/honghaoz/Ji/tree/master/Source) folder into your project. - -And that's it! +- Add sources into your project: + - Drag `Ji.swift`, `JiHelper.swift` and `JiNode.swift` in [**Sources/Ji**](https://github.com/honghaoz/Ji/tree/master/Sources/Ji) folder into your project. + - Drag [**Sources/Clibxml2**](https://github.com/honghaoz/Ji/tree/master/Sources/Clibxml2) folder into your project. + +- Configure your project: + - Open project, select the target, under **Build Settings**, in **Header Search Paths**, add `$(SDKROOT)/usr/include/libxml2` + - Under **Build Settings**, in **Import Paths**, add `$(SRCROOT)/Clibxml2` (Make sure this is the path to the `Clibxml2` folder) ## Usage @@ -112,7 +107,7 @@ And that's it! ```swift let jiDoc = Ji(htmlURL: URL(string: "http://www.apple.com/support")!) let titleNode = jiDoc?.xPath("//head/title")?.first -print("title: \(titleNode?.content)") // title: Optional("Official Apple Support") +print("title: \(String(describing: titleNode?.content))") // title: Optional("Official Apple Support") ``` - Init with `String`: @@ -120,37 +115,37 @@ print("title: \(titleNode?.content)") // title: Optional("Official Apple Support let xmlString = "ToveJaniReminderDon't forget me this weekend!" let jiDoc = Ji(xmlString: xmlString) let bodyNode = jiDoc?.rootNode?.firstChildWithName("body") -print("body: \(bodyNode?.content)") // body: Optional("Don\'t forget me this weekend!") +print("body: \(String(describing: bodyNode?.content))") // body: Optional("Don\'t forget me this weekend!") ``` - Init with `Data`: ```swift let googleIndexData = try? Data(contentsOf: URL(string: "http://www.google.com")!) if let googleIndexData = googleIndexData { - let jiDoc = Ji(htmlData: googleIndexData)! - let htmlNode = jiDoc.rootNode! - print("html tagName: \(htmlNode.tagName)") // html tagName: Optional("html") - - let aNodes = jiDoc.xPath("//body//a") - if let firstANode = aNodes?.first { - print("first a node tagName: \(firstANode.name)") // first a node tagName: Optional("a") - let href = firstANode["href"] - print("first a node href: \(href)") // first a node href: Optional("http://www.google.ca/imghp?hl=en&tab=wi") - } + let jiDoc = Ji(htmlData: googleIndexData)! + let htmlNode = jiDoc.rootNode! + print("html tagName: \(String(describing: htmlNode.tagName))") // html tagName: Optional("html") + + let aNodes = jiDoc.xPath("//body//a") + if let firstANode = aNodes?.first { + print("first a node tagName: \(String(describing: firstANode.name))") // first a node tagName: Optional("a") + let href = firstANode["href"] + print("first a node href: \(String(describing: href))") // first a node href: Optional("http://www.google.ca/imghp?hl=en&tab=wi") + } } else { - print("google.com is inaccessible") + print("google.com is inaccessible") } -let 戟文档 = 戟(htmlURL: NSURL(string: "https://cocoapods.org/pods/Ji")!) +let 戟文档 = 戟(htmlURL: URL(string: "https://cocoapods.org/pods/Ji")!) let attribution = 戟文档?.xPath("//ul[@class='attribution']")?.first -print("作者(Author): \(attribution?.content)") +print("作者(Author): \(String(describing: attribution?.content))") // 作者(Author): Optional("ByHonghao Zhang") ``` ## License The MIT License (MIT) -Copyright (c) 2015 Honghao Zhang (张宏昊) +Copyright (c) 2019 Honghao Zhang (张宏昊) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal