Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitignore and template #4

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -21,5 +25,10 @@ get("/404") { req in
return Response(.NotFound)
}

// template home.esiwft
get("/template") { req in
return Template.eswift("home")
}

serve(8080)
```
3 changes: 3 additions & 0 deletions Sources/Swiftra.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,6 +64,7 @@ public func serve(port: UInt16) {
response = Response(.NotFound)
response!.bodyBytes = Response.Status.NotFound.description.bytes()
}
print(request.method)
return response!
}
}
59 changes: 59 additions & 0 deletions Sources/Template.swift
Original file line number Diff line number Diff line change
@@ -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: "<h1>Couldn't load the file somehow!</h1>")
}
} else {
print("\(String(content)).\(String(ext)) is missing")
return Response(status: .OK,
headers: [("Content-Type", "text/html")],
body: "<h1>Missing!</h1>")
}
}
// TODO:
static public func json(content: String) -> Response {
let data = ""
return Response(status: .OK,
headers: [("Content-Type", "text/html")], body: data)
}
}