Skip to content

Commit ee51fee

Browse files
authored
Merge pull request #11 from contentful-labs/develop
Update Rich Text Renderer to 0.2.0
2 parents 172fa65 + 9f1b251 commit ee51fee

File tree

239 files changed

+30385
-2678
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

239 files changed

+30385
-2678
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ xcuserdata
99
.idea
1010

1111
## Cocoapods
12-
Pods/
12+
#Pods/
1313
build
1414
.build
1515
Packages

ContentfulRichTextRenderer.podspec

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,24 @@
22

33
Pod::Spec.new do |spec|
44
spec.name = "ContentfulRichTextRenderer"
5-
spec.version = "0.0.1"
6-
spec.summary = "Swift library for rendering Contentful RichText."
7-
spec.homepage = "https://github.com/contentful-labs/rich-text-renderer.swift/"
5+
spec.version = "0.2.0"
6+
spec.summary = "Swift library for rendering Contentful RichTextDocument."
7+
spec.homepage = "https://github.com/contentful-labs/rich-text-renderer.swift"
88
spec.social_media_url = 'https://twitter.com/contentful'
9+
spec.authors = 'Contentful'
910

10-
spec.license = {
11-
:type => 'MIT',
12-
:file => 'LICENSE'
13-
}
11+
spec.license = { :type => "MIT", :file => "LICENSE" }
12+
13+
spec.source = { :git => "https://github.com/contentful-labs/rich-text-renderer.swift", :tag => spec.version.to_s }
1414

15-
spec.authors = { "JP Wright" => "[email protected]" }
16-
spec.source = { :git => "https://github.com/contentful-labs/rich-text-renderer.swift.git",
17-
:tag => spec.version.to_s }
1815
spec.requires_arc = true
1916

20-
spec.swift_version = '4.2'
21-
spec.ios.deployment_target = '9.3'
17+
spec.swift_version = "5.2"
18+
spec.ios.deployment_target = "11.0"
2219

23-
spec.source_files = 'Sources/RichTextRenderer/*.swift'
24-
spec.ios.source_files = 'Sources/RichTextRenderer/UIKit/*.swift'
20+
spec.source_files = "RichTextRenderer/**/*.swift"
2521

26-
spec.dependency 'AlamofireImage', '~> 3.4'
27-
spec.dependency 'Contentful', '~> 4.1'
22+
spec.dependency 'AlamofireImage'
23+
spec.dependency 'Contentful'
2824
end
2925

Example-iOS/Example-iOS.xcodeproj/project.pbxproj

