diff options
author | Hugo Hörnquist <hugo@hornquist.se> | 2019-02-26 00:56:37 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@hornquist.se> | 2019-02-26 00:57:41 +0100 |
commit | 8bd1110f6b45c62f835ea69742d9e179d56ba542 (patch) | |
tree | b47a468ab971330484e1a83845c87ae80c0a25ec | |
parent | Add vcompponent_push_child_x. (diff) | |
download | calp-8bd1110f6b45c62f835ea69742d9e179d56ba542.tar.gz calp-8bd1110f6b45c62f835ea69742d9e179d56ba542.tar.xz |
Start on propper vcalendar scheme library.
-rwxr-xr-x | code.scm | 26 | ||||
-rw-r--r-- | vcalendar.scm | 38 |
2 files changed, 43 insertions, 21 deletions
@@ -2,30 +2,14 @@ -s !# -(begin - ;; Supurflous begin block here to make sourcing into geiser easier. - (setenv "LD_LIBRARY_PATH" (getcwd)) - (load-extension "libguile-calendar" "init_lib")) - -(define make-vcomponent %vcomponent-make) -(define children %vcomponent-children) -(define set-attr! %vcomponent-set-attribute!) -(define get-attr %vcomponent-get-attribute) - -(define root (make-vcomponent "testcal/d1-b.ics")) -(define cal (car (children root))) - -;; TODO flatten all calendars into root - +(add-to-load-path (dirname (current-filename))) (use-modules (srfi srfi-19) - (srfi srfi-26)) + (srfi srfi-26) + (vcalendar)) -(define (mutate-attr! ev field transformer) - (set-attr! ev field - (transformer - (get-attr ev field)))) +(define cal (make-vcomponent "testcal/d1-b.ics")) -(for-each (cut mutate-attr! <> "DTSTART" +(for-each (cut transform-attr! <> "DTSTART" (cut string->date <> "~Y~m~dT~H~M~S")) (children cal)) diff --git a/vcalendar.scm b/vcalendar.scm new file mode 100644 index 00000000..b80e40e6 --- /dev/null +++ b/vcalendar.scm @@ -0,0 +1,38 @@ +(define-module (vcalendar) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:export (make-vcomponent children set-attr! get-attr type + transform-attr! push-child!)) + +(setenv "LD_LIBRARY_PATH" (dirname (current-filename))) +(load-extension "libguile-calendar" "init_lib") + +(define (make-vcomponent path) + (if (string-ci=? ".ics" (string-take-right path 4)) + ;; == Single ICS file == + ;; Remove the abstract ROOT component, + ;; returning the wanted VCALENDAR component + (car (%vcomponent-children + (%vcomponent-make path))) + ;; == Assume vdir == + ;; Also removes the abstract ROOT component, but also + ;; merges all VCALENDAR's children into the first + ;; VCALENDAR, and return that VCALENDAR. + (reduce (lambda (cal accum) + (for-each (cut %vcomponent-push-child! accum <>) + (%vcomponent-children cal)) + accum) + '() (%vcomponent-children (%vcomponent-make path))))) + +(define children %vcomponent-children) +(define set-attr! %vcomponent-set-attribute!) +(define get-attr %vcomponent-get-attribute) +(define type %vcomponent-type) + +(define push-child! %vcomponent-push-child!) + +(define (transform-attr! ev field transformer) + "Apply transformer to field in ev, and store the result back." + (set-attr! ev field + (transformer + (get-attr ev field)))) |