Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Fix travis, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
honghaoz committed Jun 9, 2019
1 parent da7185f commit ae34495
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 74 deletions.
44 changes: 14 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
Expand Down
81 changes: 38 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:/CocoaPods/Specs.git'
use_frameworks!

pod 'Ji', '~> 2.1.0'
pod 'Ji', '~> 4.2.0'
```

Then, run the following command:
Expand All @@ -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)
Expand All @@ -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:/honghaoz/Ji.git", majorVersion: 2, minor: 1)
.package(url: "https:/honghaoz/Ji.git", from: "4.2.0")
],
targets: [
.target(
name: "YOUR_TARGET_NAME",
dependencies: ["Ji"]
),
...
]
)
```
Expand All @@ -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 <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLtree.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
#import <libxml/xmlerror.h>
```
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:/honghaoz/Ji/tree/master/Sources/Ji) folder into your project.
- Drag [**Sources/Clibxml2**](https:/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

Expand All @@ -112,45 +107,45 @@ 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`:
```swift
let xmlString = "<?xml version='1.0' encoding='UTF-8'?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>"
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
Expand Down

0 comments on commit ae34495

Please sign in to comment.