Files
GitHawk/Classes/Repository/RepositoryReadmeSectionController.swift
Ryan Nystrom 62e2763a85 Refactor markdown parsing to use text lib (#1674)
* milestones refactored with styled text

* reference refactored

* refactor commit references

* fix styled text bug

* request event refactored

* refactor titles

* warm caches for bg-gen models

* delete old text cell

* move shortlinks into MMMarkdown

* almost there

* build green

* running and trimming whitespaces

* styled text working

* fix tests

* tests passing
2018-03-31 10:12:51 -04:00

80 lines
2.5 KiB
Swift

//
// RepositoryReadmeSectionController.swift
// Freetime
//
// Created by Ryan Nystrom on 9/10/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import Foundation
import IGListKit
final class RepositoryReadmeSectionController: ListBindingSectionController<RepositoryReadmeModel>,
ListBindingSectionControllerDataSource {
private lazy var webviewCache: WebviewCellHeightCache = {
return WebviewCellHeightCache(sectionController: self)
}()
private lazy var imageCache: ImageCellHeightCache = {
return ImageCellHeightCache(sectionController: self)
}()
private lazy var photoHandler: PhotoViewHandler = {
return PhotoViewHandler(viewController: self.viewController)
}()
override init() {
super.init()
dataSource = self
}
// MARK: ListBindingSectionControllerDataSource
func sectionController(
_ sectionController: ListBindingSectionController<ListDiffable>,
viewModelsFor object: Any
) -> [ListDiffable] {
return self.object?.models ?? []
}
func sectionController(
_ sectionController: ListBindingSectionController<ListDiffable>,
sizeForViewModel viewModel: Any,
at index: Int
) -> CGSize {
guard let width = collectionContext?.containerSize.width else { fatalError("Missing context") }
let height = BodyHeightForComment(
viewModel: viewModel,
width: width,
webviewCache: webviewCache,
imageCache: imageCache
)
return CGSize(width: width, height: height)
}
func sectionController(
_ sectionController: ListBindingSectionController<ListDiffable>,
cellForViewModel viewModel: Any,
at index: Int
) -> UICollectionViewCell & ListBindable {
guard let context = self.collectionContext else { fatalError("Missing context") }
let cellClass: AnyClass = CellTypeForComment(viewModel: viewModel)
guard let cell = context.dequeueReusableCell(of: cellClass, for: self, at: index) as? UICollectionViewCell & ListBindable
else { fatalError("Cell not bindable") }
ExtraCommentCellConfigure(
cell: cell,
imageDelegate: photoHandler,
htmlDelegate: webviewCache,
htmlNavigationDelegate: viewController,
htmlImageDelegate: photoHandler,
attributedDelegate: viewController,
markdownDelegate: viewController,
imageHeightDelegate: imageCache
)
return cell
}
}