aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-30 01:45:33 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-07-07 13:10:38 +0200
commitd6304f9b0acd3894fd08fccee75ab47d10f9a64a (patch)
tree51c08b7e65d7ce41d97f51dcbe2557c1b851fd3b
parentAdd basic event creation from HTML. (diff)
downloadcalp-d6304f9b0acd3894fd08fccee75ab47d10f9a64a.tar.gz
calp-d6304f9b0acd3894fd08fccee75ab47d10f9a64a.tar.xz
Rename attributes => properties, properties => parameters.
-rw-r--r--module/output/common.scm2
-rw-r--r--module/output/ical.scm10
-rw-r--r--module/output/types.scm6
-rw-r--r--module/output/xcal.scm22
-rw-r--r--module/vcomponent/base.scm69
-rw-r--r--module/vcomponent/describe.scm6
-rw-r--r--tests/prop.scm12
-rw-r--r--tests/xcal.scm8
8 files changed, 76 insertions, 59 deletions
diff --git a/module/output/common.scm b/module/output/common.scm
index 3955442f..0d266d01 100644
--- a/module/output/common.scm
+++ b/module/output/common.scm
@@ -32,7 +32,7 @@
equal? (lset-union
equal? '("dummy")
(filter-map
- (lambda (vline) (and=> (prop vline 'TZID) car))
+ (lambda (vline) (and=> (param vline 'TZID) car))
(filter-map (extract* 'DTSTART)
events)))
'("dummy" "local")))
diff --git a/module/output/ical.scm b/module/output/ical.scm
index 114178c6..de6a351d 100644
--- a/module/output/ical.scm
+++ b/module/output/ical.scm
@@ -28,7 +28,7 @@
;; fields which can hold lists need not be considered here,
;; since they are split into multiple vlines when we parse them.
(cond
- [(and=> (prop vline 'VALUE) string->symbol) => get-writer]
+ [(and=> (param vline 'VALUE) string->symbol) => get-writer]
[(memv key '(COMPLETED DTEND DUE DTSTART RECURRENCE-ID
CREATED DTSTAMP LAST-MODIFIED
ACKNOWLEDGED EXDATE))
@@ -128,7 +128,7 @@
";" (symbol->string key)
(string-join (map (compose (get-writer 'TEXT) ->string) values)
"," 'infix))])
- (properties vline)))
+ (parameters vline)))
":" (value-format key vline))))
(define-public (component->ical-string component)
@@ -150,7 +150,7 @@
[(key vline)
(display (vline->string vline))
(display "\r\n")])
- (attributes component))
+ (properties component))
(for-each component->ical-string (children component))
(format #t "END:~a\r\n" (type component))
@@ -159,7 +159,7 @@
=> (lambda (alts) (hash-map->list (lambda (_ comp) (component->ical-string comp))
alts))]))
-;; TODO tzid prop on dtstart vs tz field in datetime object
+;; TODO tzid param on dtstart vs tz field in datetime object
;; how do we keep these two in sync?
(define (write-event-to-file event calendar-path)
(define cal (make-vcomponent 'VCALENDAR))
@@ -170,7 +170,7 @@
(add-child! cal event)
- (awhen (prop (attr* event 'DTSTART) 'TZID)
+ (awhen (param (attr* event 'DTSTART) 'TZID)
;; TODO this is broken
(add-child! cal (zoneinfo->vtimezone (getf 'zoneinfo) it)))
diff --git a/module/output/types.scm b/module/output/types.scm
index 22f3ca5b..e5829ccf 100644
--- a/module/output/types.scm
+++ b/module/output/types.scm
@@ -16,12 +16,12 @@
(define (write-date _ value)
(date->string value "~Y~m~d"))
-(define (write-datetime prop value)
- (datetime->string (hashq-ref prop 'X-HNH-ORIGINAL value)
+(define (write-datetime param value)
+ (datetime->string (hashq-ref param 'X-HNH-ORIGINAL value)
;; TODO ~Z ?
"~Y~m~dT~H~M~S~Z"
#;
- (let ((tz (and=> (prop vline 'TZID) car)))
+ (let ((tz (and=> (param vline 'TZID) car)))
(when (and tz (string= tz "UTC"))
(display #\Z)))))
diff --git a/module/output/xcal.scm b/module/output/xcal.scm
index b5eda1df..eb244921 100644
--- a/module/output/xcal.scm
+++ b/module/output/xcal.scm
@@ -17,7 +17,7 @@
(define writer
(cond
- [(and=> (prop vline 'VALUE) (compose string->symbol car))
+ [(and=> (param vline 'VALUE) (compose string->symbol car))
=> get-writer]
[(memv key '(COMPLETED DTEND DUE DTSTART RECURRENCE-ID
CREATED DTSTAMP LAST-MODIFIED
@@ -87,13 +87,13 @@
values))))
;; ((key value ...) ...) -> `(parameters , ... )
-(define (parameters-tag properties)
- (define outprops (filter-map
- (lambda (x) (apply property->value-tag x))
- properties))
+(define (parameters-tag parameters)
+ (define outparams (filter-map
+ (lambda (x) (apply property->value-tag x))
+ parameters))
- (unless (null? outprops)
- `(parameters ,@outprops)))
+ (unless (null? outparams)
+ `(parameters ,@outparams)))
(define-public (vcomponent->sxcal component)
@@ -103,7 +103,7 @@
(remove null?
`(,tagsymb
;; TODO only have <properties> when it's non-empty.
- ;; This becomes MUCH easier once attributes stop returning
+ ;; This becomes MUCH easier once properties stop returning
;; a hash-map...
(properties
,@(filter
@@ -116,16 +116,16 @@
(remove null?
`(,(downcase-symbol key)
,(parameters-tag (reduce assq-merge
- '() (map properties vlines)))
+ '() (map parameters vlines)))
,@(for vline in vlines
(vline->value-tag vline))))]
[(key vline)
(remove null?
`(,(downcase-symbol key)
- ,(parameters-tag (properties vline))
+ ,(parameters-tag (parameters vline))
,(vline->value-tag vline)))])
- (attributes component))))
+ (properties component))))
,(unless (null? (children component))
`(components ,@(map vcomponent->sxcal (children component)))))))
diff --git a/module/vcomponent/base.scm b/module/vcomponent/base.scm
index 2748e8be..e5bca46e 100644
--- a/module/vcomponent/base.scm
+++ b/module/vcomponent/base.scm
@@ -10,6 +10,18 @@
+;;; <vcomponent>
+;;; <properties>
+;;; <dtstart>
+;;; <parameters>
+;;; <tzid><text>Europe/Stockholm</text></tzid>
+;;; </parameters>
+;;; 2020-01-01T13:37:50
+;;; </dtstart>
+;;; </properties>
+;;; </vcomponent>
+;;;
+
;; The <vline> type is a bit to many times refered to as a attr ptr.
(define-record-type <vline>
(make-vline% key value parameters)
@@ -38,12 +50,12 @@
(make-vline% key value ht))
(define-record-type <vcomponent>
- (make-vcomponent% type children parent attributes)
+ (make-vcomponent% type children parent properties)
vcomponent?
(type type)
(children children set-component-children!)
(parent get-component-parent set-component-parent!)
- (attributes get-component-attributes))
+ (properties get-component-properties))
(export vcomponent? children type)
((@ (srfi srfi-9 gnu) set-record-type-printer!)
@@ -67,24 +79,24 @@
(set-component-parent! child parent))
;; TODO this doesn't handle multi-valued items
-(define* (get-attribute-value component key #:optional default)
- (cond [(hashq-ref (get-component-attributes component)
+(define* (get-property-value component key #:optional default)
+ (cond [(hashq-ref (get-component-properties component)
key #f)
=> get-vline-value]
[else default]))
-(define (get-attribute component key)
- (hashq-ref (get-component-attributes component)
+(define (get-property component key)
+ (hashq-ref (get-component-properties component)
key))
-(define (set-attribute! component key value)
- (let ((ht (get-component-attributes component)))
+(define (set-property! component key value)
+ (let ((ht (get-component-properties component)))
(cond [(hashq-ref ht key #f)
=> (lambda (vline) (set-vline-value! vline value))]
[else (hashq-set! ht key (make-vline key value))])))
(define-public (set-vline! component key vline)
- (hashq-set! (get-component-attributes component)
+ (hashq-set! (get-component-properties component)
key vline))
@@ -94,13 +106,16 @@
(make-procedure-with-setter
get-vline-value set-vline-value!))
+;;; TODO all these set-attr should be set-prop, but
+;;; set-prop is already used by what should be set-param.
+
;; vcomponent x (or str symb) → vline
(define (get-attr* component attr)
- (hashq-ref (get-component-attributes component)
+ (hashq-ref (get-component-properties component)
(as-symb attr)))
(define (set-attr*! component key value)
- (hashq-set! (get-component-attributes component)
+ (hashq-set! (get-component-properties component)
(as-symb key) value))
(define-public attr*
@@ -117,7 +132,7 @@
;; TODO do something sensible here
(define (set-attr! component key value)
- (set-attribute! component (as-symb key) value))
+ (set-property! component (as-symb key) value))
(define-public attr
(make-procedure-with-setter
@@ -125,34 +140,34 @@
set-attr!))
-(define-public prop
+(define-public param
(make-procedure-with-setter
- (lambda (attr-obj prop-key)
+ (lambda (vline parameter-key)
;; TODO `list' is a hack since a bit to much code depends
;; on prop always returning a list of values.
- (and=> (hashq-ref (get-vline-parameters attr-obj)
- (as-symb prop-key))
+ (and=> (hashq-ref (get-vline-parameters vline)
+ (as-symb parameter-key))
list))
- (lambda (attr-obj prop-key val)
- (hashq-set! (get-vline-parameters attr-obj)
- (as-symb prop-key) val))))
+ (lambda (vline parameter-key val)
+ (hashq-set! (get-vline-parameters vline)
+ (as-symb parameter-key) val))))
;; Returns the properties of attribute as an assoc list.
;; @code{(map car <>)} leads to available properties.
;; TODO shouldn't this be called parameters?
-(define-public (properties attrptr)
+(define-public (parameters attrptr)
(hash-map->list list (get-vline-parameters attrptr)))
-(define-public (attributes component)
- (get-component-attributes component))
+(define-public (properties component)
+ (get-component-properties component))
-(define-public (attribute-keys component)
- (map car (hash-map->list cons (get-component-attributes component))))
+(define-public (property-keys component)
+ (map car (hash-map->list cons (get-component-properties component))))
(define (copy-vline vline)
(make-vline (vline-key vline)
(get-vline-value vline)
- ;; TODO deep-copy on properties?
+ ;; TODO deep-copy on parameters?
(get-vline-parameters vline)))
(define-public (copy-vcomponent component)
@@ -160,13 +175,13 @@
(type component)
(children component)
(parent component)
- ;; attributes
+ ;; properties
(alist->hashq-table
(hash-map->list (lambda (key value)
(cons key (if (list? value)
(map copy-vline value)
(copy-vline value))))
- (get-component-attributes component)))))
+ (get-component-properties component)))))
(define-public (extract field)
(lambda (e) (attr e field)))
diff --git a/module/vcomponent/describe.scm b/module/vcomponent/describe.scm
index 4e89f5e8..a16c67d0 100644
--- a/module/vcomponent/describe.scm
+++ b/module/vcomponent/describe.scm
@@ -9,7 +9,7 @@
(define maxlen (find-max (hash-map->list
(lambda (a _) (string-length (symbol->string a)))
- (attributes vcomponent))))
+ (properties vcomponent))))
(format #t "~aBEGIN ~a~%" ii (type vcomponent))
@@ -20,12 +20,12 @@
(trim-to-width
(format #f "~a" (value vline))
(- 80 indent maxlen)))
- (awhen (properties vline)
+ (awhen (parameters vline)
(display " ;")
(for (key value) in it
(format #t " ~a=~a" key value)))
(newline))
- (attributes vcomponent))
+ (properties vcomponent))
(for child in (children vcomponent)
(describe child (+ indent 2)))
diff --git a/tests/prop.scm b/tests/prop.scm
index a178170d..60831e14 100644
--- a/tests/prop.scm
+++ b/tests/prop.scm
@@ -1,4 +1,6 @@
-(((vcomponent base) prop attr* properties)
+;;; TODO rename this file to param.scm
+
+(((vcomponent base) param attr* parameters)
((vcomponent parse) parse-calendar)
((util) sort*))
@@ -8,10 +10,10 @@ KEY;A=1;B=2:Some text
END:DUMMY"
parse-calendar))
-(test-equal '("1") (prop (attr* v 'KEY) 'A))
-(test-equal '("2") (prop (attr* v 'KEY) 'B))
-(test-equal #f (prop (attr* v 'KEY) 'C))
+(test-equal '("1") (param (attr* v 'KEY) 'A))
+(test-equal '("2") (param (attr* v 'KEY) 'B))
+(test-equal #f (param (attr* v 'KEY) 'C))
-(test-equal '(A B) (sort* (map car (properties (attr* v 'KEY)))
+(test-equal '(A B) (sort* (map car (parameters (attr* v 'KEY)))
string<?
symbol->string))
diff --git a/tests/xcal.scm b/tests/xcal.scm
index 938a39b0..78e7e7df 100644
--- a/tests/xcal.scm
+++ b/tests/xcal.scm
@@ -3,7 +3,7 @@
((output xcal) vcomponent->sxcal)
((util) ->)
((vcomponent base)
- properties attr* children)
+ parameters attr* children)
)
;;; Some different types, same parameters
@@ -33,13 +33,13 @@ END:VCALENDAR"
vcomponent->sxcal
sxcal->vcomponent))
-;;; NOTE both these tests may fail since neither attributes nor properties are ordered sorted.
+;;; NOTE both these tests may fail since neither properties nor parameters are ordered sorted.
(test-equal "c->x & c->x->c->x"
(vcomponent->sxcal ev)
(vcomponent->sxcal twice-converted))
-(test-equal "xcal properties"
+(test-equal "xcal parameters"
'((X-TEST-PARAM "10"))
- (properties (attr* (car (children twice-converted))
+ (parameters (attr* (car (children twice-converted))
'STATUS)))