Moved page.html location information to ArticleRenderer

This commit is contained in:
Maurice Parker 2019-09-21 12:36:35 -05:00
parent 99be955ede
commit b49aeca577
4 changed files with 18 additions and 18 deletions

View File

@ -104,11 +104,7 @@ final class DetailWebViewController: NSViewController, WKUIDelegate {
NotificationCenter.default.addObserver(self, selector: #selector(webInspectorEnabledDidChange(_:)), name: .WebInspectorEnabledDidChange, object: nil)
#endif
let pageURL = Bundle.main.url(forResource: "page", withExtension: "html")!
let page = try! String(contentsOf: pageURL)
let baseURL = pageURL.deletingLastPathComponent()
webView.loadHTMLString(page, baseURL: baseURL)
webView.loadHTMLString(ArticleRenderer.page.html, baseURL: ArticleRenderer.page.baseURL)
}
@ -181,7 +177,7 @@ private extension DetailWebViewController {
func reloadHTML() {
let style = ArticleStylesManager.shared.currentStyle
let rendering: ArticleRendering
let rendering: ArticleRenderer.Rendering
switch state {
case .noSelection:

View File

@ -11,10 +11,18 @@ import RSCore
import Articles
import Account
typealias ArticleRendering = (style: String, html: String)
struct ArticleRenderer {
typealias Rendering = (style: String, html: String)
typealias Page = (html: String, baseURL: URL)
static var page: Page = {
let pageURL = Bundle.main.url(forResource: "page", withExtension: "html")!
let html = try! String(contentsOf: pageURL)
let baseURL = pageURL.deletingLastPathComponent()
return Page(html: html, baseURL: baseURL)
}()
private let article: Article?
private let extractedArticle: ExtractedArticle?
private let articleStyle: ArticleStyle
@ -38,22 +46,22 @@ struct ArticleRenderer {
// MARK: - API
static func articleHTML(article: Article, extractedArticle: ExtractedArticle? = nil, style: ArticleStyle) -> ArticleRendering {
static func articleHTML(article: Article, extractedArticle: ExtractedArticle? = nil, style: ArticleStyle) -> Rendering {
let renderer = ArticleRenderer(article: article, extractedArticle: extractedArticle, style: style)
return (renderer.styleString(), renderer.articleHTML)
}
static func multipleSelectionHTML(style: ArticleStyle) -> ArticleRendering {
static func multipleSelectionHTML(style: ArticleStyle) -> Rendering {
let renderer = ArticleRenderer(article: nil, extractedArticle: nil, style: style)
return (renderer.styleString(), renderer.multipleSelectionHTML)
}
static func noSelectionHTML(style: ArticleStyle) -> ArticleRendering {
static func noSelectionHTML(style: ArticleStyle) -> Rendering {
let renderer = ArticleRenderer(article: nil, extractedArticle: nil, style: style)
return (renderer.styleString(), renderer.noSelectionHTML)
}
static func noContentHTML(style: ArticleStyle) -> ArticleRendering {
static func noContentHTML(style: ArticleStyle) -> Rendering {
let renderer = ArticleRenderer(article: nil, extractedArticle: nil, style: style)
return (renderer.styleString(), renderer.noContentHTML)
}

View File

@ -38,11 +38,7 @@ class DetailViewControllerWebViewProvider: NSObject, WKNavigationDelegate {
webView.navigationDelegate = self
queue.insert(webView, at: 0)
let pageURL = Bundle.main.url(forResource: "page", withExtension: "html")!
let page = try! String(contentsOf: pageURL)
let baseURL = pageURL.deletingLastPathComponent()
webView.loadHTMLString(page, baseURL: baseURL)
webView.loadHTMLString(ArticleRenderer.page.html, baseURL: ArticleRenderer.page.baseURL)
}

@ -1 +1 @@
Subproject commit fd55bace3c2ef2c9e5af8110c0fd742e2135cad1
Subproject commit 960eaf60336f592306fb1bf6f5a62800a9c5050f