From aa04d06158dd6bfdb38b620204cee63a50d51ed6 Mon Sep 17 00:00:00 2001 From: shinriyo Date: Sun, 15 May 2016 16:36:19 +0900 Subject: [PATCH 1/6] System Requirements it doesn't works in DEVELOPMENT-SNAPSHOT-2016-05-09-a so I added System Requirements. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a704d20..c61b62b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Swiftra is a library that provides DSLs like Sinatra. +## System Requirements + +DEVELOPMENT-SNAPSHOT-2016-02-08-a + ## Example See [swiftra-example](https://github.com/takebayashi/swiftra-example). From 186e830514b8a8087d2c1677b6a6faa93f0a83ff Mon Sep 17 00:00:00 2001 From: shinriyo Date: Tue, 17 May 2016 08:28:50 +0900 Subject: [PATCH 2/6] gitignore update --- .gitignore | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a217f41..15ce81b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,73 @@ -/Packages/ -/.build/ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xcuserstate + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +Status API Training Shop Blog About + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride +Icon + From 6bd41f7d148dc82017964f7faddf8cf0c9aad2a9 Mon Sep 17 00:00:00 2001 From: shinriyo Date: Tue, 17 May 2016 08:31:45 +0900 Subject: [PATCH 3/6] template feature --- README.md | 5 ++++ Sources/Template.swift | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Sources/Template.swift diff --git a/README.md b/README.md index a704d20..3bcb1e9 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,10 @@ get("/404") { req in return Response(.NotFound) } +// template home.esiwft +get("/template") { req in + return Template.eswift("home") +} + serve(8080) ``` diff --git a/Sources/Template.swift b/Sources/Template.swift new file mode 100644 index 0000000..1881f47 --- /dev/null +++ b/Sources/Template.swift @@ -0,0 +1,59 @@ +/* + The MIT License (MIT) + + Copyright (c) 2016 shiriyo + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +import Foundation +public class Template { + static public func eswift(content: String) -> Response { + // TODO: later change template ex.mustache + let ext = "eswift" + if let filePath = NSBundle.mainBundle().pathForResource( + "../../views/\(String(content))", ofType: ext) { + do { + let data = try String(contentsOfFile: filePath, + encoding: NSUTF8StringEncoding) + // for line in data.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) { + // Do something + // print(line) + // } + return Response(status: .OK, + headers: [("Content-Type", "text/html")], body: data) + } catch { + print("Couldn't load the file somehow") + return Response(status: .OK, + headers: [("Content-Type", "text/html")], + body: "

Couldn't load the file somehow!

") + } + } else { + print("\(String(content)).\(String(ext)) is missing") + return Response(status: .OK, + headers: [("Content-Type", "text/html")], + body: "

Missing!

") + } + } + // TODO: + static public func json(content: String) -> Response { + let data = "" + return Response(status: .OK, + headers: [("Content-Type", "text/html")], body: data) + } +} From 2ef6bfbc28377b8c3a698e883c8902f605527b82 Mon Sep 17 00:00:00 2001 From: shinriyo Date: Tue, 17 May 2016 08:28:50 +0900 Subject: [PATCH 4/6] gitignore update --- .gitignore | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a217f41..15ce81b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,73 @@ -/Packages/ -/.build/ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated +build/ +DerivedData/ + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ + +## Other +*.moved-aside +*.xcuserstate + +## Obj-C/Swift specific +*.hmap +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the +# screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +Status API Training Shop Blog About + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride +Icon + From 643b04608628472c6d2fd4abb1899f6b4d837368 Mon Sep 17 00:00:00 2001 From: shinriyo Date: Tue, 17 May 2016 08:31:45 +0900 Subject: [PATCH 5/6] template feature --- README.md | 5 ++++ Sources/Template.swift | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Sources/Template.swift diff --git a/README.md b/README.md index c61b62b..31106e9 100644 --- a/README.md +++ b/README.md @@ -25,5 +25,10 @@ get("/404") { req in return Response(.NotFound) } +// template home.esiwft +get("/template") { req in + return Template.eswift("home") +} + serve(8080) ``` diff --git a/Sources/Template.swift b/Sources/Template.swift new file mode 100644 index 0000000..1881f47 --- /dev/null +++ b/Sources/Template.swift @@ -0,0 +1,59 @@ +/* + The MIT License (MIT) + + Copyright (c) 2016 shiriyo + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +import Foundation +public class Template { + static public func eswift(content: String) -> Response { + // TODO: later change template ex.mustache + let ext = "eswift" + if let filePath = NSBundle.mainBundle().pathForResource( + "../../views/\(String(content))", ofType: ext) { + do { + let data = try String(contentsOfFile: filePath, + encoding: NSUTF8StringEncoding) + // for line in data.componentsSeparatedByCharactersInSet(NSCharacterSet.newlineCharacterSet()) { + // Do something + // print(line) + // } + return Response(status: .OK, + headers: [("Content-Type", "text/html")], body: data) + } catch { + print("Couldn't load the file somehow") + return Response(status: .OK, + headers: [("Content-Type", "text/html")], + body: "

Couldn't load the file somehow!

") + } + } else { + print("\(String(content)).\(String(ext)) is missing") + return Response(status: .OK, + headers: [("Content-Type", "text/html")], + body: "

Missing!

") + } + } + // TODO: + static public func json(content: String) -> Response { + let data = "" + return Response(status: .OK, + headers: [("Content-Type", "text/html")], body: data) + } +} From 4e0b65e04dcaea599dcb1cc97e4e0d2fa53ac760 Mon Sep 17 00:00:00 2001 From: shinriyo Date: Thu, 19 May 2016 23:04:54 +0900 Subject: [PATCH 6/6] log added --- Sources/Swiftra.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/Swiftra.swift b/Sources/Swiftra.swift index 5afc02f..f12efb7 100644 --- a/Sources/Swiftra.swift +++ b/Sources/Swiftra.swift @@ -48,6 +48,8 @@ public func head(path: String, handler: Handler) { } public func serve(port: UInt16) { + let stringValue = "access : http://localhost:\(port)" + print(stringValue) let addr = SocketAddress(port: port) guard let sock = Socket() else { return @@ -62,6 +64,7 @@ public func serve(port: UInt16) { response = Response(.NotFound) response!.bodyBytes = Response.Status.NotFound.description.bytes() } + print(request.method) return response! } }