1
1
mirror of https://github.com/qvacua/vimr.git synced 2025-01-07 06:33:19 +03:00
vimr/VimR/PreviewService.swift

63 lines
1.6 KiB
Swift
Raw Normal View History

2016-12-19 20:23:43 +03:00
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Foundation
class PreviewService {
2016-12-23 14:15:26 +03:00
fileprivate let empty: String
fileprivate let error: String
fileprivate let saveFirst: String
2016-12-19 20:23:43 +03:00
init() {
2016-12-23 14:15:26 +03:00
guard let emptyUrl = Bundle.main.url(forResource: "empty", withExtension: "html", subdirectory: "preview") else {
preconditionFailure("No empty.html!")
}
guard let errorUrl = Bundle.main.url(forResource: "error", withExtension: "html", subdirectory: "preview") else {
preconditionFailure("No error.html!")
}
2016-12-19 20:23:43 +03:00
2017-01-03 20:04:28 +03:00
guard let saveFirstUrl = Bundle.main.url(forResource: "save-first",
2016-12-23 14:15:26 +03:00
withExtension: "html",
subdirectory: "preview")
2016-12-19 20:23:43 +03:00
else {
2016-12-23 14:15:26 +03:00
preconditionFailure("No save-first.html!")
2016-12-19 20:23:43 +03:00
}
guard let emptyHtml = try? String(contentsOf: emptyUrl) else {
2016-12-23 14:15:26 +03:00
preconditionFailure("Error getting empty.html!")
2016-12-19 20:23:43 +03:00
}
2016-12-23 14:15:26 +03:00
guard let errorHtml = try? String(contentsOf: errorUrl) else {
preconditionFailure("Error getting error.html!")
}
guard let saveFirstHtml = try? String(contentsOf: saveFirstUrl) else {
preconditionFailure("Error getting save-first.html!")
}
self.empty = emptyHtml
self.error = errorHtml
self.saveFirst = saveFirstHtml
}
2016-12-26 11:04:03 +03:00
func baseUrl() -> URL {
return Bundle.main.resourceURL!.appendingPathComponent("preview")
}
2016-12-23 14:15:26 +03:00
func emptyHtml() -> String {
return self.empty
}
func errorHtml() -> String {
return self.error
2016-12-19 20:23:43 +03:00
}
2016-12-23 14:15:26 +03:00
func saveFirstHtml() -> String {
return self.saveFirst
2016-12-19 20:23:43 +03:00
}
}