summaryrefslogtreecommitdiff
path: root/cook/html.scm
blob: d390ca3ff1d5927c2b2fdd645d361904f8123c1e (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
;; TODO
(define (expand x)
  (match x
    (($ <note> text)
     `(p ,text))
    (($ <section> name)
     `(h2 ,name))
    (($ <step> elements)
     `(li ,@(map expand elements)))
    (($ <amount> quantity unit)
     (list "(" (number->string quantity) unit ")"))
    (($ (or <ingredient> <cookware> <timer>) name amount)
     `(span  ,@(if name (list name) '())
             ,@(if amount (expand amount) '())))
    (($ <recipe> metadata body)
     `((@raw "<!DOCTYPE html>")
       (html
         (body
           (h1 ,(cdr (assoc "title" metadata)))
           (ol ,@(expand body))))))
    ((? list? x)
     (map expand x))
    ((? string? x)
     x)
    (else "")))

(define (recipe->html recipe)
  (let ((ingredients (recipe-ingredients recipe))
        (cookware    (recipe-cookware    recipe))
        (timers      (recipe-timers      recipe)))
    #;(for-each (lambda (x)
                (display (ingredient-name x))
                (display ": ")
                (when (ingredient-amount x)
                  (display (amount-quantity (ingredient-amount x)))
                  (display (amount-unit     (ingredient-amount x))))
                (newline)) ingredients)
    (sxml->xml (expand recipe))))