summaryrefslogtreecommitdiffstats
path: root/apps/base/types.scm
blob: 91e97292e233b195f7cd63e76342032cd1558fb9 (plain)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
;;; Harmonic Flow web site

(define-module (apps base types)
  #:use-module (srfi srfi-9)
  #:export (contact
	    contact?
	    contact-description
	    contact-log
	    contact-name
	    contact-url
	    context-datum
	    crumb
	    crumb?
	    crumb-label
            crumb-url))


;;;
;;; Data types.
;;;

;;; Contact (record type)
;;; ---------------------
;;;
;;; A contact object represents a contact medium such as a mailing
;;; list, IRC channel, email address, etc.
;;;
;;; Objects of this type can be created with the "contact"
;;; procedure as well (see Helper procedures below).
;;;
;;; Fields:
;;;
;;; name (string)
;;;   The name of the contact medium. For example:
;;;   "Development mailing list".
;;;
;;; description (SXML)
;;;   A short description. For example:
;;;   '(p "Discussion about the development of Guix.").
;;;
;;; url (string)
;;;   A URL to the main page of the contact medium.
;;;
;;; log (string)
;;;   A URL to the archive or log of previous public communications
;;;   help on the contact medium (empty string if there is no log).
;;;
(define-record-type <contact>
  (make-contact name description url log)
  contact?
  (name contact-name)
  (description contact-description)
  (url contact-url)
  (log contact-log))

;;; Helper procedures.

(define* (contact #:key (name "") (description "") (url "") (log ""))
  "Return a <contact> object with the given attributes."
  (make-contact name description url log))



;;; Context (association list)
;;; --------------------------
;;;
;;; A context object is a collection of data to be rendered in the
;;; template of a web resource.
;;;
;;; A context can have any number of custom keys depending on the
;;; requirements of a given template.
;;;
;;; The following is an example of a context object to be used with an
;;; SHTML template:
;;;
(define some-context
  (list
   (cons "LANGUAGE" "es")
   (cons "CHARSET" "UTF-8")
   (cons "AUTHOR" "Jane Roe")
   (cons "FRIENDS" (list "John Doe" "Nyoro N." "Jack the Lad"))))

;;; Helper procedures.

(define (context-datum context key)
  "Return the value of KEY in the given CONTEXT.

   CONTEXT (Context)
     See more information about the Context type in (apps base types).

   KEY (atom)
     Any atomic value allowed for association list keys."
  (assoc-ref context key))



;;; Crumb (record type)
;;; -------------------
;;;
;;; A crumb object represents one of the parts of a breadcrumbs
;;; component of a website.
;;;
;;; Objects of this type can be created with the "crumb" procedure as
;;; well (see Helper procedures below).
;;;
;;; Fields:
;;;
;;; label (string)
;;;   A human readable name for the crumb. For example: "Blog".
;;;
;;; url (string)
;;;   The URL to the web resource related to the crumb.
;;;
(define-record-type <crumb>
  (make-crumb label url)
  crumb?
  (label crumb-label)
  (url crumb-url))

;;; Helper procedures.

(define (crumb label url)
  "Return a <crumb> object with the given attributes."
  (make-crumb label url))