Skip to content

Commit

Permalink
Add url for update template support
Browse files Browse the repository at this point in the history
  • Loading branch information
joeblau committed Oct 31, 2018
1 parent 26097a1 commit 18690b4
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions Sources/App/RouteHandlers/APIRouteHandlers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class APIHandlers {
///
/// - Parameter router: Vapor server side Swift router
internal func createHelp(router: Router) {
router.get("/api/") { request in
router.get("/api/") { _ in
"""
gitignore.io help:
list - lists the operating systems, programming languages and IDE input types
Expand All @@ -125,7 +125,11 @@ internal class APIHandlers {
/// - Peturns: Final formatted template with headers and footers
private func createTemplate(ignoreString: String) -> (template: String, status: HTTPResponseStatus) {
guard let urlDecoded = ignoreString.removingPercentEncoding else {
return ("\n#!! ERROR: url decoding \(ignoreString) !#\n", .internalServerError)
return ("""
#!! ERROR: url decoding \(ignoreString) !#
""", .internalServerError)
}
var createStatus: HTTPResponseStatus = .ok
let template = urlDecoded
Expand All @@ -139,14 +143,27 @@ internal class APIHandlers {
.map { (templateKey) -> String in
guard let contents = self.templates[templateKey]?.contents else {
createStatus = .notFound
return "\n#!! ERROR: \(templateKey) is undefined. Use list command to see defined gitignore types !!#\n"
return """
#!! ERROR: \(templateKey) is undefined. Use list command to see defined gitignore types !!#
"""
}
return contents
}
.reduce("\n# Created by https://www.gitignore.io/api/\(urlDecoded)\n") { (currentTemplate, contents) -> String in
.reduce("""
# Created by https://www.gitignore.io/api/\(urlDecoded)
# Edit at https://www.gitignore.io/?templates=\(urlDecoded)
""") { (currentTemplate, contents) -> String in
return currentTemplate.appending(contents)
}
.appending("\n\n# End of https://www.gitignore.io/api/\(urlDecoded)\n")
.appending("""
# End of https://www.gitignore.io/api/\(urlDecoded)
""")
.removeDuplicateLines()

return (template: template, status: createStatus)
Expand Down

0 comments on commit 18690b4

Please sign in to comment.