<commit_before>public class View {

    public static var renderers: [String: RenderDriver] = [:]

	public static let resourceDir = Application.workDir + "Resources"
	var bytes: [UInt8]

    enum Error: ErrorType {
        case InvalidPath
    }

    public convenience init(path: String) throws {
        try self.init(path: path, context: [:])
    }

    public init(path: String, context: [String: Any]) throws {
        let filesPath = View.resourceDir + "/" + path
        
        guard let fileBody = try? FileManager.readBytesFromFile(filesPath) else {
            self.bytes = []
            Log.error("No view found in path: \(filesPath)")
            throw Error.InvalidPath
        }
        self.bytes = fileBody

        for (suffix, renderer) in View.renderers {
            if path.hasSuffix(suffix) {
                let template =  String.fromUInt8(self.bytes)
                let rendered = try renderer.render(template: template, context: context)
                self.bytes = [UInt8](rendered.utf8)
            }
        }

    }

}

extension View: ResponseConvertible {
    public func response() -> Response {
        return Response(status: .OK, data: self.bytes, contentType: .Html)
    }
}

<commit_msg>2.2 fix<commit_after>public class View {

    public static var renderers: [String: RenderDriver] = [:]

	public static let resourceDir = Application.workDir + "Resources"
	var bytes: [UInt8]

    enum Error: ErrorType {
        case InvalidPath
    }

    public convenience init(path: String) throws {
        try self.init(path: path, context: [:])
    }

    public init(path: String, context: [String: Any]) throws {
        let filesPath = View.resourceDir + "/" + path
        
        guard let fileBody = try? FileManager.readBytesFromFile(filesPath) else {
            self.bytes = []
            Log.error("No view found in path: \(filesPath)")
            throw Error.InvalidPath
        }
        self.bytes = fileBody

        for (suffix, renderer) in View.renderers {
            //FIXME
            #if swift(>=3.0)
            if path.hasSuffix(suffix) {
                let template =  String.fromUInt8(self.bytes)
                let rendered = try renderer.render(template: template, context: context)
                self.bytes = [UInt8](rendered.utf8)
            }
            #endif
        }

    }

}

extension View: ResponseConvertible {
    public func response() -> Response {
        return Response(status: .OK, data: self.bytes, contentType: .Html)
    }
}


{'fraction_non_alphanumeric': 0.10467882632831087, 'fraction_numerical': 0.004758128469468675, 'mean_word_length': 2.0768292682926828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5082410', 'n_tokens_mistral': 724, 'n_tokens_neox': 698, 'n_words': 191}