Lines changed: 458 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Example-iOS
2+
3+
import UIKit
4+
5+
@UIApplicationMain
6+
class AppDelegate: UIResponder, UIApplicationDelegate {
7+
var window: UIWindow?
8+
9+
func application(
10+
_ application: UIApplication,
11+
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
12+
) -> Bool {
13+
let window = UIWindow(frame: UIScreen.main.bounds)
14+
let viewController = ViewController()
15+
window.rootViewController = viewController
16+
window.makeKeyAndVisible()
17+
18+
self.window = window
19+
20+
return true
21+
}
22+
}
23+
24+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "iphone",
5+
"scale" : "2x",
6+
"size" : "20x20"
7+
},
8+
{
9+
"idiom" : "iphone",
10+
"scale" : "3x",
11+
"size" : "20x20"
12+
},
13+
{
14+
"idiom" : "iphone",
15+
"scale" : "2x",
16+
"size" : "29x29"
17+
},
18+
{
19+
"idiom" : "iphone",
20+
"scale" : "3x",
21+
"size" : "29x29"
22+
},
23+
{
24+
"idiom" : "iphone",
25+
"scale" : "2x",
26+
"size" : "40x40"
27+
},
28+
{
29+
"idiom" : "iphone",
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
47+
},
48+
{
49+
"idiom" : "ipad",
50+
"scale" : "2x",
51+
"size" : "20x20"
52+
},
53+
{
54+
"idiom" : "ipad",
55+
"scale" : "1x",
56+
"size" : "29x29"
57+
},
58+
{
59+
"idiom" : "ipad",
60+
"scale" : "2x",
61+
"size" : "29x29"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"scale" : "1x",
66+
"size" : "40x40"
67+
},
68+
{
69+
"idiom" : "ipad",
70+
"scale" : "2x",
71+
"size" : "40x40"
72+
},
73+
{
74+
"idiom" : "ipad",
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
92+
}
93+
],
94+
"info" : {
95+
"author" : "xcode",
96+
"version" : 1
97+
}
98+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"author" : "xcode",
4+
"version" : 1
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="xdU-89-17e">
3-
<device id="retina4_7" orientation="portrait">
4-
<adaptation id="fullscreen"/>
5-
</device>
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
63
<dependencies>
7-
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14283.14"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
95
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
106
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
117
</dependencies>
128
<scenes>
139
<!--View Controller-->
14-
<scene sceneID="B5I-iW-7pw">
10+
<scene sceneID="EHf-IW-A2E">
1511
<objects>
16-
<viewController id="xdU-89-17e" sceneMemberID="viewController">
17-
<view key="view" contentMode="scaleToFill" id="481-bE-WJL">
12+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
13+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
1814
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1915
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
20-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
21-
<viewLayoutGuide key="safeArea" id="sLf-vW-XCX"/>
16+
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
17+
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
2218
</view>
2319
</viewController>
24-
<placeholder placeholderIdentifier="IBFirstResponder" id="ppg-at-QBy" userLabel="First Responder" sceneMemberID="firstResponder"/>
20+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
2521
</objects>
22+
<point key="canvasLocation" x="53" y="375"/>
2623
</scene>
2724
</scenes>
2825
</document>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="16096" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
3+
<device id="retina6_1" orientation="portrait" appearance="light"/>
4+
<dependencies>
5+
<deployment identifier="iOS"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
7+
</dependencies>
8+
<scenes/>
9+
</document>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Example-iOS
2+
3+
import ContentfulRichTextRenderer
4+
import UIKit
5+
6+
final class CarView: UIView, ResourceLinkBlockViewRepresentable {
7+
private let car: Car
8+
9+
var surroundingTextShouldWrap: Bool = false
10+
var context: [CodingUserInfoKey : Any] = [:]
11+
12+
public init(car: Car) {
13+
self.car = car
14+
super.init(frame: .zero)
15+
16+
let title = UILabel(frame: .zero)
17+
title.text = "🚗 " + car.model + " 🚗"
18+
title.translatesAutoresizingMaskIntoConstraints = false
19+
addSubview(title)
20+
21+
title.topAnchor.constraint(equalTo: topAnchor).isActive = true
22+
title.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
23+
title.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
24+
title.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
25+
title.sizeToFit()
26+
27+
frame = title.bounds
28+
backgroundColor = .lightGray
29+
}
30+
31+
required init?(coder: NSCoder) {
32+
fatalError("init(coder:) has not been implemented")
33+
}
34+
35+
func layout(with width: CGFloat) {}
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Example-iOS
2+
3+
import Contentful
4+
import ContentfulRichTextRenderer
5+
import UIKit
6+
7+
struct ExampleBlockViewProvider: ResourceLinkBlockViewProviding {
8+
func view(for resource: Link, context: [CodingUserInfoKey: Any]) -> ResourceLinkBlockViewRepresentable? {
9+
switch resource {
10+
case .entryDecodable(let entryDecodable):
11+
if let car = entryDecodable as? Car {
12+
return CarView(car: car)
13+
} else if let article = entryDecodable as? Article {
14+
return SuggestedArticleView(article: article)
15+
}
16+
17+
return nil
18+
19+
case .entry:
20+
return nil
21+
22+
case .asset(let asset):
23+
guard asset.file?.details?.imageInfo != nil else { return nil }
24+
25+
let imageView = ResourceLinkBlockImageView(asset: asset)
26+
27+
imageView.backgroundColor = .gray
28+
imageView.setImageToNaturalHeight()
29+
return imageView
30+
31+
default:
32+
return nil
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)