From a18c7e898949ed53453d983e73d741395fb140ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 11 Jul 2020 17:38:03 +0200 Subject: Add (vcomponent build). --- module/vcomponent/build.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 module/vcomponent/build.scm diff --git a/module/vcomponent/build.scm b/module/vcomponent/build.scm new file mode 100644 index 00000000..dd3431c1 --- /dev/null +++ b/module/vcomponent/build.scm @@ -0,0 +1,38 @@ +;;; Commentary: +;; Module for quickly building new vcomponents from code. +;; @example +;; (vevent +;; summary: "This is a test event" +;; dtstart: #2020-01-01T13:37:00 +;; children: (list +;; (valarm ...))) +;;; Code: + +(define-module (vcomponent build) + :use-module (util) + :use-module (vcomponent base) + :use-module (srfi srfi-26) + :use-module ((srfi srfi-88) :select (keyword->string))) + +(define-public (vevent . body) (apply vcomponent 'VEVENT body)) +(define-public (vcalendar . body) (apply vcomponent 'VCALENDAR body)) +(define-public (valarm . body) (apply vcomponent 'VALARM body)) + +(define-public (vcomponent tag . rest) + (define v (make-vcomponent tag)) + + (let loop ((rem rest)) + (unless (null? rem) + (if (eq? children: (car rem)) + (for-each (cut add-child! v <>) (cadr rem)) + (let ((symb (-> (car rem) + keyword->string + string-upcase + string->symbol))) + (set! (prop v symb) (cadr rem)))) + (loop (cddr rem)))) + + ;; Return + v) + + -- cgit v1.2.3