From edaf758b80fed1f5f14cd4b192e661c8863e84bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 23 Aug 2020 23:22:10 +0200 Subject: Move html modules under calp. --- module/calp/entry-points/html.scm | 8 +- module/calp/html/caltable.scm | 89 +++++++++ module/calp/html/components.scm | 127 +++++++++++++ module/calp/html/config.scm | 18 ++ module/calp/html/util.scm | 46 +++++ module/calp/html/vcomponent.scm | 229 +++++++++++++++++++++++ module/calp/html/view/calendar.scm | 289 ++++++++++++++++++++++++++++++ module/calp/html/view/calendar/month.scm | 117 ++++++++++++ module/calp/html/view/calendar/shared.scm | 96 ++++++++++ module/calp/html/view/calendar/week.scm | 121 +++++++++++++ module/calp/html/view/search.scm | 38 ++++ module/calp/html/view/small-calendar.scm | 19 ++ module/calp/server/routes.scm | 12 +- module/html/caltable.scm | 89 --------- module/html/components.scm | 127 ------------- module/html/config.scm | 18 -- module/html/util.scm | 46 ----- module/html/vcomponent.scm | 229 ----------------------- module/html/view/calendar.scm | 289 ------------------------------ module/html/view/calendar/month.scm | 117 ------------ module/html/view/calendar/shared.scm | 96 ---------- module/html/view/calendar/week.scm | 121 ------------- module/html/view/search.scm | 38 ---- module/html/view/small-calendar.scm | 19 -- 24 files changed, 1199 insertions(+), 1199 deletions(-) create mode 100644 module/calp/html/caltable.scm create mode 100644 module/calp/html/components.scm create mode 100644 module/calp/html/config.scm create mode 100644 module/calp/html/util.scm create mode 100644 module/calp/html/vcomponent.scm create mode 100644 module/calp/html/view/calendar.scm create mode 100644 module/calp/html/view/calendar/month.scm create mode 100644 module/calp/html/view/calendar/shared.scm create mode 100644 module/calp/html/view/calendar/week.scm create mode 100644 module/calp/html/view/search.scm create mode 100644 module/calp/html/view/small-calendar.scm delete mode 100644 module/html/caltable.scm delete mode 100644 module/html/components.scm delete mode 100644 module/html/config.scm delete mode 100644 module/html/util.scm delete mode 100644 module/html/vcomponent.scm delete mode 100644 module/html/view/calendar.scm delete mode 100644 module/html/view/calendar/month.scm delete mode 100644 module/html/view/calendar/shared.scm delete mode 100644 module/html/view/calendar/week.scm delete mode 100644 module/html/view/search.scm delete mode 100644 module/html/view/small-calendar.scm (limited to 'module') diff --git a/module/calp/entry-points/html.scm b/module/calp/entry-points/html.scm index abaa5f13..b2f613ea 100644 --- a/module/calp/entry-points/html.scm +++ b/module/calp/entry-points/html.scm @@ -8,11 +8,11 @@ :use-module ((ice-9 regex) :select (string-match regexp-substitute)) :use-module ((srfi srfi-41) :select (stream-take stream-for-each)) - :use-module ((html view calendar) :select (html-generate)) - :use-module ((html view calendar week) + :use-module ((calp html view calendar) :select (html-generate)) + :use-module ((calp html view calendar week) :select (render-calendar) :renamer (lambda _ 'render-calendar-wide)) - :use-module ((html view calendar month) + :use-module ((calp html view calendar month) :select (render-calendar-table)) :use-module ((vcomponent instance methods) :select (get-calendars get-event-set)) @@ -144,7 +144,7 @@ (lambda () (sxml->xml (re-root-static - ((@ (html view small-calendar) render-small-calendar) + ((@ (calp html view small-calendar) render-small-calendar) start standalone))))))] [(wide) diff --git a/module/calp/html/caltable.scm b/module/calp/html/caltable.scm new file mode 100644 index 00000000..65a70252 --- /dev/null +++ b/module/calp/html/caltable.scm @@ -0,0 +1,89 @@ +(define-module (calp html caltable) + :use-module (util) + :use-module (calp html util) + :use-module (datetime) + :use-module (srfi srfi-41) + ) + +;; Small calendar similar to the one below. +;; TODO highlight days depending on which events they contain +;; TODO run this standalone, for embedding in other websites. +;; @example +;; må ti on to fr lö sö +;; 1 2 3 4 5 6 7 +;; 8 9 10 11 12 13 14 +;; 15 16 17 18 19 20 21 +;; 22 23 24 25 26 27 28 +;; 29 30 +;; @end example +;; +;; start-date : +;; end-date : +;; next-start : +;; prev-start : +(define*-public (cal-table key: start-date end-date next-start prev-start) + + (define (->link date) + (date->string date "~Y-~m-~d.html")) + + ;; ( → sxml-attributes) → → sxml + (define (td attr) + (lambda (date) + `(a (@ ,@(attr date)) + ;; NOTE This time object is the correct place to show the existance + ;; of an event on a given day in this small calendar. For example + ;; making the text red for all holidays, or creating a yellow background + ;; for events from a specific source. + (time (@ (datetime ,(date->string date "~Y-~m-~d"))) + ,(day date))))) + + (define month-start (start-of-month start-date)) + (define pre-start (start-of-week month-start)) + (define month-end (end-of-month start-date)) + (define post-end (end-of-week month-end)) + + `(div (@ (class "small-calendar")) + + ;; Cell 0, 0. The letter v. for week number + (div (@ (class "column-head row-head")) "v.") + + ;; top row, names of week days + ,@(map (lambda (d) `(div (@ (class "column-head")) + ,(string-titlecase (week-day-name d 2)))) + (weekday-list)) + + ;; left columun, week numbers + ,@(map (lambda (v) `(div (@ (class "row-head")) ,v)) + (map week-number + (stream->list + (stream-take-while (lambda (s) (date<= s post-end)) + (week-stream pre-start))))) + + ;; actual days + + ,@(map (td (lambda (date) + `((class "prev") + (href ,(->link + ;; (prev-start date) + (iterate + prev-start + (lambda (d) (date<= d date (next-start d))) + start-date)) + "#" ,(date-link date))))) + (date-range pre-start (remove-day start-date))) + + + ,@(map (td (lambda (date) `((href "#" ,(date-link date))))) + (date-range start-date end-date)) + + + ,@(map (td (lambda (date) + `((class "next") + (href ,(->link + ;; (next-start date) + (iterate + next-start + (lambda (d) (and (date<= d date) + (date< date (next-start d)))) + start-date)) "#" ,(date-link date))))) + (date-range (add-day end-date) post-end)))) diff --git a/module/calp/html/components.scm b/module/calp/html/components.scm new file mode 100644 index 00000000..49f00e52 --- /dev/null +++ b/module/calp/html/components.scm @@ -0,0 +1,127 @@ +(define-module (calp html components) + :use-module (util) + :use-module (util exceptions) + :export (xhtml-doc) + ) + +;; Wraps a number of sxml forms into a valid sxhtml-tree. +(define-syntax xhtml-doc + (syntax-rules (@) + ((_ (@ attr ...) body ...) + `(*TOP* + (*PI* xml "version=\"1.0\" encoding=\"utf-8\"") + (html (@ (xmlns "http://www.w3.org/1999/xhtml") attr ...) + body ...))) + ((_ body ...) + (xhtml-doc (@) body ...)))) + + +;; Add a slider with an associated number input. Keeps the two in check. +;; Uses the js function setVar (which must be provided elsewhere) +;; set the the value of @var{variable}. +(define*-public (slider-input key: variable + (min 0) + (max 10) + (step 1) + (value 1) + (unit "")) + (let ((groupname (symbol->string (gensym "slider")))) + `(div (@ (class "input-group")) + (script + "function " ,groupname "fn (value) {" + "setVar('" ,variable "', value + '" ,unit "');" + "for (let el of document.getElementsByClassName('" ,groupname "')) {" + " el.value = value;" + "}}") + (input (@ (type "range") + (class ,groupname) + (min ,min) + (max ,max) + (step ,step) + (value ,value) + (oninput ,groupname "fn(this.value)") + )) + (input (@ (type "number") + (class ,groupname) + (min ,min) + (max ,max) + (step ,step) + (value ,value) + (oninput ,groupname "fn(this.value)")) + )))) + +;; Generates a button or button-like link. +;; TODO
inside