0001 import Foundation 0002 0003 public class View{ 0004 0005 public static var renderers
View.swift:19 let filesPath = View.resourceDir + "/" + pathView.swift:33 for (suffix, renderer) in View.renderers {View.swift:45 extension View: ResponseConvertible {: [String: RenderDriver] = [:] 0006 0007 public static let resourceDir
View.swift:33 for (suffix, renderer) in View.renderers {= Application.workDir + "Resources" 0008 var bytes
View.swift:19 let filesPath = View.resourceDir + "/" + path: [UInt8] 0009 0010 enum Error
View.swift:22 self.bytes = []View.swift:31 self.bytes = arrayView.swift:35 let template = String.fromUInt8(self.bytes)View.swift:37 self.bytes = [UInt8](rendered.utf8)View.swift:47 return Response(status: .OK, data: self.bytes, contentType: .Html): ErrorType { 0011 case InvalidPath
View.swift:24 throw Error.InvalidPath0012 } 0013 0014 public convenience init(path: String) throws { 0015 try self.init(path: path, context: [:]) 0016 } 0017 0018 public init
View.swift:24 throw Error.InvalidPath(path: String, context: [String: Any]) throws { 0019 let filesPath = View.resourceDir + "/" + path 0020 0021 guard let fileBody = NSData(contentsOfFile: filesPath) else { 0022 self.bytes = [] 0023 Log.error("No view found in path: \(filesPath)") 0024 throw Error.InvalidPath 0025 } 0026 0027 //TODO: Implement range 0028 var array = [UInt8](count: fileBody.length, repeatedValue: 0) 0029 fileBody.getBytes(&array, length: fileBody.length) 0030 0031 self.bytes = array 0032 0033 for (suffix, renderer) in View.renderers { 0034 if path.hasSuffix(suffix) { 0035 let template = String.fromUInt8(self.bytes) 0036 let rendered = try renderer.render(template: template, context: context) 0037 self.bytes = [UInt8](rendered.utf8) 0038 } 0039 } 0040 0041 } 0042 0043 } 0044 0045 extension View: ResponseConvertible { 0046 public func response() -> Response { 0047 return Response(status: .OK, data: self.bytes, contentType: .Html) 0048 } 0049 } 0050 0051
View.swift:15 try self.init(path: path, context: [:])