Skip to content

Commit

Permalink
Add the ability to initialise a DownView using a custom template bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyarnold committed May 8, 2017
1 parent b944f1a commit b043c74
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Source/Views/DownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ open class DownView: WKWebView {
- parameter frame: The frame size of the web view
- parameter markdownString: A string containing CommonMark Markdown
- parameter openLinksInBrowser: Whether or not to open links using an external browser
- parameter templateBundle: Optional custom template bundle. Leaving this as `nil` will use the bundle included with Down.
- parameter didLoadSuccessfully: Optional callback for when the web content has loaded successfully

- returns: An instance of Self
*/
public init(frame: CGRect, markdownString: String, openLinksInBrowser: Bool = true, didLoadSuccessfully: DownViewClosure? = nil) throws {
public init(frame: CGRect, markdownString: String, openLinksInBrowser: Bool = true, templateBundle: Bundle? = nil, didLoadSuccessfully: DownViewClosure? = nil) throws {
self.didLoadSuccessfully = didLoadSuccessfully

if let templateBundle = templateBundle {
self.bundle = templateBundle
} else {
let classBundle = Bundle(for: DownView.self)
let url = classBundle.url(forResource: "DownView", withExtension: "bundle")!
self.bundle = Bundle(url: url)!
}

super.init(frame: frame, configuration: WKWebViewConfiguration())

if openLinksInBrowser || didLoadSuccessfully != nil { navigationDelegate = self }
Expand Down Expand Up @@ -58,11 +68,7 @@ open class DownView: WKWebView {

// MARK: - Private Properties

fileprivate let bundle: Bundle = {
let bundle = Bundle(for: DownView.self)
let url = bundle.url(forResource: "DownView", withExtension: "bundle")!
return Bundle(url: url)!
}()
let bundle: Bundle

fileprivate lazy var baseURL: URL = {
return self.bundle.url(forResource: "index", withExtension: "html")!
Expand Down

0 comments on commit b043c74

Please sign in to comment.