[jenkinscat-docs] master: Added - file handlers should be stored in a separate file and namespace. (9ccfdc4)
immanetize at fedoraproject.org
immanetize at fedoraproject.org
Fri Feb 6 07:40:06 UTC 2015
Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git
On branch : master
>---------------------------------------------------------------
commit 9ccfdc421e471919b9a07539a77c78d9e71c312d
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date: Thu Dec 4 10:48:15 2014 +0100
Added - file handlers should be stored in a separate file and namespace.
>---------------------------------------------------------------
ChangeLog | 7 +++
src/jenkinscat/file_handlers.clj | 81 ++++++++++++++++++++++++++++++++++++++
src/jenkinscat/fileutils.clj | 3 +
3 files changed, 91 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f6f7c79..c2821aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-12-04 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/jenkinscat/file_handlers.clj:
+ Added - file handlers should be stored in a separate file and namespace.
+ * src/jenkinscat/fileutils.clj:
+ Updated.
+
2014-12-03 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/jenkinscat/server.clj:
diff --git a/src/jenkinscat/file_handlers.clj b/src/jenkinscat/file_handlers.clj
new file mode 100644
index 0000000..b7f7554
--- /dev/null
+++ b/src/jenkinscat/file_handlers.clj
@@ -0,0 +1,81 @@
+;;;
+;;; Jenkinscat HTTP server that handles all requests send from clients/browsers.
+;;;
+;;; Copyright (c) 2014 Pavel Tisnovsky, Red Hat
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions are met:
+;;; * Redistributions of source code must retain the above copyright
+;;; notice, this list of conditions and the following disclaimer.
+;;; * Redistributions in binary form must reproduce the above copyright
+;;; notice, this list of conditions and the following disclaimer in the
+;;; documentation and/or other materials provided with the distribution.
+;;; * Neither the name of the Red Hat nor the
+;;; names of its contributors may be used to endorse or promote products
+;;; derived from this software without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;; DISCLAIMED. IN NO EVENT SHALL Pavel Tisnovsky BE LIABLE FOR ANY
+;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+;;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+;;;
+
+
+
+(ns jenkinscat.file-handlers)
+
+(require '[ring.util.response :as http-response])
+(require '[jenkinscat.fileutils :as fileutils])
+
+(defn return-file
+ "Return given file with proper content type as a response to a HTTP request."
+ [file-name content-type]
+ (let [file (fileutils/new-file "www" file-name)]
+ (println "Returning file " (.getAbsolutePath file))
+ (println "")
+ (-> (http-response/response file)
+ (http-response/content-type content-type))))
+
+(def file-handlers
+ "Map of file handlers, ie. map of known files included from the generated HTML page."
+ {"/" '(jenkinscat.file-handlers/return-file "index.html" "text/html")
+ "/favicon.ico" '(jenkinscat.file-handlers/return-file "favicon.ico" "image/x-icon")
+ "/jenkinscat.gif" '(jenkinscat.file-handlers/return-file "jenkinscat.gif" "image/gif")
+ "/jenkinscat.png" '(jenkinscat.file-handlers/return-file "jenkinscat.png" "image/png")
+ "/stopwatch2.png" '(jenkinscat.file-handlers/return-file "stopwatch2.png" "image/png")
+ "/erase-l.gif" '(jenkinscat.file-handlers/return-file "erase-l.gif" "image/gif")
+ ; this one is there only for test purposes
+ ;"/data.json" '(jenkinscat.file-handlers/return-file "data.json" "application/json")
+
+ "/css/bootstrap.css" '(jenkinscat.file-handlers/return-file "/css/bootstrap.css" "text/css")
+ "/css/bootstrap.css.map" '(jenkinscat.file-handlers/return-file "/css/bootstrap.css.map" "text/css")
+ "/css/bootstrap.min.css" '(jenkinscat.file-handlers/return-file "/css/bootstrap.min.css" "text/css")
+ "/css/bootstrap-theme.css" '(jenkinscat.file-handlers/return-file "/css/bootstrap-theme.css" "text/css")
+ "/css/bootstrap-theme.css.map" '(jenkinscat.file-handlers/return-file "/css/bootstrap-theme.css.map" "text/css")
+ "/css/bootstrap-theme.min.css" '(jenkinscat.file-handlers/return-file "/css/bootstrap-theme.min.css" "text/css")
+ "/css/Jenkinscat.css" '(jenkinscat.file-handlers/return-file "/css/Jenkinscat.css" "text/css")
+
+ "/js/angular.min.js" '(jenkinscat.file-handlers/return-file "/js/angular.min.js" "application/javascript")
+ "/js/bootstrap.js" '(jenkinscat.file-handlers/return-file "/js/bootstrap.js" "application/javascript")
+ "/js/bootstrap.min.js" '(jenkinscat.file-handlers/return-file "/js/bootstrap.min.js" "application/javascript")
+ "/js/jenkinscat.js" '(jenkinscat.file-handlers/return-file "/js/jenkinscat.js" "application/javascript")
+ "/js/jquery.min.js" '(jenkinscat.file-handlers/return-file "/js/jquery.min.js" "application/javascript")
+
+ "/fonts/glyphicons-halflings-regular.eot" '(jenkinscat.file-handlers/return-file "/fonts/glyphicons-halflings-regular.eot" "application/vnd.ms-fontobject")
+ "/fonts/glyphicons-halflings-regular.svg" '(jenkinscat.file-handlers/return-file "/fonts/glyphicons-halflings-regular.svg" "image/svg+xml")
+ "/fonts/glyphicons-halflings-regular.ttf" '(jenkinscat.file-handlers/return-file "/fonts/glyphicons-halflings-regular.ttf" "application/x-font-ttf")
+ "/fonts/glyphicons-halflings-regular.woff" '(jenkinscat.file-handlers/return-file "/fonts/glyphicons-halflings-regular.woff" "application/font-woff")
+})
+
+(defn get-file-handler
+ "Return selected file handler or nil in case the handler is unknown."
+ [uri]
+ (get file-handlers uri nil))
+
diff --git a/src/jenkinscat/fileutils.clj b/src/jenkinscat/fileutils.clj
index b556a5a..cd9d4a1 100644
--- a/src/jenkinscat/fileutils.clj
+++ b/src/jenkinscat/fileutils.clj
@@ -1,3 +1,6 @@
+;;;
+;;; Jenkinscat HTTP server that handles all requests send from clients/browsers.
+;;;
;;; Copyright (c) 2014 Pavel Tisnovsky, Red Hat
;;; All rights reserved.
;;;
More information about the docs-commits
mailing list