0001    import Inquiline
0002    
0003    public class Controller
Controller.swift:10
    public static var applicationController = Controller()
Router.swift:37
    public func resources(name: String, _ controller: Controller) {
{ 0004 public typealias Parameters = [String: String] 0005 public typealias Action
Controller.swift:11
    var actions = [String: Action]()
= (request: Request) -> Response 0006 public typealias Filter
Controller.swift:12
    var filters = [String: Filter]()
= (request: Request) -> Response? 0007 public typealias FilterCollection
Controller.swift:13
    var beforeFilters = FilterCollection()
Controller.swift:14
    var afterFilters = FilterCollection()
= [String: FilterOptions] 0008 public typealias FilterOptions
Controller.swift:7
    public typealias FilterCollection = [String: FilterOptions]
Controller.swift:80
    public func beforeAction(filter: String, _ options: FilterOptions = nil) -> Void {
Controller.swift:84
    public func afterAction(filter: String, _ options: FilterOptions = nil) -> Void {
= [String: [String]]? 0009 0010 public static var applicationController = Controller() 0011 var actions = [String: Action]() 0012 var filters = [String: Filter]() 0013 var beforeFilters
Controller.swift:81
        beforeFilters[filter] = options
= FilterCollection() 0014 var afterFilters
Controller.swift:85
        afterFilters[filter] = options   
= FilterCollection() 0015 public let next:Response? = nil 0016 0017 public init
Controller.swift:10
    public static var applicationController = Controller()
() {} 0018 0019 public func action(name: String, body: Action) { 0020 actions[name] = body 0021 } 0022 0023 public func filter(name: String, body: Filter) { 0024 filters[name] = body 0025 } 0026 0027 public subscript(actionName: String) -> Action { 0028 get { 0029 return { (request) in 0030 guard let action = self.actions[actionName] else { 0031 return Response(.NotFound, contentType: "text/plain; charset=utf8", body: "Action Not Found") 0032 } 0033 0034 if let filterResponse = self.runFilters(request, actionName, self.beforeFilters) { 0035 return filterResponse 0036 } 0037 0038 let response = action(request: request) 0039 0040 if let filterResponse = self.runFilters(request, actionName, self.afterFilters) { 0041 return filterResponse 0042 } 0043 0044 return response 0045 } 0046 } 0047 0048 set(newValue) { 0049 actions[actionName] = newValue 0050 } 0051 } 0052 0053 func runFilters(request: Request, _ actionName: String, _ filterCollection: FilterCollection) -> Response? { 0054 for (filter, options) in filterCollection { 0055 // prefer filter in child controller 0056 if let selectedFilter = self.filters[filter] { 0057 // if "only" option is used then check if action is in the list 0058 if let opts = options, let only = opts["only"] { 0059 if only.contains(actionName) { 0060 if let response = selectedFilter(request: request) { 0061 return response 0062 } 0063 } 0064 // otherwise run filter without any checking 0065 } else { 0066 if let response = selectedFilter(request: request) { 0067 return response 0068 } 0069 } 0070 // use ApplicationController filter if it's not defined in child controller 0071 } else if let selectedFilter = Controller.applicationController.filters[filter] { 0072 if let response = selectedFilter(request: request) { 0073 return response 0074 } 0075 } 0076 } 0077 return nil 0078 } 0079 0080 public func beforeAction(filter: String, _ options: FilterOptions = nil) -> Void { 0081 beforeFilters[filter] = options 0082 } 0083 0084 public func afterAction(filter: String, _ options: FilterOptions = nil) -> Void { 0085 afterFilters[filter] = options 0086 } 0087 0088 public func render(template: String) -> Response { 0089 let body = StencilView(template).render() 0090 return Response(.Ok, contentType: "text/html", body: body) 0091 } 0092 0093 public func render
Controller.swift:88
    public func render(template: String) -> Response {
Controller.swift:103
    public func render(template: String, _ context: [String: Any]) -> Response {
(template: String, _ object: HTMLRenderable?) -> Response { 0094 var body:String 0095 if let obj = object { 0096 body = StencilView(template, obj.renderableAttributes()).render() 0097 } else { 0098 body = StencilView(template).render() 0099 } 0100 return Response(.Ok, contentType: "text/html", body: body) 0101 } 0102 0103 public func render(template: String, _ context: [String: Any]) -> Response { 0104 var body:String 0105 body = StencilView(template, context).render() 0106 return Response(.Ok, contentType: "text/html", body: body) 0107 } 0108 0109 public func renderJSON(object: JSONRenderable?) -> Response { 0110 var body:String 0111 if let obj = object { 0112 body = JSONView(obj.renderableJSONAttributes()).render() 0113 } else { 0114 body = "null" 0115 } 0116 return Response(.Ok, contentType: "text/html", body: body) 0117 } 0118 0119 public func renderJSON
Controller.swift:109
    public func renderJSON(object: JSONRenderable?) -> Response {
(context: [String: Any]? = nil) -> Response { 0120 var body:String 0121 body = JSONView(context).render() 0122 return Response(.Ok, contentType: "application/json", body: body) 0123 } 0124 0125 public func redirectTo(path: String) -> Response { 0126 return Response(.Found, headers: [("Location", path)]) 0127 } 0128 0129 public func respondTo(request: Request, _ responders: [String: () -> Response]) -> Response { 0130 let accepts = request.accept!.split(",") 0131 for (accept, response) in responders { 0132 if accepts.contains(accept.mimeType()) { 0133 return response() 0134 } 0135 } 0136 return Response(.NotAcceptable) 0137 } 0138 } 0139 0140