(module html-utils (tabularize itemize enumerate html-page combo-box hidden-input text-input password-input submit-input) (import chicken scheme files data-structures posix utils) (use html-tags srfi-13 srfi-1) (define (list-attribs attribs) (let ((attribs (filter-map (lambda (attrib) (let ((value (cdr attrib))) (and value (list (car attrib) value)))) attribs))) (if (null? attribs) '() (list (cons '@ attribs))))) ;;; tabularize (define (sxml-tabularize data #!key table-id table-class even-row-class odd-row-class header thead/tbody) (let ((even-row #f)) (append '(table) (list-attribs `((id . ,table-id) (class . ,table-class))) (if header (let ((h `(tr ,@(map (lambda (item) `(th ,item)) header)))) (if thead/tbody `((thead ,h)) `(,h))) '()) (let ((body (map (lambda (line) (append '(tr) (list-attribs `((class . ,(if even-row even-row-class odd-row-class)))) (begin (set! even-row (not even-row)) (map (lambda (cell) `(td ,cell)) line)))) data))) (if thead/tbody `((tbody ,body)) body))))) (define (tabularize data #!key table-id table-class quote-procedure even-row-class odd-row-class header thead/tbody) (if (generate-sxml?) (sxml-tabularize data table-id: table-id table-class: table-class even-row-class: even-row-class odd-row-class: odd-row-class header: header thead/tbody: thead/tbody) (let ((even-row #f)) ( id: table-id class: table-class quote-procedure: quote-procedure (string-append (if header (let ((h ( (string-intersperse (map h) h)) "") (let ((body (string-intersperse (map (lambda (line) ( class: (and even-row-class odd-row-class (begin (set! even-row (not even-row)) (if even-row even-row-class odd-row-class))) (string-intersperse (map body) body))))))) ;;; itemize & enumerate (define (sxml-list listing self items #!key list-id list-class) (cons listing (append (list-attribs `((id . ,list-id) (class . ,list-class))) (map (lambda (item) (if (and (list? item) (eq? (car item) listing)) item `(li ,item))) items)))) (define (html-list listing self items #!key list-id list-class quote-procedure) (if (generate-sxml?) (sxml-list 'ul itemize items list-id: list-id list-class: list-class) (listing id: list-id class: list-class quote-procedure: quote-procedure (string-intersperse (map (lambda (item) (if (list? item) (self item quote-procedure: quote-procedure) (
  • item))) items) "")))) (define (itemize items #!key list-id list-class quote-procedure) (html-list
  • header) "")))) (if thead/tbody (
    line) ""))) data) ""))) (if thead/tbody (