[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Tatiana |
Date: |
Wed, 23 May 2018 09:37:38 -0400 (EDT) |
branch: web-interface
commit a4fe6dd0d0c82c84a810d3368dd60fea3aa1b2b0
Author: TSholokhova <address@hidden>
Date: Wed May 23 16:37:23 2018 +0300
basic html templates
---
Makefile.am | 3 ++-
src/cuirass/http.scm | 15 +++++++++++++++
src/cuirass/templates.scm | 32 ++++++++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index d372b9e..75848ef 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,7 +39,8 @@ dist_pkgmodule_DATA = \
src/cuirass/http.scm \
src/cuirass/logging.scm \
src/cuirass/ui.scm \
- src/cuirass/utils.scm
+ src/cuirass/utils.scm \
+ src/cuirass/templates.scm
nodist_pkgmodule_DATA = \
src/cuirass/config.scm
diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm
index e911b9b..f5e3ac1 100644
--- a/src/cuirass/http.scm
+++ b/src/cuirass/http.scm
@@ -1,3 +1,4 @@
+
;;;; http.scm -- HTTP API
;;; Copyright © 2016 Mathieu Lirzin <address@hidden>
;;; Copyright © 2017 Mathieu Othacehe <address@hidden>
@@ -32,6 +33,8 @@
#:use-module (web uri)
#:use-module (fibers)
#:use-module (fibers channels)
+ #:use-module (sxml simple)
+ #:use-module (cuirass templates)
#:export (run-cuirass-server))
(define (build->hydra-build build)
@@ -112,6 +115,7 @@ Hydra format."
;;; https://github.com/NixOS/hydra/blob/master/doc/manual/api.xml
;;;
+
(define (request-path-components request)
(split-and-decode-uri-path (uri-path (request-uri request))))
@@ -135,6 +139,12 @@ Hydra format."
#:body
(object->json-string
`((error . ,message)))))
+
+ (define (respond-html body)
+ (respond '((content-type . (text/html)))
+ #:body (lambda (port)
+ (sxml->xml body port)
+ )))
(define (respond-build-not-found build-id)
(respond-json-with-error
@@ -223,6 +233,11 @@ Hydra format."
,@params
(order status+submission-time)))))
(respond-json-with-error 500 "Parameter not defined!"))))
+ (("status")
+ (respond-html (templatize
+ "Status"
+ (specifications-table
+ (with-critical-section db-channel (db)
(db-get-specifications db))))))
('method-not-allowed
;; 405 "Method Not Allowed"
(values (build-response #:code 405) #f db-channel))
diff --git a/src/cuirass/templates.scm b/src/cuirass/templates.scm
new file mode 100644
index 0000000..ff63469
--- /dev/null
+++ b/src/cuirass/templates.scm
@@ -0,0 +1,32 @@
+(define-module (cuirass templates)
+ #:export (templatize
+ specifications-table))
+
+
+(define (templatize title body)
+ `(html
+ ,(head title)
+ (body ,body)))
+
+
+(define (head title)
+ `(head
+ (meta (@ (charset "utf-8")))
+ (title ,title)))
+
+
+(define (specifications-table specs)
+ `(table
+ (@ (class "table-fill"))
+ (thead
+ (tr
+ (th (@ (class "text-left")) Name)
+ (th (@ (class "text-left")) Branch)))
+ (tbody
+ (@ (class "table-fill"))
+ ,@(map
+ (lambda (spec)
+ `(tr
+ (td ,(assq-ref spec #:name))
+ (td ,(assq-ref spec #:branch))))
+ specs))))